How is the zombie process generated in the Unix/linux system? What's the harm? How to avoid it?

Source: Internet
Author: User
Tags signal handler

How is the zombie process generated in the title Unix/linux system? What's the harm? How to avoid it?

When a process calls the Exit command to end its own life, he is not actually destroyed, but rather leaves behind a data structure called the zombie process (Zombie) (System call exit, whose role is to make the process exit, but only a normal process becomes a zombie process, not 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, and can not be dispatched, just keep a position in the process list, record the process's exit status information for other processes to collect, in addition, The zombie process no longer occupies any storage space. He needed his father's process to bury him, if his parent process did not install the SIGCHLD signal handler call wait or waitpid () wait for the child process to end, there is no explicit ignore the signal, then it remains zombie state, if this time the parent process is finished, Then the init process will automatically take over the child process, and he will be able to get rid of it. But if the parent process is a loop and does not end, then the child process remains zombie, which is why there are sometimes a lot of zombie processes in the system.

Ways to avoid Zombie

1) in SVR4, if you call signal or Sigset to set the SIGCHLD configuration to ignore, no zombie subprocess will be generated. In addition, with SVR4 version sigaction, you can set the SA_NOCLDWAIT flag to avoid child process zombies. This can also be used in Linux, where a program starts calling this function signal (sigchld,sig_ign);

2) Call Fork two times

3) Wait for the child process to return with Waitpid.

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.