October 2018
Beginner
794 pages
19h 23m
English
Consider that we have a process with three children; it is required that the parent waits (blocks) upon the termination of a particular child process. If we use the generic wait API, we have seen that it will get unblocked upon the state change of any of the children. The answer to this conundrum: the waitpid(2) system call:
pid_t waitpid(pid_t pid, int *wstatus, int options);
The first parameter pid is set to the PID of the child to wait upon. However, other values are possible; if -1 is passed, it generically waits for any waitable child process. (There are other more arcane cases; we refer you to the man page for them). In other words, issuing this is equivalent to a generic wait(&stat); API call:
waitpid(-1, &stat, 0); ...
Read now
Unlock full access