Remove a zombie process from the process table
The only way to get rid of a zombie is to make its parent wait()
so it can report its exit status. You can do that by sending SIGCHLD
to the parent, assuming the parent is written properly.
If you have zombies it usually means the parent is NOT written properly (because the child already sent SIGCHLD
to its parent when it died and became a zombie), so the next step is to kill the parent.
A tool like pstree
(with the -p
option) can show you the lineage of your zombies so you know which process is the parent.
When the parent dies the zombie will be adopted by init
, which is always wait()
ing for children to die, and will happily slay all the zombies it adopts.
If the parent process is actually init
(PID 1) already you're in a situation that should never happen. You can try sending SIGCHLD
to init
, but you really shouldn't have to do that, and if that doesn't work your only recourse is to reboot because your system's init
is broken and not doing its job.
(These are the "shotgun" options.)
Some more creative folks than I have also come up with this option if you want to avoid killing the parent process:
- Determine the zombie & parent processes' PIDS
(For this example let's say the zombie is PID 3101 and the parent is PID 3100) - Fire up
gdb
andattach
to the parent:attach 3100
- Call
waitpid
for the zombie:call waitpid(3101,0,0)
- Detach from the parent (
detach
) and exit the debugger.
(This is a finely tuned sniper rifle.)