Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: kill %jobspec tries to kill dead processes
- X-seq: zsh-workers 42234
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: kill %jobspec tries to kill dead processes
- Date: Fri, 5 Jan 2018 23:21:50 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=yUNpW1oYdMDyBzyZS2rMBX/ZWxRf8k78GIN2Qg6Rshk=; b=moXlfwLWlc+7hxd9CZdVopemB40GNP4zPUM9u/eMvjXt/1pbQtL2kLfw+piXmqTmJp WvAGn3DlZgMk3LgODx+uJ6PTOutE0FxNUKFYu09wjHLuQbWHiVhLc1LTh8RGIdo+FniD o5CdJgG0M7Czxcg2hPVQpweH+Kmo/Lc5XUfuH+zxPoK1cC7wBute43vmdry0Vg09NGif AewsJLx+vZxKmgMVv5oVBFHdhlHLaNghV1ZS2xQCc8bSFKky7Jbq4bpRUo140Q7jV47p 6LwTfAaJPqgT4Ida6Z7ZS4XKjYISGFjwBr40Vq0VYCIvfAn/V0evfIHW2UTrC6RTb2fJ ANZQ==
- In-reply-to: <20180105124602.GB16078@chaz.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <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;
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author