1WAITID(3P) POSIX Programmer's Manual WAITID(3P)
2
3
4
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
11
13 waitid — wait for a child process to change state
14
16 #include <sys/wait.h>
17
18 int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
19
21 The waitid() function shall suspend the calling thread until one child
22 of the process containing the calling thread changes state. It records
23 the current state of a child in the structure pointed to by infop. The
24 fields of the structure pointed to by infop are filled in as described
25 for the SIGCHLD signal in <signal.h>. If a child process changed state
26 prior to the call to waitid(), waitid() shall return immediately. If
27 more than one thread is suspended in wait(), waitid(), or waitpid()
28 waiting for termination of the same process, exactly one thread shall
29 return the process status at the time of the target process termina‐
30 tion.
31
32 The idtype and id arguments are used to specify which children waitid()
33 waits for.
34
35 If idtype is P_PID, waitid() shall wait for the child with a process ID
36 equal to (pid_t)id.
37
38 If idtype is P_PGID, waitid() shall wait for any child with a process
39 group ID equal to (pid_t)id.
40
41 If idtype is P_ALL, waitid() shall wait for any children and id is
42 ignored.
43
44 The options argument is used to specify which state changes waitid()
45 shall wait for. It is formed by OR'ing together the following flags:
46
47 WCONTINUED Status shall be returned for any continued child process
48 whose status either has not been reported since it contin‐
49 ued from a job control stop or has been reported only by
50 calls to waitid() with the WNOWAIT flag set.
51
52 WEXITED Wait for processes that have exited.
53
54 WNOHANG Do not hang if no status is available; return immediately.
55
56 WNOWAIT Keep the process whose status is returned in infop in a
57 waitable state. This shall not affect the state of the
58 process; the process may be waited for again after this
59 call completes.
60
61 WSTOPPED Status shall be returned for any child that has stopped
62 upon receipt of a signal, and whose status either has not
63 been reported since it stopped or has been reported only by
64 calls to waitid() with the WNOWAIT flag set.
65
66 Applications shall specify at least one of the flags WEXITED, WSTOPPED,
67 or WCONTINUED to be OR'ed in with the options argument.
68
69 The application shall ensure that the infop argument points to a sig‐
70 info_t structure. If waitid() returns because a child process was found
71 that satisfied the conditions indicated by the arguments idtype and
72 options, then the structure pointed to by infop shall be filled in by
73 the system with the status of the process; the si_signo member shall be
74 set equal to SIGCHLD. If waitid() returns because WNOHANG was speci‐
75 fied and status is not available for any process specified by idtype
76 and id, then the si_signo and si_pid members of the structure pointed
77 to by infop shall be set to zero and the values of other members of the
78 structure are unspecified.
79
81 If WNOHANG was specified and status is not available for any process
82 specified by idtype and id, 0 shall be returned. If waitid() returns
83 due to the change of state of one of its children, 0 shall be returned.
84 Otherwise, −1 shall be returned and errno set to indicate the error.
85
87 The waitid() function shall fail if:
88
89 ECHILD The calling process has no existing unwaited-for child pro‐
90 cesses.
91
92 EINTR The waitid() function was interrupted by a signal.
93
94 EINVAL An invalid value was specified for options, or idtype and id
95 specify an invalid set of processes.
96
97 The following sections are informative.
98
100 None.
101
103 Calls to waitid() with idtype equal to P_ALL will collect information
104 about any child process. This may result in interactions with other
105 interfaces that may be waiting for their own children (such as by use
106 of system()). For this reason it is recommended that portable applica‐
107 tions not use waitid() with idtype of P_ALL. See also APPLICATION USAGE
108 for wait().
109
111 None.
112
114 None.
115
117 exec, exit(), wait()
118
119 The Base Definitions volume of POSIX.1‐2008, <signal.h>, <sys_wait.h>
120
122 Portions of this text are reprinted and reproduced in electronic form
123 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
124 -- Portable Operating System Interface (POSIX), The Open Group Base
125 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
126 cal and Electronics Engineers, Inc and The Open Group. (This is
127 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
128 event of any discrepancy between this version and the original IEEE and
129 The Open Group Standard, the original IEEE and The Open Group Standard
130 is the referee document. The original Standard can be obtained online
131 at http://www.unix.org/online.html .
132
133 Any typographical or formatting errors that appear in this page are
134 most likely to have been introduced during the conversion of the source
135 files to man page format. To report such errors, see https://www.ker‐
136 nel.org/doc/man-pages/reporting_bugs.html .
137
138
139
140IEEE/The Open Group 2013 WAITID(3P)