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.

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.

2 Answers 2

Kernel assumes that the parent process is interested in knowing the result of the child process that it forked. First the child process sends to parent SIGCHLD signal. Then parent calls one of the wait functions to retrieve return status from child.

If the return status is not retrieved, child remains a zombie. However if the parent process exists before the child process, the child is adopted by init, 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

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

Your Answer

 
discard

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