Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

kill %jobspec tries to kill dead processes



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



Messages sorted by: Reverse Date, Date, Thread, Author