Zombie Processes (Zombie process)

Source: Internet
Author: User

This article briefly describes the zombie process.

Before you introduce, first look at the 6 big states of the process in Linux.

D        Uninterruptible sleep (usually IO) R        Running or runnable (on run queue) S        forevent to complete) T        is  being traced. W        2.6. XX kernel) X        dead (should never be seen) Z        Defunct ("  Zombie") process, terminated but not reaped by its parent.

State transition Diagram:

What is a zombie process? A zombie process is a process that has finished running, but whose parent process has not yet been processed. So why is the parent process going after a process has finished running? What has been done to deal with the aftermath?

Specifically, after a process finishes running, the process is not completely destroyed, and the kernel still maintains some information about the process (the process ID, the process's terminating state, and the total CPU time used by the process ). The parent process can obtain this information by calling wait ()/waitpid (), and eventually destroy the process.

How to avoid the production of zombie process?

1. The parent process waits for the child process to end by calling wait ()/waitpid (). (This causes the parent process to be suspended)

2. If the parent process is busy and does not want to be suspended, you can set the handler of the SIGCHLD signal through the signal function and call Wait ()/waitpid () in handler.

( at the end of the child process, the kernel sends a SIGCHLD signal to the parent process, which is ignored by the parent process for that signal.) )

3. The parent process displays the ignore SIGCHLD signal through signal (SIGCHLD, sig_ign), so that after the process finishes, the kernel does not send a SIGCHLD signal to the parent process and the kernel is responsible for reclaiming the child process.

4. Two times fork ().

The parent Process fork () out of the child process, the child process fork () exits after the grandchild process, and after the grandchild process finishes running, the Init process takes over because its parent process has exited. The INIT process will be responsible for destroying the process.

How do I clear the zombie process?

The KILL command cannot kill the zombie process, but we can kill the parent process of the zombie process so that the zombie process becomes orphaned and then taken over by the INIT process.

Zombie Processes (Zombie 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.