Zombie process and orphan process----concepts

Source: Internet
Author: User
Tags signal handler terminates

This gives only the concept of the zombie process and the orphan process. SOURCE "In-depth understanding of the computer system (original book 3rd edition)" and online blog, the following will give a blog source.

Introduction: Recycling of sub-processes

When a process terminates for some reason, the kernel does not immediately purge it from the system. Instead, the process is kept in a terminated state until it is reclaimed by its parent process (reaped). When the parent process recycles the terminated child process, the kernel passes the child process's exit state to the parent process, and then discards the terminated process. From this point on, the process does not exist.

1. Basic Concepts

Zombie Process: a process uses fork to create a child process, and if the child process is retired , and the parent process does not call wait or waitpid to get state information for the child process, the process descriptor of the child process is still stored in the system. This process is called a zombie process.

Orphan process: One parent process exits , and one or more of its child processes are still running, then those child processes will become orphans. The orphan process will be adopted by the INIT process (process number 1) and the Init process completes the state collection for them.

2. Related issues

(1) Why should I go into zombie state after the end of the subprocess?

Because the parent process may want to get information such as the exit status of the child process.

(2) is zombie status A must-have status for each sub-process?

Yes. Any child process (except Init) after exit () does not disappear immediately, leaving behind a data structure called the zombie process (Zombie), waiting for the parent process to handle it. This is the stage at which each child process passes at the end. If the child process has not been processed by the parent process after exit (), then the PS command will be able to see the status of the child process as "Z". If the parent process can be processed in a timely manner, it may be too late to see the zombie state of the child process with the PS command, but this does not mean that the child process does not go through zombie state. * If the parent process exits before the child process ends, the child process will be taken over by Init. Init will process the child process of the zombie state as the parent process.

3. Harm

(1) UNIX provides a mechanism that can be obtained if the parent process wants to know the state information at the end of the child process. The mechanism is that when each process exits, the kernel frees all of the resources of the process, including open files, memory usage, and so on. However, it still retains certain information (including process ID, exit status of the termination status of the process, run time of the amount of the CPU taken by the Proces s, etc.). It is not released until the parent process passes wait/waitpid. However, this causes the problem, if the process does not call Wait/waitpid, then the reservation of the piece of information will not be released, its process number will always be occupied, but the system can use the process number is limited, if a large number of zombie process generated, The system cannot produce a new process because no process number is available. This is the threat to the zombie process and should be avoided.

(2) The orphan process is a process without a parent process. If a parent process terminates, the kernel will schedule the init process to be known as the adoptive father of its orphan process, the PID of the Init process is 1, the system is created by the kernel at boot, it does not terminate, it is the ancestor of all processes, and the kernel arranges the init process to reclaim them. So the orphan process does not have any harm.

4. Ways to avoid zombie processes

(1) The child process becomes the orphan process, so that its parent process becomes the Init process, through the INIT process can handle the zombie process;

(2) The parent process of the zombie process to reclaim, the parent process every time to query whether the child process is finished and recycled, call wait () or Waitpid (), notify the kernel to release the zombie process

(3) A sigchild signal is sent to the parent process when the child process exits, and the parent process processes the sigchild signal. Call wait in the signal handler function to process the zombie process.

REF:

http://blog.csdn.net/qq_20218109/article/details/52078076

Http://www.cnblogs.com/Anker/p/3271773.html#top

Http://www.cnblogs.com/yuxingfirst/p/3165407.html

Zombie process and orphan process----concepts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.