
WAIT(2)                    UNIX Programmer's Manual                    WAIT(2)

NNAAMMEE
     wwaaiitt, wwaaiittppiidd, wwaaiitt44, wwaaiitt33 - wait for process terminatation

SSYYNNOOPPSSIISS
     ##iinncclluuddee <<ssyyss//ttyyppeess..hh>>
     ##iinncclluuddee <<ssyyss//wwaaiitt..hh>>

     _p_i_d___t
     wwaaiitt(_i_n_t _*_s_t_a_t_u_s)

     ##iinncclluuddee <<ssyyss//ttiimmee..hh>>
     ##iinncclluuddee <<ssyyss//rreessoouurrccee..hh>>

     _p_i_d___t
     wwaaiittppiidd(_p_i_d___t _w_p_i_d, _i_n_t _*_s_t_a_t_u_s, _i_n_t _o_p_t_i_o_n_s)

     _p_i_d___t
     wwaaiitt33(_i_n_t _*_s_t_a_t_u_s, _i_n_t _o_p_t_i_o_n_s, _s_t_r_u_c_t _r_u_s_a_g_e _*_r_u_s_a_g_e)

     _p_i_d___t
     wwaaiitt44(_p_i_d___t _w_p_i_d, _i_n_t _*_s_t_a_t_u_s, _i_n_t _o_p_t_i_o_n_s, _s_t_r_u_c_t _r_u_s_a_g_e _*_r_u_s_a_g_e)

DDEESSCCRRIIPPTTIIOONN
     The wwaaiitt() function suspends execution of its calling process until
     _s_t_a_t_u_s information is available for a terminated child process, or a sig-
     nal is received.  On return from a successful wwaaiitt() call, the _s_t_a_t_u_s
     area contains termination information about the process that exited as
     defined below.

     The wwaaiitt44() call provides a more general interface for programs that need
     to wait for certain child processes, that need resource utilization
     statistics accummulated by child processes, or that require options.  The
     other wait functions are implemented using wwaaiitt44().

     The _w_p_i_d parameter specifies the set of child processes for which to
     wait.  If _w_p_i_d is -1, the call waits for any child process.  If _w_p_i_d is
     0, the call waits for any child process in the process group of the
     caller.  If _w_p_i_d is greater than zero, the call waits for the process
     with process id _w_p_i_d. If _w_p_i_d is less than -1, the call waits for any
     process whose process group id equals the absolute value of _w_p_i_d.

     The _s_t_a_t_u_s parameter is defined below.  The _o_p_t_i_o_n_s parameter contains
     the bitwise OR of any of the following options.  The WNOHANG option is
     used to indicate that the call should not block if there are no processes
     that wish to report status.  If the WUNTRACED option is set, children of
     the current process that are stopped due to a SIGTTIN, SIGTTOU, SIGTSTP,
     or SIGSTOP signal also have their status reported.

     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 processes).

     When the WNOHANG option is specified and no processes wish to report sta-
     tus, wwaaiitt44() returns a process id of 0.

     The wwaaiittppiidd() call is identical to wwaaiitt44() with an _r_u_s_a_g_e value of zero.
     The older wwaaiitt33() call is the same as wwaaiitt44() with a _w_p_i_d value of -1.

     The following macros may be used to test the manner of exit of the pro-
     cess.  One of the first three macros will evaluate to a non-zero (true)


     value:

     WWIIFFEEXXIITTEEDD(_s_t_a_t_u_s)
             True if the process terminated normally by a call to _exit(2) or
             exit(2).

     WWIIFFSSIIGGNNAALLEEDD(_s_t_a_t_u_s)
             True if the process terminated due to receipt of a signal.

     WWIIFFSSTTOOPPPPEEDD(_s_t_a_t_u_s)
             True if the process has not terminated, but has stopped and can
             be restarted.  This macro can be true only if the wait call spec-
             ified the WUNTRACED option or if the child process is being
             traced (see ptrace(2)).

     Depending on the values of those macros, the following macros produce the
     remaining status information about the child process:

     WWEEXXIITTSSTTAATTUUSS(_s_t_a_t_u_s)
             If WWIIFFEEXXIITTEEDD(_s_t_a_t_u_s) is true, evaluates to the low-order 8 bits
             of the argument passed to _exit(2) or exit(2) by the child.

     WWTTEERRMMSSIIGG(_s_t_a_t_u_s)
             If WWIIFFSSIIGGNNAALLEEDD(_s_t_a_t_u_s) is true, evaluates to the number of the
             signal that caused the termination of the process.

     WWCCOORREEDDUUMMPP(_s_t_a_t_u_s)
             If WWIIFFSSIIGGNNAALLEEDD(_s_t_a_t_u_s) is true, evaluates as true if the termina-
             tion of the process was accompanied by the creation of a core
             file containing an image of the process when the signal was re-
             ceived.

     WWSSTTOOPPSSIIGG(_s_t_a_t_u_s)
             If WWIIFFSSTTOOPPPPEEDD(_s_t_a_t_u_s) is true, evaluates to the number of the
             signal that caused the process to stop.

NNOOTTEESS
     See sigaction(2) for a list of termination signals.  A status of 0 indi-
     cates normal termination.

     If a parent process terminates without waiting for all of its child pro-
     cesses to terminate, the remaining child processes are assigned the par-
     ent process 1 ID (the init process ID).

     If a signal is caught while any of the wwaaiitt() calls is pending, the call
     may be interrupted or restarted when the signal-catching routine returns,
     depending on the options in effect for the signal; see intro(2),  System
     call restart.

RREETTUURRNN VVAALLUUEESS
     If wwaaiit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.

     If wwaaiitt44(), wwaaiitt33() or wwaaiittppiidd() returns due to a stopped or terminated
     child process, the process ID of the child is returned to the calling
     process.  If there are no children not previously awaited, -1 is returned
     with _e_r_r_n_o set to [ECHILD]. Otherwise, if WNOHANG is specified and there
     are no stopped or exited children, 0 is returned.  If an error is detect-
     ed or a caught signal aborts the call, a value of -1 is returned and
     _e_r_r_n_o is set to indicate the error.

EERRRROORRSS
     WWaaiitt() will fail and return immediately if:

     [ECHILD]      The calling process has no existing unwaited-for child pro-

                   cesses.

     [EFAULT]      The _s_t_a_t_u_s or _r_u_s_a_g_e arguments point to an illegal address.
                   (May not be detected before exit of a child process.)

     [EINTR]       The call was interrupted by a caught signal, or the signal
                   did not have the SA_RESTART flag set.

SSTTAANNDDAARRDDSS
     The wwaaiitt() and wwaaiittppiidd() functions are defined by POSIX; wwaaiitt44() and
     wwaaiitt33() are not specified by POSIX.  The WWCCOORREEDDUUMMPP() macro and the abili-
     ty to restart a pending wwaaiitt() call are extensions to the POSIX inter-
     face.

SSEEEE AALLSSOO
     exit(2),  sigaction(2)

HHIISSTTOORRYY
     A wwaaiitt function call appeared in Version 6 AT&T UNIX.

4th Berkeley Distribution       March 10, 1991                               3













































