Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can somebody please explain when parent process receives the exit status of a dead child process via wait, who actually reallocates the memory of the child process and removes it from the process table?

share|improve this question

migrated from stackoverflow.com Jun 30 '11 at 14:26

This question came from our site for professional and enthusiast programmers.

Manipulating the process table and the memory mappings is always the kernel's job. The kernel acts when some process makes a system call. When a process exits, all of the resources that it uses, including memory, except for the entry in the process table, are deleted − that's what the _exit system call does. Then, when the parent process calls wait or waitpid, part of that system call's job is to clean up the process table entry. The parent process may decide to call wait whenever it wants (if the parent is init, it calls wait pretty much all the time).

share|improve this answer

The kernel assumes that the parent process is interested in knowing the result of any child process that it forked. When a child process terminates, it automatically sends a SIGCHLD signal to the parent process.  If the parent is explicitly ignoring the SIGCHLD signal, the child is immediately cleaned up and removed completely (and does not become a zombie). Otherwise, the child becomes a zombie until the parent calls one of the wait functions to retrieve termination status from the child.

If the status is not retrieved, child remains a zombie. However if the parent process exits before the child process, the child is adopted by init (process 1), which collects the status immediately, effectively removing the zombie process.

share|improve this answer
thank You, but what if the parent process doesn't exist before the child process, and father received status value, who will remove ZOMBIE? also init? – macindows Jun 29 '11 at 12:33
@macindows: Yes. If the parent process doesn't exist, responsibility passes to its parent, then that process's parent, and so on. If no other ancestor process currently exists, it will end up with init. – Dave Sherohman Jun 29 '11 at 14:43

Your Answer


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