In my Python script, I first launch a subprocess by subprocess.Popen(). Then later on, I want to kill that subprocess by kill -9 Pid.
What I found is that after the kill is executed, the subprocess is “stopped” because the GUI window of that process disappeared immediately. But when I perform a “ps aux” right after the kill, the same process (with same pid) is still shown in the result. The difference is the command of the process is included in a pair of () like below:
root 30506 0.0 0.0 0 0 s000 Z+ 6:13PM
0:00.00 (sample process)
This breaks my process detect logical since the dead process still can be found by ps.
Anyone know why this is happening?
Thanks!
From the manual page of ps:
That means that the parent didn’t do a
waitpid()for the child that died.Apart from waitpid(), you can avoid that by using a double fork when executing the child.