Linux Zombie processes (Zombie or defunct) about Linux botnets, generally because some resources are not released when the child process ends, it is not allowed until the parent process ends or the parent process processes it! The www.2cto.com zombie process is a child process that has been completed but has not been processed by the parent process! The parent process can use waitpid and wait to process zombie processes! If the parent process is unfortunately "dead" before the child process, the child process is managed by the init (pid = 1) process ~ We can test the following: for specific program explanations, see the code comments! [Cpp] # include <stdio. h> # include <stdlib. h> # include <sys/types. h> www.2cto.com int main () {int status; if (! Fork () //!> Fork a process {printf ("child pid = % d \ n", getpid (); exit (0) ;}printf ("Enter ps-e: View zombie processes! \ N "); sleep (10); //!> Let you have time to enter ps-e to view printf ("let's have the parent process wait to handle zombie processes. Please check ps-e again! \ N "); if (waitpid (-1, & status, 0 )! =-1) //!> The parameter-1 is waiting for all sub-processes {printf ("sub-processes exit status: % d \ n", status);} else {printf ("waitpid error! \ N "); exit (1) ;}sleep (10); //!> Let you have time to enter ps-e to view exit (0);} www.2cto.com gcc-o 1 1.c running result on my machine: 2747 pts/0 00:00:00 bash 2768 pts/0 00:00:00 1 //!> View: This is the parent process 2769 pts/0 00:00:00 1 <defunct> //!> View: This is the sub-process that becomes the zombie process 2772 pts/1 00:00:00 bash 2802 pts/1 00:00:00 ps pengtao @ ubuntu :~ $ //!> 10 s later I opened the second terminal ps-e 2747 pts/0 00:00:00 bash 2768 pts/0 00:00:00 1 //!> No ~~~ Haha ~~~ 2772 pts/1 00:00:00 bash 2805 pts/2 00:00:00 bash 2821 pts/2 00:00:00 ps pengtao @ ubuntu :~ $ Of course, we can use the ignore signal to prevent zombie processes! Signal (SIGCHLD, SIG_IGN); //!> Ignore the zombie process www.2cto.com [cpp] # include <stdio. h> # include <stdlib. h> # include <sys/types. h> # include <signal. h> int main () {int status; int I; signal (SIGCHLD, SIG_IGN); //!> Ignore the zombie process generated for (I = 0; I <5; I ++) //!> Five sub-processes {if (! Fork () {printf ("child pid = % d \ n", getpid (); exit (0) ;}} printf ("Enter ps-e: view zombie processes! \ N "); www.2cto.com sleep (10); exit (0 );} gcc-o 1 1.c 3115 pts/0 00:00:00 bash 3172 pts/1 00:00:00 bash 3228 pts/0 00:00:00 1 3237 pts/1 00:00:00 ps so in general, if you need the sub-process results to do it some judgments, we need wait or waitpid, but it can be ignored in many cases. For zombie processes, the consumption of src is small, however, when a botnet is built too much, it will also affect performance, so you should pay attention to it! Author shanshanpt