| WAITID(2) | System Calls Manual | WAITID(2) |
waitid — wait for
process state change
#include
<sys/wait.h>
int
waitid(idtype_t
idtype, id_t id,
siginfo_t *infop,
int options);
The
waitid()
function suspends execution of its calling process until a selected state
change occurs for a matching child process, or a signal is received.
The set of child processes to be queried is specified by the arguments idtype and id.
P_PID,
waitid()
waits for the child process with a process ID equal to
(pid_t)id.P_PGID,
waitid() waits for the child process with a
process group ID equal to (pid_t)id.P_ALL,
waitid() waits for any child process and the
id is ignored.The options argument is the bitwise OR of zero or more of the following values:
WCONTINUEDSIGCONT signal.WEXITEDWNOHANGWNOWAITWSTOPPEDSIGTTIN, SIGTTOU,
SIGTSTP, or SIGSTOP
signal.WTRAPPEDAt least one of WCONTINUED,
WEXITED, WSTOPPED, or
WTRAPPED must be specified.
If
waitid()
found a matching process, the structure referenced by
infop is filled with the status of the process:
si_signo is set to SIGCHLD,
and si_pid and si_uid are set to
the process ID and effective user ID of the matched process.
si_code will be set to one of the following
values:
CLD_CONTINUEDSIGCONT. Only returned if
options includes
WCONTINUED.CLD_DUMPEDWEXITED.CLD_EXITEDWEXITED.CLD_KILLEDWEXITED.CLD_STOPPEDWSTOPPED.CLD_TRAPPEDWTRAPPED.If WNOHANG was specified and
waitid()
didn't find a matching process, si_signo and
si_pid will be set to zero.
If waitid() returns because one or more
processes have a state change to report, 0 is returned. If an error is
detected, a value of -1 is returned and errno is set
to indicate the error. If WNOHANG is specified and
there are no stopped, continued or exited children, 0 is returned.
waitid() will fail and return immediately
if:
ECHILD]ECHILD]SIGCHLD or setting the flag
SA_NOCLDWAIT for that signal.EFAULT]EINTR]SA_RESTART flag set.EINVAL]The waitid() function conforms to
IEEE Std 1003.1-2008 (“POSIX.1”). The
WTRAPPED macro is an extension to that
specification.
| December 20, 2022 | openbsd |