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 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 _i_n_f_o_p.  The
       fields of the structure pointed to by _i_n_f_o_p are filled in as described
       for the SIGCHLD signal in _<_s_i_g_n_a_l_._h_>.  If a child process changed state
       prior to the call to _w_a_i_t_i_d(), _w_a_i_t_i_d() shall return immediately. If
       more than one thread is suspended in _w_a_i_t(), _w_a_i_t_i_d(), or _w_a_i_t_p_i_d()
       waiting for termination of the same process, exactly one thread shall
       return the process status at the time of the target process
       termination.

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

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _e_x_e_c, _e_x_i_t(), _w_a_i_t()

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

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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                  2013                            WAITID(3)
