1WAITID(3P)                 POSIX Programmer's Manual                WAITID(3P)
2
3
4

PROLOG

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

NAME

12       waitid — wait for a child process to change state
13

SYNOPSIS

15       #include <sys/wait.h>
16
17       int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
18

DESCRIPTION

20       The waitid() function shall  obtain  status  information  (see  Section
21       2.13,  Status Information) pertaining to termination, stop, and/or con‐
22       tinue events in one of the caller's child processes.
23
24       The waitid() function shall cause the calling thread to become  blocked
25       until  an  error  occurs or status information becomes available to the
26       calling thread that satisfies all of the following properties (``match‐
27       ing status information''):
28
29        *  The  status  information  is from one of the child processes in the
30           set of child processes specified by the idtype and id arguments.
31
32        *  The state change in the status information matches one of the state
33           change flags set in the options argument.
34
35       If  matching  status  information  is  available  prior  to the call to
36       waitid(), return shall be immediate. If matching status information  is
37       available  for  two  or  more child processes, the order in which their
38       status is reported is unspecified.
39
40       As described in Section 2.13, Status Information, the waitid() function
41       consumes  the  status information it obtains unless the WNOWAIT flag is
42       set in the options argument.
43
44       The behavior when multiple threads are blocked in wait(), waitid(),  or
45       waitpid() is described in Section 2.13, Status Information.
46
47       The  waitid()  function shall record the obtained status information in
48       the structure pointed to by infop.  The fields of the structure pointed
49       to  by infop shall be filled in as described under ``Pointer to a Func‐
50       tion'' in Section 2.4.3, Signal Actions.
51
52       The idtype and id arguments are used to specify which children waitid()
53       waits for.
54
55       If idtype is P_PID, waitid() shall wait for the child with a process ID
56       equal to (pid_t)id.
57
58       If idtype is P_PGID, waitid() shall wait for any child with  a  process
59       group ID equal to (pid_t)id.
60
61       If  idtype  is  P_ALL,  waitid()  shall wait for any children and id is
62       ignored.
63
64       The options argument is used to specify which  state  changes  waitid()
65       shall wait for. It is formed by OR'ing together the following flags:
66
67       WCONTINUED  Status  shall  be  returned for any continued child process
68                   whose status either has not been reported since it  contin‐
69                   ued  from  a  job control stop or has been reported only by
70                   calls to waitid() with the WNOWAIT flag set.
71
72       WEXITED     Wait for processes that have exited.
73
74       WNOHANG     Do not hang if no status is available; return immediately.
75
76       WNOWAIT     Keep the process whose status is returned  in  infop  in  a
77                   waitable  state.  This  shall  not  affect the state of the
78                   process; the process may be waited  for  again  after  this
79                   call completes.
80
81       WSTOPPED    Status  shall  be  returned  for any child that has stopped
82                   upon receipt of a signal, and whose status either  has  not
83                   been reported since it stopped or has been reported only by
84                   calls to waitid() with the WNOWAIT flag set.
85
86       Applications shall specify at least one of the flags WEXITED, WSTOPPED,
87       or WCONTINUED to be OR'ed in with the options argument.
88
89       The  application  shall ensure that the infop argument points to a sig‐
90       info_t structure. If waitid() returns because a child process was found
91       that  satisfied  the  conditions  indicated by the arguments idtype and
92       options, then the structure pointed to by infop shall be filled  in  by
93       the system with the status of the process; the si_signo member shall be
94       set equal to SIGCHLD.  If waitid() returns because WNOHANG  was  speci‐
95       fied  and  status  is not available for any process specified by idtype
96       and id, then the si_signo and si_pid members of the  structure  pointed
97       to by infop shall be set to zero and the values of other members of the
98       structure are unspecified.
99

RETURN VALUE

101       If WNOHANG was specified and status is not available  for  any  process
102       specified  by  idtype  and id, 0 shall be returned. If waitid() returns
103       due to the change of state of one of its children, 0 shall be returned.
104       Otherwise, -1 shall be returned and errno set to indicate the error.
105

ERRORS

107       The waitid() function shall fail if:
108
109       ECHILD The  calling  process  has  no  existing unwaited-for child pro‐
110              cesses.
111
112       EINTR  The waitid() function was interrupted by a signal.
113
114       EINVAL An invalid value was specified for options,  or  idtype  and  id
115              specify an invalid set of processes.
116
117       The following sections are informative.
118

EXAMPLES

120       None.
121

APPLICATION USAGE

123       Calls  to  waitid() with idtype equal to P_ALL will collect information
124       about any child process. This may result  in  interactions  with  other
125       interfaces  that  may be waiting for their own children (such as by use
126       of system()).  For this reason it is recommended that portable applica‐
127       tions not use waitid() with idtype of P_ALL. See also APPLICATION USAGE
128       for wait().
129
130       As specified in Consequences of Process  Termination,  if  the  calling
131       process  has  SA_NOCLDWAIT  set or has SIGCHLD set to SIG_IGN, then the
132       termination of a child process will not  cause  status  information  to
133       become available to a thread blocked in wait(), waitid(), or waitpid().
134       Thus, a thread blocked in one of the wait functions will remain blocked
135       unless some other condition causes the thread to resume execution (such
136       as an [ECHILD] failure due to no  remaining  children  in  the  set  of
137       waited-for children).
138

RATIONALE

140       None.
141

FUTURE DIRECTIONS

143       None.
144

SEE ALSO

146       Section  2.4.3, Signal Actions, Section 2.13, Status Information, exec,
147       exit(), wait()
148
149       The Base Definitions volume of POSIX.1‐2017, <signal.h>, <sys_wait.h>
150
152       Portions of this text are reprinted and reproduced in  electronic  form
153       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
154       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
155       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
156       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
157       event of any discrepancy between this version and the original IEEE and
158       The Open Group Standard, the original IEEE and The Open Group  Standard
159       is  the  referee document. The original Standard can be obtained online
160       at http://www.opengroup.org/unix/online.html .
161
162       Any typographical or formatting errors that appear  in  this  page  are
163       most likely to have been introduced during the conversion of the source
164       files to man page format. To report such errors,  see  https://www.ker
165       nel.org/doc/man-pages/reporting_bugs.html .
166
167
168
169IEEE/The Open Group                  2017                           WAITID(3P)
Impressum