_018_ retrieving the sub-process _ signal Transfer parameter

Source: Internet
Author: User

=============================================================

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.