while (PID = Waitpid ( -1, &stat, Wnohang)) > 0)
Need to write to the signal processing function, if there are 10 sub-processes
As long as the parent process is able to receive the last signal, the resulting zombie process from the previous loss can be recovered.
The parent process is able to receive the last signal, even if the parent process starts processing the signal function at the end of the child process to the 5th.
If the processing time is too long, the remaining 5 will also end up in the process of processing function execution. At this point, due to the signal processing mechanism will cause the remaining 5 transmitted signals will be blocked, of course, because the signal is not queued
So the pending set will only have one signal (when the block set corresponds to 1 o'clock, if a corresponding signal arrives, the pending set to 1 indicates a pending signal). At this point, the child process has been all over, when the signal function is completed, the kernel open block signal set, then. The signal that was blocked before is passed in.
Next, recycle the remaining zombie processes again.
The following shows the code, showing the number of executions of the signal function and the count of the number of recoveries. You can see the difference.
void hander (int n) { static int i = 0; i++; printf (" i:%d\n", i); while (waitpid (0, NULL, Wnohang) > 0) { static int j = 0; j + +; printf ("j:%d\n", j); } }
Waitpid ( -1, &stat, Wnohang) recycles the subprocess, recycles the successful one, returns the PID of the subprocess, and if the Wnohang is specified, it will no longer block the recycle, at which point the return rule is. If there are child processes but no end (no zombie process), Waitpid returns 0, if there is a zombie process, recycle a zombie process, return to the zombie process PID, so you have to use the loop to deal with. Recycle the zombie process
For while (PID = Waitpid ( -1, &stat, Wnohang) > 0) I don't understand.