12

Zombie processes are created in Unix/Linux systems. We can remove them via the kill command.

But is there any in-built clean-up mechanism in Linux to handle zombie processes?

migrated from operatingsystems.stackexchange.com Sep 11 '14 at 12:34

18

Zombie processes are already dead. You cannot kill them. The kill command or system call has no effect on a zombie process. (You can make a zombie go away with kill, but you have to shoot the parent, not the zombie, as we'll see in a minute.)

A zombie process is not really a process, it's only an entry in the process table. There are no other resources associated with the zombie process: it doesn't have any memory or any running code, it doesn't hold any files open, etc.

When a process dies, the last thing to go, after all other resources are cleaned up, is the entry in the process table. This entry is kept around, forming a zombie, to allow the parent process to track the exit status of the child. The parent reads the exit status by calling one of the wait family of syscalls; at this point, the zombie disappears. Calling wait is said to reap the child, extending the metaphor of a zombie being dead but in some way still not fully processed into the afterlife. The parent can also indicate that it doesn't care (by ignoring the SIGCHLD signal, or by calling sigaction with the SA_NOCLDWAIT flag), in which case the entry in the process table is deleted immediately when the child dies.

Thus a zombie only exists when a process has died and its parent hasn't called wait yet. This state can only last as long as the parent is still running. If the parent dies before the child or dies without reading the child's status, the zombie's parent process is set to the process with PID 1, which is init. One of the jobs of init is to call wait in a loop and thus reap any zombie process left behind by its parent.

6

You don't kill a zombie process, as it's already dead.

Zombie processes have to be waited by their parents, so that their exit status to be collected.

The only "built-in clean-up mechanism" there is in Linux, works for the case that any parent-process dies before it collects its children's exit status. In this case, each child is inherited by the init process, which will wait on the child, collect its exit status and remove its entry in the process table.

3

As soon as the parent of a process dies, the process becomes an orphan - disregarding if it's a zombie or not. What happens to orphans? They get a new parent, called init. init will wait on each orphan that it collected, thus reaping the orphan (that may also have been a zombie as well).

  • 1
    No. Being precise, init doesn't kill any process. It only waits on its children to collect their status. – chrk Aug 20 '14 at 13:30
  • 1
    @chrk, Philipp: the usual term is reap. – Gilles 'SO- stop being evil' Aug 20 '14 at 13:31
1

No, there is no in-built cleaning mechanism for zombies. Zombies go to zombie heaven once their parent is killed. Until then, the OS keeps them to return the exit status to parent.

  • so.. doesn't this has negative effect of memory etc? – atur Aug 20 '14 at 13:17
  • 1
    actually, when the parent of the zombie dies, the init process takes over and will call wait it – mmk Aug 20 '14 at 13:19
  • No, all the resources allocated to the process are released, except for the entry in the process table. – unxnut Aug 20 '14 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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