=============================================================
Reclaim Child processes
=============================================================
1 Create 10 sub-processes, at 46 line normal end, in 55 lines to capture the SIGCHLD signal, capture the process of blocking, will not execute the following code, only processing the function we specified
To continue executing the following code
2 Our function is called Do_sig_chird,waitpid function is to recycle the specified process (see _013_ process), the first parameter to fill 0, that is, to reclaim all of our child processes, the second parameter saved the state
The third parameter indicates no waiting. Is non-blocking, because there is no need to block, since we have reached the 20 line, we have captured the sigchld signal, no need to wait
As for the wifexited is the second parameter of the macro specified , 22 rows of Wexitstatus is to get the child process exit () Return the end code, that is, get our 46th line of return i+1
(The above is a description of the Waitpid function, see the Waitpid function of the _013_ process in detail )
3 The whole program means to create 10 child processes that are reclaimed by the parent process for each process
4 if the while in line 20th is changed to if, it logically seems to have the same effect, but in fact, some of the child processes are not recycled because the end of our subprocess is indeterminate, that is, indeterminate
Which subroutine ends first, not the imagined child process 1, subprocess 2 ... This is done in order. Because of the CPU's occupation, I'm not sure which child process ends first.
So we captured the sub-process is not sure, if Waitpid captured the 2nd sub-process, at this time, sub-process 3rd and process 4th died, also sent a sigchld signal, and if the execution once
So some of the child processes are not received back
=============================================================
Signal-Transfer parameters
=============================================================
_018_ retrieving the sub-process _ signal Transfer parameter