Skip to content

Commit

Permalink
Fix issue 10587 - std.process.kill should fail for a terminated pid
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow authored and dlang-bot committed Dec 29, 2024
1 parent 68da19a commit 8c6fca9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion std/process.d
Original file line number Diff line number Diff line change
Expand Up @@ -2815,6 +2815,10 @@ void kill(Pid pid, int codeOrSignal)
else version (Posix)
{
import core.sys.posix.signal : kill;
if (pid.osHandle == Pid.invalid)
throw new ProcessException("Pid is invalid");
if (pid.osHandle == Pid.terminated)
throw new ProcessException("Pid is already terminated");
if (kill(pid.osHandle, codeOrSignal) == -1)
throw ProcessException.newFromErrno();
}
Expand Down Expand Up @@ -2856,7 +2860,7 @@ void kill(Pid pid, int codeOrSignal)
do { s = tryWait(pid); } while (!s.terminated);
version (Windows) assert(s.status == 123);
else version (Posix) assert(s.status == -SIGKILL);
assertThrown!ProcessException(kill(pid));
assertThrown!ProcessException(kill(pid)); // Already terminated
}

@system unittest // wait() and kill() detached process
Expand Down

0 comments on commit 8c6fca9

Please sign in to comment.