1. the generation of zombie processes :
When a process calls the Exit command to end its own life, it is not actually destroyed, but rather leaves behind a data structure called the "zombie process". At this point, it has abandoned almost all memory space, no executable code, and cannot be dispatched, just keep a location in the process list (its kernel stack resides in memory), record the exit status of the process and other useful information for other processes to collect. The status of the process becomes Exit_zombie, and the SIGCHLD signal is sent to the parent process, and Linux defaults to ignoring the signal, and the parent process can display the signal to install it, call the wait or waitpid function in the signal handler function and wait for the child process to end and clear it completely. If the parent process does not do so, the child process becomes a zombie process. But after the parent process dies, all its processes are passed on to the Init process, and the INIT process periodically calls the wait system call to clear its zombie child.
2. hazards of the zombie process :
A few zombie processes do not have any impact on the performance of the system, but because the Linux system has a limited number of processes to run, if the resulting zombie process is too large, it will take up the available process numbers, which can cause new processes to fail to build.
3. avoidance of zombie processes :
(1) When the process is created call two fork, and the immediate child process to exit, so that the grandson process becomes an orphan
Process, the INIT process will be responsible for cleaning up the orphan process.
(2) Under Linux, you can simply set the operation of the SIGCHLD signal to sig_ign so that the kernel ends at the child process
The zombie process is not generated. In SVR4, if you call signal or Sigset to set the SIGCHLD configuration to
Ignored, and no zombie process is generated.
(3) Call wait or waitpid to wait for the child process to end, collect the information left by the zombie process, and make the zombie process
The bottom disappears.
Note: You cannot use kill to pick up a SIGKILL signal such as kill the zombie process like killing normal process, because the zombie process is already dead process, it can no longer receive any signal.
Unix/linux Zombie Process