From 449f13a46738ff303e41a8fcad1df850cae721fd Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 14 May 2018 16:47:29 +0100 Subject: 42234: Stephane: don't kill a process if not running. This could happen when kiiling a job. The processs might be reused. --- Src/signals.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Src/signals.c b/Src/signals.c index f2165c005..4958534e2 100644 --- a/Src/signals.c +++ b/Src/signals.c @@ -793,9 +793,21 @@ killjb(Job jn, int sig) else return killpg(jn->gleader, sig); } - for (pn = jn->procs; pn; pn = pn->next) - if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0) - return -1; + for (pn = jn->procs; pn; pn = pn->next) { + /* + * Do not kill this job's process if it's already dead as its + * pid could have been reused by the system. + * As the PID doesn't exist don't return an error. + */ + if (pn->status == SP_RUNNING || WIFSTOPPED(pn->status)) { + /* + * kill -0 on a job is pointless. We still call kill() for each process + * in case the user cares about it but we ignore its outcome. + */ + if ((err = kill(pn->pid, sig)) == -1 && errno != ESRCH && sig != 0) + return -1; + } + } return err; } -- cgit 1.4.1