Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
5  
...with a shotgun. ;) –  Nathan C Feb 12 at 21:13
    
+1, because I looked at the main and saw "kill zombie" –  HopelessN00b Feb 12 at 23:08

2 Answers 2

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:

  1. Determine the zombie & parent processes' PIDS
    (For this example let's say the zombie is PID 3101 and the parent is PID 3100)
  2. Fire up gdb and attach to the parent:
    attach 3100
  3. Call waitpid for the zombie:
    call waitpid(3101,0,0)
  4. Detach from the parent (detach) and exit the debugger.

(This is a finely tuned sniper rifle.)

share|improve this answer
1  
heh, great answer. "Mosin" rifle right there. –  Danila Ladner Feb 12 at 21:41
1  
@DanilaLadner I wish I could take credit, but until I went on a little google hunt to see what skerit meant about "attaching the zombie as a child of a dummy process" the thought of using the debugger to force a waitpid() never occurred to me. I'm a terrible ex-programmer... –  voretaq7 Feb 12 at 21:44

Why are you worried about the zombie processes? The resources they keep tied up are minimal (space for a skeleton struct task, a PID and not much else). Sure, it is unseemly, but that is it. Search for their parents and fix those, replace them by better written alternatives (might have other beneficial side effects), report that as bugs (which they certainly are).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.