18.29 zombie process

  Zombie process (Zombie) :

  But the process has terminated a parent process had not yet deal with the aftermath (for information on the termination of the child process, the release of resources it is still occupied) of.

  Zombie produce:

  In a process called when the exit command to end his own life, in fact, it does not really being destroyed, but leaves the data structure (system call exit called zombie (Zombie), its role is to make the process of withdrawal, but it is only limited to a normal process becomes a zombie process does not bring its complete destruction). In the state of Linux process, the zombie process is a very special one, it has given up almost all of the memory space, there is no executable code, can not be scheduled, only to retain a position in the list of processes, the process according to exit status and other information for other processes to collect, in addition, zombie process no longer occupy any memory space. It needs its parent to serve it to remove the process if () generated child process in a fork at the end of the child process the parent process is still there, but the parent process fork did not install SIGCHLD signal processing function before (), then the child becomes zombie process, not the end of normal time even if you are root and kill -9 can not kill a zombie process. If at this time the parent process is over, then the init process will automatically take over the child process for it to remove it, or it can be cleared. However, if the parent process is a cycle, not the end, then the child will remain a zombie state, which is why systems sometimes have a lot of zombies.

  View zombie process:

  With the command PS -A , you can see a marked defunct process is a zombie process.

  Clear zombie process:

  1. rewrite the parent process, the child process to the death for it to remove it. The specific approach is to take over the SIGCHLD signal. The child's death, after SIGCHLD signal is sent to the parent, the parent process receives this signal, execute waitpid () function for the child process to remove it. This is based on the principle: even if the parent does not wait to call, the kernel will send a message to SIGCHLD it, even though the default processing is ignored, if you want to respond to this message, you can set up a handler.

#include <signal.h>
signal(SIGCLD, SIG_IGN); 

  2. The parent process to kill. The parent's death, zombie process to become "orphaned", had one of his No. 1 process init, init will always be responsible for cleaning up zombie process. All zombie process it produces also disappears.


 

Guess you like

Origin www.cnblogs.com/baixu/p/11226073.html