WAITID(3POSIX)
π WAITID(3POSIX) π
okay so bestie, welcome to the POSIX Programmer's Manual β¨ this one is waitid(3POSIX) and she is so important for anyone out here reaping children (process children, obviously π«Ά).
πΈ PROLOG πΈ
real talk before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the actual Linux behavior, no cap), or honestly the interface may not even be implemented on Linux at all. vibe check: don't assume, verify π
β¨ NAME β¨
waitid β wait for a child process to change state
like, you're sitting there waiting for your child process to do something. iconic behavior. π
π SYNOPSIS π
#include <sys/wait.h>
int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
π¦ DESCRIPTION π¦
so the waitid() function shall obtain status information (peep Section 2.13, Status Information) about termination, stop, and/or continue events in one of the caller's child processes. all the drama, all the tea. β
The waitid() 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 (we call this ``matching status information'' π):
- The status information is from one of the child processes in the set of child processes specified by the
idtypeandidarguments. - The state change in the status information matches one of the state change flags set in the
optionsargument.
If matching status information is available prior to the call to waitid(), return shall be immediate. no waiting, we're not doing that today. If matching status information is available for two or more child processes, the order in which their status is reported is unspecified (so like, don't build your whole personality around which one comes first π).
As described in Section 2.13, Status Information, the waitid() function consumes the status information it obtains β unless the WNOWAIT flag is set in the options argument. so WNOWAIT is the "look but don't touch" flag, love that for her.
The behavior when multiple threads are blocked in wait(), waitid(), or waitpid() is described in Section 2.13, Status Information. (yes bestie, it's a whole group chat in there.)
The waitid() function shall record the obtained status information in the structure pointed to by infop. The fields of the structure pointed to by infop shall be filled in as described under ``Pointer to a Function'' in Section 2.4.3, Signal Actions.
The idtype and id arguments are used to specify which children waitid() waits for. here's the lineup:
- If
idtypeisP_PID,waitid()shall wait for the child with a process ID equal to(pid_t)id. - If
idtypeisP_PGID,waitid()shall wait for any child with a process group ID equal to(pid_t)id. - If
idtypeisP_ALL,waitid()shall wait for any children andidis ignored. (she said "any of y'all, idk, idc" π)
The options argument is used to specify which state changes waitid() 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 towaitid()with theWNOWAITflag set.WEXITEDβ Wait for processes that have exited.WNOHANGβ Do not hang if no status is available; return immediately. (the "bestie I have plans" flag β¨)WNOWAITβ Keep the process whose status is returned ininfopin 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 towaitid()with theWNOWAITflag set.
π¨ Applications shall specify at least one of the flagsWEXITED,WSTOPPED, orWCONTINUEDto be OR'ed in with theoptionsargument. this is not optional, this is the rule, periodt.
The application shall ensure that the infop argument points to a siginfo_t structure. If waitid() returns because a child process was found that satisfied the conditions indicated by the arguments idtype and options, then the structure pointed to by infop shall be filled in by the system with the status of the process; the si_signo member shall be set equal to SIGCHLD. If waitid() returns because WNOHANG was specified and status is not available for any process specified by idtype and id, then the si_signo and si_pid members of the structure pointed to by infop shall be set to zero and the values of other members of the structure are unspecified. (so like, don't read those other fields, they're giving chaos π)
π RETURN VALUE π
- If
WNOHANGwas specified and status is not available for any process specified byidtypeandid,0shall be returned. - If
waitid()returns due to the change of state of one of its children,0shall be returned. - Otherwise,
-1shall be returned anderrnoset to indicate the error.
slay. π
π₯ ERRORS π₯
The waitid() function shall fail if:
ECHILDβ The calling process has no existing unwaited-for child processes.EINTRβ Thewaitid()function was interrupted by a signal.EINVALβ An invalid value was specified foroptions, oridtypeandidspecify an invalid set of processes.
The following sections are informative. (aka: cute bonus content, not the law π)
π EXAMPLES π
None.
yeah. literally none. moving on bestie π
π§ APPLICATION USAGE π§
Calls to waitid() with idtype 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 system()). For this reason it is recommended that portable applications not use waitid() with idtype of P_ALL. See also APPLICATION USAGE for wait().
like, imagine stealing someone else's kid's status report. not the vibe. π
As specified in Consequences of Process Termination, 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 wait(), waitid(), or waitpid(). 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 [ECHILD] failure due to no remaining children in the set of waited-for children).
β οΈ so if you setSIG_IGNorSA_NOCLDWAITand then block in a wait function, bestie you may be there forever. that's not a bug, that's just the rules. π
β RATIONALE β
None.
(nothing to justify, she simply is β¨)
π¦ FUTURE DIRECTIONS π¦
None.
(she's perfect, no notes π)
π SEE ALSO π
Section 2.4.3, Signal Actions, Section 2.13, Status Information, exec, exit(), wait()
The Base Definitions volume of POSIX.1β2017, <signal.h>, <sys_wait.h>
π COPYRIGHT π
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 .
and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017 β stay waiting, stay iconic, WAITID(3POSIX) out π β¨π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms