Get child process termination status: Wait and Waitpid

Source: Internet
Author: User
Tags function prototype
When the parent process calls the wait and WAITPID functions to get the aborted state of the child process, there are generally 3 scenarios:
1, if all of its child processes are still running, then blocking;
2. If a child process is terminated and is waiting for the parent process to obtain its termination state, the terminating state of the child process is returned immediately;
3. If there are no child processes, the return is terminated immediately.
If the parent process receives a SIGCHLD signal (when a process is normal or abnormally terminated), the kernel sends a SIGCHLD signal to its parent process, and the call to Wait,wait returns immediately.

The function prototype is as follows:
The difference between the two functions is as follows:
1. Before a child process terminates, wait causes its caller to block, and Waitpid has an option (int options) that makes the caller not block;
2. Waitpid does not wait for the first aborted child process after its invocation, it has several options to control the process it waits for.
The function of PID parameter in Waitpid function is explained as follows:

The Waitpid function returns the ID of the terminating subprocess and holds the terminating state of the subprocess in the storage unit pointed to by Statloc.
3. For wait, the only error is that the calling process has no child processes;
However, for Waitpid, if the specified process or process group does not exist, or if the process specified by the parameter PID is not a subprocess of the calling process, there may be an error.

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.