Wait for a child process to change state
#include <sys/wait.h>
int waitid( idtype_t idtype,
            id_t id,
            siginfo_t * infop,
            int options );
- idtype
 
- Which children you want to wait for:
  
- P_PID  --  the child with a process ID of
    (pid_t)id.
    
  
 
- P_PGID  --  any child with a process group ID equal
    to (pid_t)id.
    
    
  
 
- P_ALL  --  any child; id is ignored.
    
  
 
 
- id
 
- The process or process group ID that you want to wait for, depending on
  the value of idtype.
 
- infop
 
- A pointer to a siginfo_t structure, as defined in
  <sys/siginfo.h>, where the function can store the
  current state of the child; see below.
 
- options
 
- A combination of zero or more of the following flags:
  
- WCONTINUED  --  return the status for any child that
    was stopped and has been continued.
    
  
 
- WEXITED  --  wait for the process(es) to exit. 
    
  
 
- WNOHANG  --  return immediately if there are no
    children to wait for. 
    
  
 
- WNOWAIT  --  keep the process in a waitable state.
    This doesn't affect the state of the process; the process may be waited
    for again after this call completion.
    
  
 
- WSTOPPED  --  wait for and return the process status
    of any child that has stopped because it received a signal.
    
  
 
- WUNTRACED  --  report the status of a stopped child
    process.
    
  
 
 
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The waitid() function suspends the calling process until 
one of its children 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() returns immediately.
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 is filled in by the system with the  status
of the process.  The si_signo member is always
SIGCHLD.
If idtype is P_ALL and options is
WEXITED|WTRAPPED, waitid() is equivalent to 
wait().
- 0
  
 
- One of the children changed its state. If WNOHANG
      was used, 0 can be returned (indicating no error);  however,  no  children  
      may have changed state if info->si_pid is 0.
  
 
- -1
  
 
- An error occurred
    (errno
    is set).
 
- ECHILD
  
 
- The set of processes specified by idtype  and
      id doesn't contain   any  unwaited-for processes.
  
 
- EFAULT
  
 
- The infop argument points to an illegal address.
  
 
- EINTR
  
 
- The waitid() function was interrupted by a signal.
  
 
- EINVAL
  
 
- An invalid value was specified  for  options,
      or idtype  and id specify an invalid set of processes.
 
POSIX 1003.1 XSI
| Safety: |  | 
| Cancellation point | 
    Yes | 
| Interrupt handler | 
    No | 
| Signal handler | 
    Yes | 
| Thread | 
    Yes | 
execl(),
execle(),
execlp(),
execlpe(),
execv(),
execve(),
execvp(),
execvpe(),
exit(),
fork(),
pause(),
sigaction(),
signal(),
wait(),
wait3(),
wait4(),
waitpid()