WAITID(3)                  POSIX Programmer's Manual                 WAITID(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       waitid -- wait for a child process to change state

SSYYNNOOPPSSIISS
       #include <sys/wait.h>

       int waitid(idtype_t _i_d_t_y_p_e, id_t _i_d, siginfo_t *_i_n_f_o_p, int _o_p_t_i_o_n_s);

DDEESSCCRRIIPPTTIIOONN
       The _w_a_i_t_i_d() function shall obtain status information (see _S_e_c_t_i_o_n
       _2_._1_3, _S_t_a_t_u_s _I_n_f_o_r_m_a_t_i_o_n) pertaining to termination, stop, and/or
       continue events in one of the caller's child processes.

       The _w_a_i_t_i_d() function shall cause the calling thread to become blocked
       until an error occurs or status information becomes available to the
       calling thread that satisfies all of the following properties
       (``matching status information''):

        *  The status information is from one of the child processes in the
           set of child processes specified by the _i_d_t_y_p_e and _i_d arguments.

        *  The state change in the status information matches one of the state
           change flags set in the _o_p_t_i_o_n_s argument.

       If matching status information is available prior to the call to
       _w_a_i_t_i_d(), return shall be immediate. If matching status information is
       available for two or more child processes, the order in which their
       status is reported is unspecified.

       As described in _S_e_c_t_i_o_n _2_._1_3, _S_t_a_t_u_s _I_n_f_o_r_m_a_t_i_o_n, the _w_a_i_t_i_d() function
       consumes the status information it obtains unless the WNOWAIT flag is
       set in the _o_p_t_i_o_n_s argument.

       The behavior when multiple threads are blocked in _w_a_i_t(), _w_a_i_t_i_d(), or
       _w_a_i_t_p_i_d() is described in _S_e_c_t_i_o_n _2_._1_3, _S_t_a_t_u_s _I_n_f_o_r_m_a_t_i_o_n.

       The _w_a_i_t_i_d() function shall record the obtained status information in
       the structure pointed to by _i_n_f_o_p.  The fields of the structure pointed
       to by _i_n_f_o_p shall be filled in as described under ``Pointer to a
       Function'' in _S_e_c_t_i_o_n _2_._4_._3, _S_i_g_n_a_l _A_c_t_i_o_n_s.

       The _i_d_t_y_p_e and _i_d arguments are used to specify which children _w_a_i_t_i_d()
       waits for.

       If _i_d_t_y_p_e is P_PID, _w_a_i_t_i_d() shall wait for the child with a process ID
       equal to (ppiidd__tt)_i_d.

       If _i_d_t_y_p_e is P_PGID, _w_a_i_t_i_d() shall wait for any child with a process
       group ID equal to (ppiidd__tt)_i_d.

       If _i_d_t_y_p_e is P_ALL, _w_a_i_t_i_d() shall wait for any children and _i_d is
       ignored.

       The _o_p_t_i_o_n_s argument is used to specify which state changes _w_a_i_t_i_d()
       shall wait for. It is formed by OR'ing together the following flags:

       WCONTINUED  Status shall be returned for any continued child process
                   whose status either has not been reported since it
                   continued from a job control stop or has been reported only
                   by calls to _w_a_i_t_i_d() with the WNOWAIT flag set.

       WEXITED     Wait for processes that have exited.

       WNOHANG     Do not hang if no status is available; return immediately.

       WNOWAIT     Keep the process whose status is returned in _i_n_f_o_p in a
                   waitable state. This shall not affect the state of the
                   process; the process may be waited for again after this
                   call completes.

       WSTOPPED    Status shall be returned for any child that has stopped
                   upon receipt of a signal, and whose status either has not
                   been reported since it stopped or has been reported only by
                   calls to _w_a_i_t_i_d() with the WNOWAIT flag set.

       Applications shall specify at least one of the flags WEXITED, WSTOPPED,
       or WCONTINUED to be OR'ed in with the _o_p_t_i_o_n_s argument.

       The application shall ensure that the _i_n_f_o_p argument points to a
       ssiiggiinnffoo__tt structure. If _w_a_i_t_i_d() returns because a child process was
       found that satisfied the conditions indicated by the arguments _i_d_t_y_p_e
       and _o_p_t_i_o_n_s, then the structure pointed to by _i_n_f_o_p shall be filled in
       by the system with the status of the process; the _s_i___s_i_g_n_o member shall
       be set equal to SIGCHLD.  If _w_a_i_t_i_d() returns because WNOHANG was
       specified and status is not available for any process specified by
       _i_d_t_y_p_e and _i_d, then the _s_i___s_i_g_n_o and _s_i___p_i_d members of the structure
       pointed to by _i_n_f_o_p shall be set to zero and the values of other
       members of the structure are unspecified.

RREETTUURRNN VVAALLUUEE
       If WNOHANG was specified and status is not available for any process
       specified by _i_d_t_y_p_e and _i_d, 0 shall be returned. If _w_a_i_t_i_d() returns
       due to the change of state of one of its children, 0 shall be returned.
       Otherwise, -1 shall be returned and _e_r_r_n_o set to indicate the error.

EERRRROORRSS
       The _w_a_i_t_i_d() function shall fail if:

       EECCHHIILLDD The calling process has no existing unwaited-for child
              processes.

       EEIINNTTRR  The _w_a_i_t_i_d() function was interrupted by a signal.

       EEIINNVVAALL An invalid value was specified for _o_p_t_i_o_n_s, or _i_d_t_y_p_e and _i_d
              specify an invalid set of processes.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       Calls to _w_a_i_t_i_d() with _i_d_t_y_p_e equal to P_ALL will collect information
       about any child process. This may result in interactions with other
       interfaces that may be waiting for their own children (such as by use
       of _s_y_s_t_e_m()).  For this reason it is recommended that portable
       applications not use _w_a_i_t_i_d() with idtype of P_ALL. See also
       APPLICATION USAGE for _w_a_i_t().

       As specified in _C_o_n_s_e_q_u_e_n_c_e_s _o_f _P_r_o_c_e_s_s _T_e_r_m_i_n_a_t_i_o_n, if the calling
       process has SA_NOCLDWAIT set or has SIGCHLD set to SIG_IGN, then the
       termination of a child process will not cause status information to
       become available to a thread blocked in _w_a_i_t(), _w_a_i_t_i_d(), or _w_a_i_t_p_i_d().
       Thus, a thread blocked in one of the wait functions will remain blocked
       unless some other condition causes the thread to resume execution (such
       as an [[EECCHHIILLDD]] failure due to no remaining children in the set of
       waited-for children).

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._4_._3, _S_i_g_n_a_l _A_c_t_i_o_n_s, _S_e_c_t_i_o_n _2_._1_3, _S_t_a_t_u_s _I_n_f_o_r_m_a_t_i_o_n, _e_x_e_c,
       _e_x_i_t(), _w_a_i_t()

       The Base Definitions volume of POSIX.1-2017, <<ssiiggnnaall..hh>>, <<ssyyss__wwaaiitt..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                            WAITID(3)
