Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Transmission is intermittently hanging on my NAS. If I send SIGTERM, it doesn't disappear from the process list and a <defunct> label appears next to it. If I send a SIGKILL, it still doesn't disappear and I can't terminate the parent because the parent is init. The only way I can get rid of the process and restart Transmission is to reboot.

I realize the best thing I can do is try and fix Transmission (and I've tried), but I'm a novice at compiling and I wanted to make sure my torrents finished before I start messing around with it.

share|improve this question
2  
No one is stating the obvious... a <defunct> process owned by "init" should be impossible! This is a very strange situtation! Are you sure? –  JoelFan Apr 12 '11 at 19:17
    
@JoelFan: I was just looking that up to make sure that I wasn't forgetting something important. Zombies that are children of init should go away pretty quickly since init waits on children periodically as one of its many common tasks... is <defunct> the same as a zombie? –  D.Shawley Apr 13 '11 at 1:31
1  
nevermind ... <defunct> is precisely the same as a zombie. init will wait on its children so this should never happen in theory. I wonder what happens if you send a SIGCHLD to init? –  D.Shawley Apr 13 '11 at 1:34
    
@JoelFan: yeah, I'm sure. The value for PPID was 1 (init), so it was impossible to SIGKILL the process. –  Andy E Apr 14 '11 at 15:08
1  
similar to unix.stackexchange.com/a/5648 –  Tshepang Jun 5 '12 at 20:57

2 Answers 2

up vote 15 down vote accepted

You cannot kill a <defunct> (zombie) process as it is already dead. The only reason why the system keeps zombie processes is to keep the exit status for the parent to collect. If the parent does not collect the exit status then the zombie processes will stay around forever. The only way to get rid of those zombie processes are by killing the parent. If the parent is init then you can only reboot.

http://en.wikipedia.org/wiki/Zombie_process

share|improve this answer
5  
init can never have zombie children. From the wikipedia article: When a process loses its parent, init becomes its new parent. Init periodically executes the wait system call to reap any zombies with init as parent. One of init's responsibilities is reaping orphans and parentless zombies. –  D.Shawley Apr 13 '11 at 1:45
7  
@D.Shawley: init can have bugs though. The init replacement runit has had a bug that causes this issue. –  camh Apr 13 '11 at 8:26

Anyone trying to fix the Transmission C source code should read about the "double fork" trick to avoid zombies and signal handlers ... and how it can be used as part of a smart variadic spawn function (see Spawning in Unix).

excerpt from: 
   "Spawning in Unix", http://lubutu.com/code/spawning-in-unix

Double fork
This trick lets you spawn processes whilst avoiding zombies, without 
installing any signal handler. The first process forks and waits for its 
child; the second process forks and immediately exits and is reaped;
the third process is adopted by init, and executes the desired program. 
All zombies accounted for, since init is always waiting.

if(fork() == 0) {
   if(fork() == 0) {
       execvp(file, argv);
       exit(EXIT_FAILURE);
   }
   exit(EXIT_SUCCESS);
}
wait(NULL);
share|improve this answer
    
The double fork prevents zombie processes by forcing the kernel to set its parent to PID 1, which is supposed to clean up zombies. It sounds like Transmission already does it, since its parent is already process 1. –  Jander Jun 3 '12 at 21:48

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.