Zombie and orphan Processes

Source: Internet
Author: User

Zombie process (zombie process ):
When a process stops running (exit), all its resources and memory space will be released for use by other processes; however, it retains a record in the Process Table of the OS kernel, including the process ID, exit status, and running time of the process. This information is convenient for the parent process of the process to obtain its exit status at any time (that is, why the child process enters the zombie state after it ends ).

In UNIX/Unix-like systems, zombie processes are called processes that have completed execution but have not been cleared in the process table. Any process enters this status. Zombie is cleared only when the parent process calls wait (System Call.

The child process sends a sigchld signal to the parent process at the end of the operation. Therefore, a handler is usually specified for the signal in the code of the parent process, and the wait system is called in the handler, the zombie information of the sub-process is cleared immediately.

If the parent process does not or fails to clear the zombie information of the child process, the child process will be adopted by Init (process ID 1, the process automatically calls wait at intervals to clear zombie information of all its sub-processes. Therefore, the zombie process will be cleared sooner or later.

Zombie hazards:
Processes in the zombie state do not occupy any resources and memory space. The only danger is that they occupy a row in the Process Table and occupy a process ID, if there are too many processes, the system may not have too many process IDs to generate new processes.

It can be seen from the above that the zombie process will be cleared sooner or later. Therefore, the common zombie problem means that the parent process runs for a long time and the parent process generates a large quantum process, A large number of zombie processes may exist for a long period of time, resulting in insufficient process IDs.

Under what circumstances is it easy to generate too many zombie processes:
Common zombie processes are:

The parent process does not process the handler of sigchld, and it runs for a long time (a loop) to generate too many sub-processes, so that there will be too many zombie processes within a certain period of time.
In socket programming, if a sub-process is generated for each new client process for special processing, remember to add the sigchld handler (which calls wait) to the parent process ), otherwise, a large number of zombie processes will be generated when too many clients are processed.

Fork twice
When the parent process fork a sub-process, and then the sub-process fork a sun process situation attention.

View the zombie status of a process:
Kill and other commands can only kill running processes, and cannot clear zombie information of zombie processes;

You can run the PS aux command to check which processes are in the zombie state: the stat column is Z. In addition, s indicates the sleep state; D indicates the sleep state that cannot be interrupted; r indicates the running state; t indicates the stopped or tracked state.

Orphan process (orphan process)
Note the differences between zombie process and orphan process. The orphan process refers to the parent process died of the running process. The orphan process is not a zombie process. When a process changes to an orphan process, the INIT process (process ID 1) will adopt it as its new parent process.

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.