I have a script spawning two zombies. I can kill the group via kill -- -<parent-pid>
, but when invoked by the PHP interpreter, that won’t work although killing every single process manually will.
The script is
#!/bin/bash
sleep 1d&
sleep 1d
and the PHP file just invokes it:
<?php
exec("./spawn")
?>
From the shell directly:
$ ./spawn&
[1] 19871
$ pstree -p 19871
spawn(19871)─┬─sleep(19872)
└─sleep(19873)
$ kill -- -19871
$ pstree -p 19871
[1]+ Terminated ./spawn
... and via PHP:
$ php -f zomby.php &
[1] 19935
$ pstree -p 19935
php(19935)───sh(19936)───spawn(19937)─┬─sleep(19938)
└─sleep(19939)
$ kill -- -19937
bash: kill: (-19937) - No matching process found
$ kill -- -19936
bash: kill: (-19936) - No matching process found
$ kill 19939 19938 19937
$ Terminated
[1]+ Fertig php -f zomby.php
only killing the PHP parent process will work:
$ php -f zomby.php &
[1] 20021
$ pstree -p 20021
php(20021)───sh(20022)───spawn(20023)─┬─sleep(20024)
└─sleep(20025)
$ kill -- -20021
$ pstree -p 20021
[1]+ Terminated php -f zomby.php
Any ideas on that?
LC_ALL=C
(so, for example,LC_ALL=C kill 19939 19938 19937
so we can see the messages in English? I translated the ones I was sure about, but both "Fertig" and "Beendet" seem to mean something like "done" so I couldn't guess what message each was supposed to be.kill -- pid
does, but I think you might want to replace that withkill -1 pid
which sends the HUP/HangUP signal to the process.kill
with no signal specified sends signal 1 (TERM
), so there's no difference betweenkill -1 -PID
andkill -- -PID
. But yes, when a PID is < 1 that does mean "kill group" and that's precisely why it didn't work in your case, as I explain in my answer.