From 8c6fca9ccdb30b69b627808c698526a76f7c4248 Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Sun, 29 Dec 2024 10:45:27 +0000 Subject: [PATCH] Fix issue 10587 - std.process.kill should fail for a terminated pid https://github.com/dlang/phobos/issues/10587 --- std/process.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/std/process.d b/std/process.d index 2efbcaa84..1cb2264f6 100644 --- a/std/process.d +++ b/std/process.d @@ -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(); } @@ -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