The role of ignore sigchld signal-preventing the generation of zombie Processes
Signal (sigchld, sig_igr); // ignores sigchld signals, which is commonly used as a technique for concurrent server performance.
// Because the concurrent server often fork many sub-processes and needs
// The server process cleans up resources through wait. If you set the signal processing method
// Ignore, so that the kernel can forward the zombie sub-process to the INIT process for processing, saving
// A large number of zombie processes occupy system resources. (Linux only)
-
Code: select all
-
Some code ();
PID = fork (); // generate a sub-process
If (PID <0) // error check.
Handle_err ();
If (pid = 0)
Exit (execl (...); // child process.
Else
If (wait (& RET) <0)
Perror ("wait"); // parent process
// Here wait will get the no such process error,
// After the sub-process is terminated, the kernel sends the sigchld to the parent process
// Signal, but the above signal has been set to ignore, essentially from
// Init to receive the processing of this sub-process.
In addition, the child process inherits the signal processing method of the parent process.