Killing undead processes
Sometimes you want to kill a process, and kill
doesn’t work, and kill -9
doesn’t work either.
I think this can happen when a process is blocked in kernel mode waiting for some event.
What is sure is that a zombie cannot be killed. Zombie processes are already terminated, and appear in the output of ps
as <defunct>
(in Linux, anyway). The system keeps zombies around because their parent process is supposed to be able to receive their return value using wait(2)
or waitpid(2)
, so the PID cannot be re-used until the parent calls one of these functions.
Just as in movies, you cannot kill a zombie but you can kill the zombie master: using pstree -p
you can find the parent of the zombie, and that’s the one you need to kill. As soon as the parent process dies, all zombie processes that it spawned will disappear.
You shouldn’t feel too bad about killing the parent: leaving zombies is a sign that the application is malfunctionning anyway.