UNIX Network programming: Zombie Process

Source: Internet
Author: User
Tags signal handler

In the process of fork ()/exec (), assuming that the parent process is still present at the end of the child process and the parent process fork () before the SIGCHLD signal processing function call Waitpid () waits for the child process to end, and the signal is not explicitly ignored, the child process becomes a zombie and does not end properly. At this point, even root identity kill-9 can not kill the zombie process. The remedy is to kill the parent process of the zombie process (the parent process of the zombie process is inevitable), the zombie process becomes an "orphan process", and the adoptive 1th process Init,init will always be responsible for cleaning up the zombie process.

Defined:

In UNIX terminology, a process that has been terminated but whose parent process has not yet been dealt with (getting information about terminating a child process, releasing the resources it still occupies) is called a Zombie process (zombie).

Produce:

How to produce zombie processes:

When a process ends its own life by invoking the Exit command, it is not actually destroyed, but rather leaves behind a data structure called the zombie process (Zombie) (System call exit, which acts as a process exit, but is limited to turning a normal process into a zombie process, It cannot be completely destroyed). In the state of the Linux process, the zombie process is a very special one, it has abandoned almost all memory space, no executable code, can not be scheduled, only in the process list to retain a location, record the process of exit status and other information for other processes to collect, in addition, The zombie process no longer occupies any memory space. It needs its parent process to bury it, and if his parent process does not install the SIGCHLD signal handler call wait or Waitpid () waits for the child process to end and does not explicitly ignore the signal, it remains zombie, if the parent process ends, Then the init process will automatically take over the subprocess and bury it, it can still be cleared. But if the parent process is a loop and does not end, then the child process will remain zombie, which is why there are sometimes many zombie processes in the system.

View:

Using the command PS, you can see that a process marked with Z is a zombie process.

Clear:

How to clear the zombie process:

1. Rewrite the parent process and bury it after the child process dies. The concrete procedure is to take over the SIGCHLD signal. After the child process dies, a SIGCHLD signal is sent to the parent process, and the parent process receives the signal and executes the waitpid () function to bury the child process. This is based on the principle that even if the parent process does not call wait, the kernel sends it a SIGCHLD message, although the default processing is ignored and if you want to respond to this message, you can set up a handler function.

2. Kill the parent process. After the parent process dies, the zombie process becomes an "orphan process", and the adoptive 1th process Init,init is always responsible for cleaning up the zombie process. All the zombie processes it produces are also disappearing.

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/unix/

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.