zsh-workers
 help / color / mirror / code / Atom feed
* kill %jobspec tries to kill dead processes
@ 2018-01-05 12:46 Stephane Chazelas
  2018-01-05 23:21 ` Stephane Chazelas
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2018-01-05 12:46 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-05 23:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-05 12:46 kill %jobspec tries to kill dead processes Stephane Chazelas
2018-01-05 23:21 ` Stephane Chazelas

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).