Skip to content

Commit 8c6fca9

Browse files
CyberShadowdlang-bot
authored andcommitted
Fix issue 10587 - std.process.kill should fail for a terminated pid
#10587
1 parent 68da19a commit 8c6fca9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

std/process.d

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2815,6 +2815,10 @@ void kill(Pid pid, int codeOrSignal)
28152815
else version (Posix)
28162816
{
28172817
import core.sys.posix.signal : kill;
2818+
if (pid.osHandle == Pid.invalid)
2819+
throw new ProcessException("Pid is invalid");
2820+
if (pid.osHandle == Pid.terminated)
2821+
throw new ProcessException("Pid is already terminated");
28182822
if (kill(pid.osHandle, codeOrSignal) == -1)
28192823
throw ProcessException.newFromErrno();
28202824
}
@@ -2856,7 +2860,7 @@ void kill(Pid pid, int codeOrSignal)
28562860
do { s = tryWait(pid); } while (!s.terminated);
28572861
version (Windows) assert(s.status == 123);
28582862
else version (Posix) assert(s.status == -SIGKILL);
2859-
assertThrown!ProcessException(kill(pid));
2863+
assertThrown!ProcessException(kill(pid)); // Already terminated
28602864
}
28612865

28622866
@system unittest // wait() and kill() detached process

0 commit comments

Comments
 (0)