A "defunct" process (sometimes referred to as "zombie") is a process that is actually finished which depends on a parent process which for some reason (=error) has not accepted the knowledge that it is finished and should be terminated.
How to get rid of them[edit | edit source]
Defunct processes will sometimes show up in the process list (top and ps -aux). Many people, including myself, find these annoying. Additionally, the reason for processes to be listed as defunct is that something has gone wrong with the parent process.
The solution is to find out what parent process the defunct processes belong to and stop it (or restart it).
The long story[edit | edit source]
Unix manages an explicit parent-child relationships between processes (Windows does not do this).
When a child process dies, the parent process recieves a notification. It is then the duty of the parent process to explicitly take notice of the childs demise by using the wait() system call.
The return value of the wait() is the process ID of the child, which gives the parent exact control about which of its children are still alive. Upon returning, wait() will have set the integer pointed to by its argument to the exit status of the child. A shell programm like "bash" could then decide how to process following commands and set the special $? variable accordingly.
As long as the parent hasn't called wait(), the system needs to keep the dead child in the global process list, because that's the only place where the process ID is stored. The purpose of the "zombies" is really just for the system to remember the process ID, so that it can inform the parent process about it on request.
If the parent "forgets" to collect on its children, then the zombie will stay undead forever.
Well, almost forever. If the parent itself dies, then "init" (the system process with the ID 0) will take over fostership over its children and catch up on the neglected parental duties. This is why you need to identify the parent process and stop or restart it in order to get rid of defunct processes. If the zombie process has id nnnnn, you can do ps -ef | grep nnnnn and find the id of the parent process, which you can then kill if no longer needed. Then the defunct process will be removed from the list.