"Todo" Zombie process learning & process Status list

Source: Internet
Author: User
Tags signal handler cpu usage

Refer to this article:

http://www.mike.org.cn/articles/treatment-of-zombie-processes-under-linux/

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, and can not be scheduled, just keep a position in the process list, record the process's 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 get the corpse of it.

If his parent process did not install the SIGCHLD signal handler, and did not call wait or waitpid () waiting for the end of the child process, and did not explicitly ignore the signal, then it remains zombie state, if the parent process is finished, then the INIT process will automatically take over the child process, for it to corpse, It can still be erased.

Avoidance of zombie processes

1. The parent process waits for the child process to end through functions such as wait and waitpid, which causes the parent process to hang

2. If the parent process is busy, you can use the signal function to install handler for SIGCHLD, because the parent process will receive the signal when the child process ends, and you can call the wait recycle in handler

3, if the parent process does not care about when the child process ends, then you can use signal (SIGCHLD, Sig_ign) to notify the kernel, the end of the child process is not interested, then the end of the process, the kernel will be recycled, and no longer send a signal to the parent process

4, there are some tricks, that is, fork two times, the parent process fork a child process, and then continue to work, the child process fork a grandchild process after the exit, then the Sun process is init takeover, after the end of the sun process, init will be recycled. But the recycling of the sub-process to do it yourself.

Why do I have to go into zombie state after the child process ends?

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

S (State of the process)

O: The process is running on the processor
S: Sleep state (sleeping)
R: Waiting to run (runable)
I: Idle state (idle)
Z: Zombie Status (Zombie)
T: Tracking status (traced)
B: The process is waiting for more memory pages
Estimated value of C:CPU utilization (CPU usage)

Kill-18 PPID (PPID is its parent process)

"Todo" Zombie process learning & process Status list

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.