zsh-workers
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: kill %jobspec tries to kill dead processes
Date: Fri, 5 Jan 2018 12:46:02 +0000	[thread overview]
Message-ID: <20180105124602.GB16078@chaz.gmail.com> (raw)

Hi,

kill %jobspec

usually avoids the problem when kill $pid may kill the wrong
process when it may have been reused. However, in:

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:

$ strace -e kill zsh -c 'sleep 1 | sleep 3 & ps -f; sleep 2; printf "%s => %s\n" "${(@kv)jobstates}"; kill %"sleep 1"'
UID        PID  PPID  C STIME TTY          TIME CMD
chazelas  8175 14816  0 12:37 pts/4    00:00:00 strace -e kill zsh -c sleep 1 | sleep 3 & ps -f; sleep 2; printf "%s => %s\n" "${(@kv)jobstates}"; kill %"sleep 1"
chazelas  8177  8175  0 12:37 pts/4    00:00:00 zsh -c sleep 1 | sleep 3 & ps -f; sleep 2; printf "%s => %s\n" "${(@kv)jobstates}"; kill %"sleep 1"
chazelas  8178  8177  0 12:37 pts/4    00:00:00 sleep 1
chazelas  8179  8177  0 12:37 pts/4    00:00:00 sleep 3
chazelas  8180  8177  0 12:37 pts/4    00:00:00 ps -f
chazelas 14816 14812  0 Jan03 pts/4    00:00:01 /bin/zsh
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8180, si_uid=1000, si_status=0, si_utime=0, si_stime=2} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8178, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=8181, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
1 => running:+:8178=done:8179=running
kill(8178, SIGTERM)                     = -1 ESRCH (No such process)
kill(8179, SIGTERM)                     = 0
+++ exited with 0 +++

See how 8178 was known to be "done", but is still killed.

mksh has the same issue. bash is worse in that it doesn't
attempt to kill the sleep 3 process. ksh93 segfaults when I try
the same thing there.

-- 
Stephane


             reply	other threads:[~2018-01-05 12:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-05 12:46 Stephane Chazelas [this message]
2018-01-05 23:21 ` Stephane Chazelas

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=20180105124602.GB16078@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).