For further fine tuning and control, there is the waitid(2) system call as well (from Linux 2.6.9):
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
The first two parameters will in effect specify the children to wait upon:
waitid(2): 1st parameter: idtype | Second parameter: id |
P_PID | Set to the PID of the child to wait (block) upon |
P_PGID | Wait upon any child whose process group ID (PGID) matches this number |
P_ALL | Wait upon any child (this parameter is ignored) |
The fourth options parameter is similar to how it was used with the waitpid(2), but not identical; there are some additional options that can be passed along; again, it's a bitmask, not an absolute value: the WNOHANG and WCONTINUED