#include <sys/wait.h>

sys/wait.h

27 macros · 5 functions · 1 enum · 1 typedef · 1 union

enumidtype_t

[XSI] The type idtype_t shall be defined as an enumeration type whose possible values shall include at least P_ALL, P_PID, and P_PGID.
underlying type unsigned int
P_ALL0
P_PID1
P_PGID2

typedefidtype_t

typedef enum idtype_t idtype_t;

macroWNOHANG

Option bits for the third argument of wait4. WNOHANG causes the wait to not hang if there are no stopped or terminated processes, rather returning an error indication in this case (pid==0). WUNTRACED indicates that the caller should receive status about untraced children which stop due to signals. If children are stopped and a wait without this option is done, it is as though they were still running... nothing about them is returned.
#define WNOHANG 0x00000001
[XSI] no hang in wait/no child to reap

macroWUNTRACED

#define WUNTRACED 0x00000002
[XSI] notify on stop, untraced child

macro_W_INT

Macros to test the exit status returned by wait and extract the relevant values.
#define _W_INT(w) (*(int *)&(w))
convert union wait to int

macroWCOREFLAG

#define WCOREFLAG 0200

macro_WSTATUS

These macros are permited, as they are in the implementation namespace
#define _WSTATUS(x) (_W_INT(x) & 0177)

macro_WSTOPPED

#define _WSTOPPED 0177
_WSTATUS if process is stopped

macroWEXITSTATUS

[XSI] The <sys/wait.h> header shall define the following macros for analysis of process status values
#define WEXITSTATUS(x) ((_W_INT(x) >> 8) & 0x000000ff)

macroWSTOPSIG

0x13 == SIGCONT
#define WSTOPSIG(x) (_W_INT(x) >> 8)

macroWIFCONTINUED

#define WIFCONTINUED(x) (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) == 0x13)

macroWIFSTOPPED

#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) != 0x13)

macroWIFEXITED

#define WIFEXITED(x) (_WSTATUS(x) == 0)

macroWIFSIGNALED

#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)

macroWTERMSIG

#define WTERMSIG(x) (_WSTATUS(x))

macroWCOREDUMP

#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)

macroW_EXITCODE

#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))

macroW_STOPCODE

#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)

macroWEXITED

[XSI] The following symbolic constants shall be defined as possible values for the fourth argument to waitid(). WNOHANG already defined for wait4() WUNTRACED defined for wait4() but not for waitid()
#define WEXITED 0x00000004
[XSI] Processes which have exitted

macroWSTOPPED

waitid() parameter
#define WSTOPPED 0x00000008
[XSI] Any child stopped by signal

macroWCONTINUED

#define WCONTINUED 0x00000010
[XSI] Any child stopped then continued

macroWNOWAIT

#define WNOWAIT 0x00000020
[XSI] Leave process returned waitable

macroWAIT_ANY

Tokens for special values of the "pid" parameter to wait4.
#define WAIT_ANY (-1)
any process

macroWAIT_MYPGRP

#define WAIT_MYPGRP 0
any process in my process group

unionwait

Deprecated: Structure of the information in the status word returned by wait4. If w_stopval==_WSTOPPED, then the second structure describes the information returned, else the first.
size 4, align 4
intw_statusused in syscall
unnamed struct at sys/wait.h:199:2w_TTerminated process status.
unsigned int:7w_Termsigtermination signal
unsigned int:1w_Coredumpcore dump indicator
unsigned int:8w_Retcodeexit code if w_termsig==0
unsigned int:16w_Fillerupper bits filler
unnamed struct at sys/wait.h:217:2w_SStopped process status. Returned only for traced children unless requested with the WUNTRACED option bit.
unsigned int:8w_Stopval== W_STOPPED if stopped
unsigned int:8w_Stopsigsignal that stopped us
unsigned int:16w_Fillerupper bits filler

macrow_termsig

#define w_termsig w_T.w_Termsig

macrow_coredump

#define w_coredump w_T.w_Coredump

macrow_retcode

#define w_retcode w_T.w_Retcode

macrow_stopval

#define w_stopval w_S.w_Stopval

macrow_stopsig

#define w_stopsig w_S.w_Stopsig

functionwait

__DARWIN_ALIAS_C(wait)
pid_t wait(int *)
man page · April 19, 1994
wait(2) — wait for process termination

functionwaitpid

__DARWIN_ALIAS_C(waitpid)
pid_t waitpid(pid_t, int *, int)
man page · April 19, 1994
waitpid(2) — wait for process termination

functionwaitid

__DARWIN_ALIAS_C(waitid)
int waitid(idtype_t, id_t, siginfo_t *, int)

functionwait3

pid_t wait3(int *, int, struct rusage *)
man page · April 19, 1994
wait3(2) — wait for process termination

functionwait4

pid_t wait4(pid_t, int *, int, struct rusage *)
man page · April 19, 1994
wait4(2) — wait for process termination