I've got an annoying zombie process that gets adopted by init, and it won't go away.
I've read there is a way to create a dummy process, attach the zombie as a child of that new process and then kill it, removing it from the process table.
How would I do that, precisely?
And yes, I've read most of this stuff:
A zombie process is already dead, so it can't be killed.
Or
You should just reboot your system
And
Zombie processes don't use any resources, you should just let them be
Unfortunately, lots of programs check the process table to see if an instance is already running, and will refuse to start a new one if there is an entry in the process table.
And rebooting every time my SSHFS connection drops out, taking Sublime with it, is kind of silly.
Best Answer
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 sendingSIGCHLD
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 alwayswait()
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 sendingSIGCHLD
toinit
, but you really shouldn't have to do that, and if that doesn't work your only recourse is to reboot because your system'sinit
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:
(For this example let's say the zombie is PID 3101 and the parent is PID 3100)
gdb
andattach
to the parent:attach 3100
waitpid
for the zombie:call waitpid(3101,0,0)
detach
) and exit the debugger.(This is a finely tuned sniper rifle.)