WAIT(2) WAIT(2) NAME wait, wait3 - wait for process to terminate SYNOPSIS #include pid = wait(status) int pid; union wait *status; pid = wait(0) int pid; #include #include pid = wait3(status, options, rusage) int pid; union wait *status; int options; struct rusage *rusage; DESCRIPTION _W_a_i_t causes its caller to delay until a signal is received or one of its child processes terminates. If any child has died since the last _w_a_i_t, return is immediate, returning the process id and exit status of one of the terminated children. If there are no children, return is immediate with the value -1 returned. On return from a successful _w_a_i_t call, _s_t_a_t_u_s is nonzero, and the high byte of _s_t_a_t_u_s contains the low byte of the argument to _e_x_i_t supplied by the child process; the low byte of _s_t_a_t_u_s contains the termination status of the process. A more precise definition of the _s_t_a_t_u_s word is given in <_s_y_s_/_w_a_i_t_._h>. _W_a_i_t_3 provides an alternate interface for programs that must not block when collecting the status of child processes. The _s_t_a_t_u_s parameter is defined as above. The _o_p_t_i_o_n_s parameter is used to indicate the call should not block if there are no processes that wish to report status (WNOHANG), and/or that children of the current process that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP, or SIGSTOP signal should also have their status reported (WUNTRACED). If _r_u_s_a_g_e is non-zero, a summary of the resources used by the terminated process and all its children is returned (this information is currently not available for stopped pro‐ cesses). When the WNOHANG option is specified and no processes wish to report status, _w_a_i_t_3 returns a _p_i_d of 0. The WNOHANG and WUNTRACED options may be combined by _o_r’ing the two values. NOTES See _s_i_g_v_e_c(2) for a list of termination statuses (signals); 0 status indicates normal termination. A special status (0177) is returned for a stopped process that has not terminated and can be restarted; see _p_t_r_a_c_e(2). If the 0200 bit of the termination status is set, a core image of the process was produced by the system. If the parent process terminates without waiting on its children, the initialization process (process ID = 1) inherits the children. _W_a_i_t and _w_a_i_t_3 are automatically restarted when a process receives a signal while awaiting termination of a child process. RETURN VALUE If _w_a_i_t returns due to a stopped or terminated child process, the pro‐ cess ID of the child is returned to the calling process. Otherwise, a value of -1 is returned and _e_r_r_n_o is set to indicate the error. _W_a_i_t_3 returns -1 if there are no children not previously waited for; 0 is returned if WNOHANG is specified and there are no stopped or exited children. ERRORS _W_a_i_t will fail and return immediately if one or more of the following are true: [ECHILD] The calling process has no existing unwaited-for child processes. [EFAULT] The _s_t_a_t_u_s or _r_u_s_a_g_e arguments point to an illegal address. SEE ALSO exit(2) 4th Berkeley Distribution June 30, 1985 WAIT(2)