Zombie process, zombie Process

Source: Internet
Author: User

Zombie process, zombie Process
 

 

 

In a UNIX system, a zombie process is executedExit System Call, a fatal error occurs during operation, or a termination signal is received. However, there is still a table item (Process Control Block PCB) in the operating system table ), a process in the "terminated" status. This occurs when the child process needs to retain table items to allow its parent process to read the exit status of the child process: Once the exit state passesWhen the wait system calls read data, zombie process entries are deleted from the Progress table, which is called "reaped )". Under normal circumstances, the process is directly owned by its parent processwaitIt is recycled by the system. A process that remains zombie for a long time is generally incorrect and causes resource leakage.

TermsZombie processDerived from en: zombie-undead, It is a metaphor that sub-processes are dead but still not harvested. Unlike normal processes,The kill command is invalid for zombie processes. Unlike a zombie process, an orphan process has been killed, but it can still be executed normally, but it will not become a zombie process because it isInit (process ID 1) adopted andwaitIt exits.

After a child process dies, the system sends a SIGCHLD signal to the parent process. The parent process ignores the signal by default. If you want to respond to this message, the parent process usually usesWait system calls to respond to the termination of the sub-process.

After a zombie process is harvested, its process ID (PID) and table items in the progress table can be reused by the system. However, if the parent process does not callwait, The zombie process will keep the table items in the table, resulting in resource leakage. In some cases, this is expected: the parent process creates another sub-process and wants to have different process numbers. If the parent process sets the event handler functionSIG_IGNExplicitly ignore the SIGCHLD signal, instead of implicitly ignoring the signal by default, orSA_NOCLDWAITIndicates that the exit status of all sub-processes will be discarded and directly recycled by the system.

UNIX CommandsThe State ("STAT") column of the processes listed in ps is marked as"Z"It is a zombie process.

The method for harvesting botnets is throughkillCommand to manually send a SIGCHLD signal to the parent process. If the parent process still refuses to harvest botnets, terminate the parent processinitProcesses adopt zombie processes.initProcess execution cyclewaitThe system calls to harvest all zombie processes it adopted.

To avoid zombie processes, the following methods are generally used in actual applications:

Example:

 

 
12345678910111213141516171819202122 # Include & lt; sys/wait. h & gt; # include & lt; stdlib. h & gt; # include & lt; unistd. h & gt; int main (void) {pid_t pids [10]; int I; for (I = 9; I & gt; = 0; -- I) {pids [I] = fork (); if (pids [I] = 0) {sleep (I + 1); _ exit (0 );}} for (I = 9; I & gt; = 0; -- I) waitpid (pids [I], NULL, 0); return 0 ;}

Our public account

 

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.