#include <sys/wait.h>
int waitid(idtype_t idtype, id_t id, siginfo_t
*infop, int
options);
The waitid() function shall suspend the calling thread until one child of the process containing the calling thread changes state. It records the current state of a child in the structure pointed to by infop. If a child process changed state prior to the call to waitid(), waitid() shall return immediately. If more than one thread is suspended in wait() or waitpid() waiting for termination of the same process, exactly one thread shall return the process status at the time of the target process termination.
The idtype and id arguments are used to specify which children waitid() waits for.
If idtype is P_PID, waitid() shall wait for the child with a process ID equal to (pid_t)id.
If idtype is P_PGID, waitid() shall wait for any child with a process group ID equal to (pid_t)id.
If idtype is P_ALL, waitid() shall wait for any children and id is ignored.
The options argument is used to specify which state changes waitid() shall wait for. It is formed by OR'ing together one or more of the following flags:
The application shall ensure that the infop argument points to a siginfo_t structure. If waitid() returns because a child process was found that satisfied the conditions indicated by the arguments idtype and options, then the structure pointed to by infop shall be filled in by the system with the status of the process. The si_signo member shall always be equal to SIGCHLD.
If WNOHANG was specified and there are no children to wait for, 0 shall be returned. If waitid() returns due to the change of state of one of its children, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.
The waitid() function shall fail if:
The following sections are informative.
exec(), exit(), wait(), the Base Definitions volume of IEEE Std 1003.1-2001, <sys/wait.h>