From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: kill %jobspec tries to kill dead processes
Date: Fri, 5 Jan 2018 23:21:50 +0000 [thread overview]
Message-ID: <20180105232150.GA16579@chaz.gmail.com> (raw)
In-Reply-To: <20180105124602.GB16078@chaz.gmail.com>
2018-01-05 12:46:02 +0000, Stephane Chazelas:
[...]
> sleep 1 | sleep 3 & sleep 2
> kill %"sleep 1"
>
> kill still tries to kill the process that was running sleep 1
> even though the shell knows it has died:
[...]
I beleive the patch below should do it. I added an unrelated
comment about the "sig != 0". I guess we could skip the killing
altogether for sig == 0, but I left it in on the basis of "who
are we do deny the user's request even if it's pointless".
diff --git a/Src/signals.c b/Src/signals.c
index 94f379e..e06fc05 100644
--- a/Src/signals.c
+++ b/Src/signals.c
@@ -779,8 +779,17 @@ killjb(Job jn, int sig)
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;
+ /*
+ * Do not kill this job's process if it's already dead as its
+ * pid could have been reused by the system.
+ */
+ 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;
}
prev parent reply other threads:[~2018-01-05 23:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-05 12:46 Stephane Chazelas
2018-01-05 23:21 ` Stephane Chazelas [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180105232150.GA16579@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).