1*8269e767SBrooks Davis.\" Copyright (c) 1980, 1991, 1993, 1994 2*8269e767SBrooks Davis.\" The Regents of the University of California. All rights reserved. 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 5*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 6*8269e767SBrooks Davis.\" are met: 7*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 8*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 9*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 11*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 12*8269e767SBrooks Davis.\" 3. Neither the name of the University nor the names of its contributors 13*8269e767SBrooks Davis.\" may be used to endorse or promote products derived from this software 14*8269e767SBrooks Davis.\" without specific prior written permission. 15*8269e767SBrooks Davis.\" 16*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17*8269e767SBrooks Davis.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*8269e767SBrooks Davis.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*8269e767SBrooks Davis.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20*8269e767SBrooks Davis.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*8269e767SBrooks Davis.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*8269e767SBrooks Davis.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*8269e767SBrooks Davis.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*8269e767SBrooks Davis.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*8269e767SBrooks Davis.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*8269e767SBrooks Davis.\" SUCH DAMAGE. 27*8269e767SBrooks Davis.\" 28*8269e767SBrooks Davis.Dd June 24, 2022 29*8269e767SBrooks Davis.Dt WAIT 2 30*8269e767SBrooks Davis.Os 31*8269e767SBrooks Davis.Sh NAME 32*8269e767SBrooks Davis.Nm wait , 33*8269e767SBrooks Davis.Nm waitid , 34*8269e767SBrooks Davis.Nm waitpid , 35*8269e767SBrooks Davis.Nm wait3 , 36*8269e767SBrooks Davis.Nm wait4 , 37*8269e767SBrooks Davis.Nm wait6 38*8269e767SBrooks Davis.Nd wait for processes to change status 39*8269e767SBrooks Davis.Sh LIBRARY 40*8269e767SBrooks Davis.Lb libc 41*8269e767SBrooks Davis.Sh SYNOPSIS 42*8269e767SBrooks Davis.In sys/wait.h 43*8269e767SBrooks Davis.Ft pid_t 44*8269e767SBrooks Davis.Fn wait "int *status" 45*8269e767SBrooks Davis.Ft pid_t 46*8269e767SBrooks Davis.Fn waitpid "pid_t wpid" "int *status" "int options" 47*8269e767SBrooks Davis.In signal.h 48*8269e767SBrooks Davis.Ft int 49*8269e767SBrooks Davis.Fn waitid "idtype_t idtype" "id_t id" "siginfo_t *info" "int options" 50*8269e767SBrooks Davis.In sys/time.h 51*8269e767SBrooks Davis.In sys/resource.h 52*8269e767SBrooks Davis.Ft pid_t 53*8269e767SBrooks Davis.Fn wait3 "int *status" "int options" "struct rusage *rusage" 54*8269e767SBrooks Davis.Ft pid_t 55*8269e767SBrooks Davis.Fn wait4 "pid_t wpid" "int *status" "int options" "struct rusage *rusage" 56*8269e767SBrooks Davis.Ft pid_t 57*8269e767SBrooks Davis.Fo wait6 58*8269e767SBrooks Davis.Fa "idtype_t idtype" "id_t id" 59*8269e767SBrooks Davis.Fa "int *status" 60*8269e767SBrooks Davis.Fa "int options" 61*8269e767SBrooks Davis.Fa "struct __wrusage *wrusage" 62*8269e767SBrooks Davis.Fa "siginfo_t *infop" 63*8269e767SBrooks Davis.Fc 64*8269e767SBrooks Davis.Sh DESCRIPTION 65*8269e767SBrooks DavisThe 66*8269e767SBrooks Davis.Fn wait 67*8269e767SBrooks Davisfunction suspends execution of its calling thread until 68*8269e767SBrooks Davis.Fa status 69*8269e767SBrooks Davisinformation is available for a child process 70*8269e767SBrooks Davisor a signal is received. 71*8269e767SBrooks DavisOn return from a successful 72*8269e767SBrooks Davis.Fn wait 73*8269e767SBrooks Daviscall, 74*8269e767SBrooks Davisthe 75*8269e767SBrooks Davis.Fa status 76*8269e767SBrooks Davisarea contains information about the process that reported a status change 77*8269e767SBrooks Davisas defined below. 78*8269e767SBrooks Davis.Pp 79*8269e767SBrooks DavisThe 80*8269e767SBrooks Davis.Fn wait4 81*8269e767SBrooks Davisand 82*8269e767SBrooks Davis.Fn wait6 83*8269e767SBrooks Davissystem calls provide a more general interface for programs 84*8269e767SBrooks Davisthat need to wait for specific child processes, 85*8269e767SBrooks Davisthat need resource utilization statistics accumulated by child processes, 86*8269e767SBrooks Davisor that require options. 87*8269e767SBrooks DavisThe other wait functions are implemented using either 88*8269e767SBrooks Davis.Fn wait4 89*8269e767SBrooks Davisor 90*8269e767SBrooks Davis.Fn wait6 . 91*8269e767SBrooks Davis.Pp 92*8269e767SBrooks DavisThe 93*8269e767SBrooks Davis.Fn wait6 94*8269e767SBrooks Davisfunction is the most general function in this family and its distinct 95*8269e767SBrooks Davisfeatures are: 96*8269e767SBrooks Davis.Pp 97*8269e767SBrooks DavisAll of the desired process statuses to be waited on must be explicitly 98*8269e767SBrooks Davisspecified in 99*8269e767SBrooks Davis.Fa options . 100*8269e767SBrooks DavisThe 101*8269e767SBrooks Davis.Fn wait , 102*8269e767SBrooks Davis.Fn waitpid , 103*8269e767SBrooks Davis.Fn wait3 , 104*8269e767SBrooks Davisand 105*8269e767SBrooks Davis.Fn wait4 106*8269e767SBrooks Davisfunctions all implicitly wait for exited and trapped processes, 107*8269e767SBrooks Davisbut the 108*8269e767SBrooks Davis.Fn waitid 109*8269e767SBrooks Davisand 110*8269e767SBrooks Davis.Fn wait6 111*8269e767SBrooks Davisfunctions require the corresponding 112*8269e767SBrooks Davis.Dv WEXITED 113*8269e767SBrooks Davisand 114*8269e767SBrooks Davis.Dv WTRAPPED 115*8269e767SBrooks Davisflags to be explicitly specified. 116*8269e767SBrooks DavisThis allows waiting for processes which have experienced other 117*8269e767SBrooks Davisstatus changes without having to also handle the exit status from 118*8269e767SBrooks Davisterminated processes. 119*8269e767SBrooks Davis.Pp 120*8269e767SBrooks DavisThe 121*8269e767SBrooks Davis.Fn wait6 122*8269e767SBrooks Davisfunction accepts a 123*8269e767SBrooks Davis.Fa wrusage 124*8269e767SBrooks Davisargument which points to a structure defined as: 125*8269e767SBrooks Davis.Bd -literal 126*8269e767SBrooks Davisstruct __wrusage { 127*8269e767SBrooks Davis struct rusage wru_self; 128*8269e767SBrooks Davis struct rusage wru_children; 129*8269e767SBrooks Davis}; 130*8269e767SBrooks Davis.Ed 131*8269e767SBrooks Davis.Pp 132*8269e767SBrooks DavisThis allows the calling process to collect resource usage statistics 133*8269e767SBrooks Davisfrom both its own child process as well as from its grand children. 134*8269e767SBrooks DavisWhen no resource usage statistics are needed this pointer can be 135*8269e767SBrooks Davis.Dv NULL . 136*8269e767SBrooks Davis.Pp 137*8269e767SBrooks DavisThe last argument 138*8269e767SBrooks Davis.Fa infop 139*8269e767SBrooks Davismust be either 140*8269e767SBrooks Davis.Dv NULL 141*8269e767SBrooks Davisor a pointer to a 142*8269e767SBrooks Davis.Fa siginfo_t 143*8269e767SBrooks Davisstructure. 144*8269e767SBrooks DavisIf 145*8269e767SBrooks Davis.Pf non- Dv NULL , 146*8269e767SBrooks Davisthe structure is filled with the same data as for a 147*8269e767SBrooks Davis.Dv SIGCHLD 148*8269e767SBrooks Davissignal delivered when the process changed state. 149*8269e767SBrooks Davis.Pp 150*8269e767SBrooks DavisThe set of child processes to be queried is specified by the arguments 151*8269e767SBrooks Davis.Fa idtype 152*8269e767SBrooks Davisand 153*8269e767SBrooks Davis.Fa id . 154*8269e767SBrooks DavisThe separate 155*8269e767SBrooks Davis.Fa idtype 156*8269e767SBrooks Davisand 157*8269e767SBrooks Davis.Fa id 158*8269e767SBrooks Davisarguments support many other types of 159*8269e767SBrooks Davisidentifiers in addition to process IDs and process group IDs. 160*8269e767SBrooks Davis.Bl -bullet -offset indent 161*8269e767SBrooks Davis.It 162*8269e767SBrooks DavisIf 163*8269e767SBrooks Davis.Fa idtype 164*8269e767SBrooks Davisis 165*8269e767SBrooks Davis.Dv P_PID , 166*8269e767SBrooks Davis.Fn waitid 167*8269e767SBrooks Davisand 168*8269e767SBrooks Davis.Fn wait6 169*8269e767SBrooks Daviswait for the child process with a process ID equal to 170*8269e767SBrooks Davis.Dv (pid_t)id . 171*8269e767SBrooks Davis.It 172*8269e767SBrooks DavisIf 173*8269e767SBrooks Davis.Fa idtype 174*8269e767SBrooks Davisis 175*8269e767SBrooks Davis.Dv P_PGID , 176*8269e767SBrooks Davis.Fn waitid 177*8269e767SBrooks Davisand 178*8269e767SBrooks Davis.Fn wait6 179*8269e767SBrooks Daviswait for the child process with a process group ID equal to 180*8269e767SBrooks Davis.Dv (pid_t)id . 181*8269e767SBrooks Davis.It 182*8269e767SBrooks DavisIf 183*8269e767SBrooks Davis.Fa idtype 184*8269e767SBrooks Davisis 185*8269e767SBrooks Davis.Dv P_ALL , 186*8269e767SBrooks Davis.Fn waitid 187*8269e767SBrooks Davisand 188*8269e767SBrooks Davis.Fn wait6 189*8269e767SBrooks Daviswait for any child process and the 190*8269e767SBrooks Davis.Dv id 191*8269e767SBrooks Davisis ignored. 192*8269e767SBrooks Davis.It 193*8269e767SBrooks DavisIf 194*8269e767SBrooks Davis.Fa idtype 195*8269e767SBrooks Davisis 196*8269e767SBrooks Davis.Dv P_PID 197*8269e767SBrooks Davisor 198*8269e767SBrooks Davis.Dv P_PGID 199*8269e767SBrooks Davisand the 200*8269e767SBrooks Davis.Dv id 201*8269e767SBrooks Davisis zero, 202*8269e767SBrooks Davis.Fn waitid 203*8269e767SBrooks Davisand 204*8269e767SBrooks Davis.Fn wait6 205*8269e767SBrooks Daviswait for any child process in the same process group as the caller. 206*8269e767SBrooks Davis.El 207*8269e767SBrooks Davis.Pp 208*8269e767SBrooks DavisNon-standard identifier types supported by this 209*8269e767SBrooks Davisimplementation of 210*8269e767SBrooks Davis.Fn waitid 211*8269e767SBrooks Davisand 212*8269e767SBrooks Davis.Fn wait6 213*8269e767SBrooks Davisare: 214*8269e767SBrooks Davis.Bl -tag -width P_JAILID 215*8269e767SBrooks Davis.It Dv P_UID 216*8269e767SBrooks DavisWait for processes whose effective user ID is equal to 217*8269e767SBrooks Davis.Dv (uid_t) Fa id . 218*8269e767SBrooks Davis.It Dv P_GID 219*8269e767SBrooks DavisWait for processes whose effective group ID is equal to 220*8269e767SBrooks Davis.Dv (gid_t) Fa id . 221*8269e767SBrooks Davis.It Dv P_SID 222*8269e767SBrooks DavisWait for processes whose session ID is equal to 223*8269e767SBrooks Davis.Fa id . 224*8269e767SBrooks Davis.\" This is just how sessions work, not sure this needs to be documented here 225*8269e767SBrooks DavisIf the child process started its own session, 226*8269e767SBrooks Davisits session ID will be the same as its process ID. 227*8269e767SBrooks DavisOtherwise the session ID of a child process will match the caller's session ID. 228*8269e767SBrooks Davis.It Dv P_JAILID 229*8269e767SBrooks DavisWaits for processes within a jail whose jail identifier is equal to 230*8269e767SBrooks Davis.Fa id . 231*8269e767SBrooks Davis.El 232*8269e767SBrooks Davis.Pp 233*8269e767SBrooks DavisFor the 234*8269e767SBrooks Davis.Fn waitpid 235*8269e767SBrooks Davisand 236*8269e767SBrooks Davis.Fn wait4 237*8269e767SBrooks Davisfunctions, the single 238*8269e767SBrooks Davis.Fa wpid 239*8269e767SBrooks Davisargument specifies the set of child processes for which to wait. 240*8269e767SBrooks Davis.Bl -bullet -offset indent 241*8269e767SBrooks Davis.It 242*8269e767SBrooks DavisIf 243*8269e767SBrooks Davis.Fa wpid 244*8269e767SBrooks Davisis -1, the call waits for any child process. 245*8269e767SBrooks Davis.It 246*8269e767SBrooks DavisIf 247*8269e767SBrooks Davis.Fa wpid 248*8269e767SBrooks Davisis 0, 249*8269e767SBrooks Davisthe call waits for any child process in the process group of the caller. 250*8269e767SBrooks Davis.It 251*8269e767SBrooks DavisIf 252*8269e767SBrooks Davis.Fa wpid 253*8269e767SBrooks Davisis greater than zero, the call waits for the process with process ID 254*8269e767SBrooks Davis.Fa wpid . 255*8269e767SBrooks Davis.It 256*8269e767SBrooks DavisIf 257*8269e767SBrooks Davis.Fa wpid 258*8269e767SBrooks Davisis less than -1, the call waits for any process whose process group ID 259*8269e767SBrooks Davisequals the absolute value of 260*8269e767SBrooks Davis.Fa wpid . 261*8269e767SBrooks Davis.El 262*8269e767SBrooks Davis.Pp 263*8269e767SBrooks DavisThe 264*8269e767SBrooks Davis.Fa status 265*8269e767SBrooks Davisargument is defined below. 266*8269e767SBrooks Davis.Pp 267*8269e767SBrooks DavisThe 268*8269e767SBrooks Davis.Fa options 269*8269e767SBrooks Davisargument contains the bitwise OR of any of the following options. 270*8269e767SBrooks Davis.Bl -tag -width WCONTINUED 271*8269e767SBrooks Davis.It Dv WCONTINUED 272*8269e767SBrooks DavisReport the status of selected processes that 273*8269e767SBrooks Davishave continued from a job control stop by receiving a 274*8269e767SBrooks Davis.Dv SIGCONT 275*8269e767SBrooks Davissignal. 276*8269e767SBrooks Davis.It Dv WNOHANG 277*8269e767SBrooks DavisDo not block when 278*8269e767SBrooks Davisthere are no processes wishing to report status. 279*8269e767SBrooks Davis.It Dv WUNTRACED 280*8269e767SBrooks DavisReport the status of selected processes which are stopped due to a 281*8269e767SBrooks Davis.Dv SIGTTIN , SIGTTOU , SIGTSTP , 282*8269e767SBrooks Davisor 283*8269e767SBrooks Davis.Dv SIGSTOP 284*8269e767SBrooks Davissignal. 285*8269e767SBrooks Davis.It Dv WSTOPPED 286*8269e767SBrooks DavisAn alias for 287*8269e767SBrooks Davis.Dv WUNTRACED . 288*8269e767SBrooks Davis.It Dv WTRAPPED 289*8269e767SBrooks DavisReport the status of selected processes which are being traced via 290*8269e767SBrooks Davis.Xr ptrace 2 291*8269e767SBrooks Davisand have trapped or reached a breakpoint. 292*8269e767SBrooks DavisThis flag is implicitly set for the functions 293*8269e767SBrooks Davis.Fn wait , 294*8269e767SBrooks Davis.Fn waitpid , 295*8269e767SBrooks Davis.Fn wait3 , 296*8269e767SBrooks Davisand 297*8269e767SBrooks Davis.Fn wait4 . 298*8269e767SBrooks Davis.br 299*8269e767SBrooks DavisFor the 300*8269e767SBrooks Davis.Fn waitid 301*8269e767SBrooks Davisand 302*8269e767SBrooks Davis.Fn wait6 303*8269e767SBrooks Davisfunctions, the flag has to be explicitly included in 304*8269e767SBrooks Davis.Fa options 305*8269e767SBrooks Davisif status reports from trapped processes are expected. 306*8269e767SBrooks Davis.It Dv WEXITED 307*8269e767SBrooks DavisReport the status of selected processes which have terminated. 308*8269e767SBrooks DavisThis flag is implicitly set for the functions 309*8269e767SBrooks Davis.Fn wait , 310*8269e767SBrooks Davis.Fn waitpid , 311*8269e767SBrooks Davis.Fn wait3 , 312*8269e767SBrooks Davisand 313*8269e767SBrooks Davis.Fn wait4 . 314*8269e767SBrooks Davis.br 315*8269e767SBrooks DavisFor the 316*8269e767SBrooks Davis.Fn waitid 317*8269e767SBrooks Davisand 318*8269e767SBrooks Davis.Fn wait6 319*8269e767SBrooks Davisfunctions, the flag has to be explicitly included in 320*8269e767SBrooks Davis.Fa options 321*8269e767SBrooks Davisif status reports from terminated processes are expected. 322*8269e767SBrooks Davis.It Dv WNOWAIT 323*8269e767SBrooks DavisKeep the process whose status is returned in a waitable state. 324*8269e767SBrooks DavisThe process may be waited for again after this call completes. 325*8269e767SBrooks Davis.El 326*8269e767SBrooks Davis.sp 327*8269e767SBrooks DavisFor the 328*8269e767SBrooks Davis.Fn waitid 329*8269e767SBrooks Davisand 330*8269e767SBrooks Davis.Fn wait6 331*8269e767SBrooks Davisfunctions, at least one of the options 332*8269e767SBrooks Davis.Dv WEXITED , 333*8269e767SBrooks Davis.Dv WUNTRACED , 334*8269e767SBrooks Davis.Dv WSTOPPED , 335*8269e767SBrooks Davis.Dv WTRAPPED , 336*8269e767SBrooks Davisor 337*8269e767SBrooks Davis.Dv WCONTINUED 338*8269e767SBrooks Davismust be specified. 339*8269e767SBrooks DavisOtherwise there will be no events for the call to report. 340*8269e767SBrooks DavisTo avoid hanging indefinitely in such a case these functions 341*8269e767SBrooks Davisreturn -1 with 342*8269e767SBrooks Davis.Dv errno 343*8269e767SBrooks Davisset to 344*8269e767SBrooks Davis.Dv EINVAL . 345*8269e767SBrooks Davis.Pp 346*8269e767SBrooks DavisIf 347*8269e767SBrooks Davis.Fa rusage 348*8269e767SBrooks Davisis non-NULL, a summary of the resources used by the terminated 349*8269e767SBrooks Davisprocess and all its children is returned. 350*8269e767SBrooks Davis.Pp 351*8269e767SBrooks DavisIf 352*8269e767SBrooks Davis.Fa wrusage 353*8269e767SBrooks Davisis non-NULL, separate summaries are returned for the resources used 354*8269e767SBrooks Davisby the terminated process and the resources used by all its children. 355*8269e767SBrooks Davis.Pp 356*8269e767SBrooks DavisIf 357*8269e767SBrooks Davis.Fa infop 358*8269e767SBrooks Davisis non-NULL, a 359*8269e767SBrooks Davis.Dv siginfo_t 360*8269e767SBrooks Davisstructure is returned with the 361*8269e767SBrooks Davis.Fa si_signo 362*8269e767SBrooks Davisfield set to 363*8269e767SBrooks Davis.Dv SIGCHLD 364*8269e767SBrooks Davisand the 365*8269e767SBrooks Davis.Fa si_pid 366*8269e767SBrooks Davisfield set to the process ID of the process reporting status. 367*8269e767SBrooks DavisFor the exited process, the 368*8269e767SBrooks Davis.Fa si_status 369*8269e767SBrooks Davisfield of the 370*8269e767SBrooks Davis.Dv siginfo_t 371*8269e767SBrooks Davisstructure contains the full 32 bit exit status passed to 372*8269e767SBrooks Davis.Xr _exit 2 ; 373*8269e767SBrooks Davisthe 374*8269e767SBrooks Davis.Fa status 375*8269e767SBrooks Davisargument of other calls only returns 8 lowest bits of the exit status. 376*8269e767SBrooks Davis.Pp 377*8269e767SBrooks DavisWhen the 378*8269e767SBrooks Davis.Dv WNOHANG 379*8269e767SBrooks Davisoption is specified and no processes 380*8269e767SBrooks Daviswish to report status, 381*8269e767SBrooks Davis.Fn waitid 382*8269e767SBrooks Davissets the 383*8269e767SBrooks Davis.Fa si_signo 384*8269e767SBrooks Davisand 385*8269e767SBrooks Davis.Fa si_pid 386*8269e767SBrooks Davisfields in 387*8269e767SBrooks Davis.Fa infop 388*8269e767SBrooks Davisto zero. 389*8269e767SBrooks DavisChecking these fields is the only way to know if a status change was reported. 390*8269e767SBrooks Davis.Pp 391*8269e767SBrooks DavisWhen the 392*8269e767SBrooks Davis.Dv WNOHANG 393*8269e767SBrooks Davisoption is specified and no processes 394*8269e767SBrooks Daviswish to report status, 395*8269e767SBrooks Davis.Fn wait4 396*8269e767SBrooks Davisand 397*8269e767SBrooks Davis.Fn wait6 398*8269e767SBrooks Davisreturn a 399*8269e767SBrooks Davisprocess id 400*8269e767SBrooks Davisof 0. 401*8269e767SBrooks Davis.Pp 402*8269e767SBrooks DavisThe 403*8269e767SBrooks Davis.Fn wait 404*8269e767SBrooks Daviscall is the same as 405*8269e767SBrooks Davis.Fn wait4 406*8269e767SBrooks Daviswith a 407*8269e767SBrooks Davis.Fa wpid 408*8269e767SBrooks Davisvalue of -1, 409*8269e767SBrooks Daviswith an 410*8269e767SBrooks Davis.Fa options 411*8269e767SBrooks Davisvalue of zero, 412*8269e767SBrooks Davisand a 413*8269e767SBrooks Davis.Fa rusage 414*8269e767SBrooks Davisvalue of 415*8269e767SBrooks Davis.Dv NULL . 416*8269e767SBrooks DavisThe 417*8269e767SBrooks Davis.Fn waitpid 418*8269e767SBrooks Davisfunction is identical to 419*8269e767SBrooks Davis.Fn wait4 420*8269e767SBrooks Daviswith an 421*8269e767SBrooks Davis.Fa rusage 422*8269e767SBrooks Davisvalue of 423*8269e767SBrooks Davis.Dv NULL . 424*8269e767SBrooks DavisThe older 425*8269e767SBrooks Davis.Fn wait3 426*8269e767SBrooks Daviscall is the same as 427*8269e767SBrooks Davis.Fn wait4 428*8269e767SBrooks Daviswith a 429*8269e767SBrooks Davis.Fa wpid 430*8269e767SBrooks Davisvalue of -1. 431*8269e767SBrooks DavisThe 432*8269e767SBrooks Davis.Fn wait4 433*8269e767SBrooks Davisfunction is identical to 434*8269e767SBrooks Davis.Fn wait6 435*8269e767SBrooks Daviswith the flags 436*8269e767SBrooks Davis.Dv WEXITED 437*8269e767SBrooks Davisand 438*8269e767SBrooks Davis.Dv WTRAPPED 439*8269e767SBrooks Davisset in 440*8269e767SBrooks Davis.Fa options 441*8269e767SBrooks Davisand 442*8269e767SBrooks Davis.Fa infop 443*8269e767SBrooks Davisset to 444*8269e767SBrooks Davis.Dv NULL . 445*8269e767SBrooks Davis.Pp 446*8269e767SBrooks DavisThe following macros may be used to test the current status of the process. 447*8269e767SBrooks DavisExactly one of the following four macros will evaluate to a non-zero 448*8269e767SBrooks Davis.Pq true 449*8269e767SBrooks Davisvalue: 450*8269e767SBrooks Davis.Bl -tag -width Ds 451*8269e767SBrooks Davis.It Fn WIFCONTINUED status 452*8269e767SBrooks DavisTrue if the process has not terminated, and 453*8269e767SBrooks Davishas continued after a job control stop. 454*8269e767SBrooks DavisThis macro can be true only if the wait call specified the 455*8269e767SBrooks Davis.Dv WCONTINUED 456*8269e767SBrooks Davisoption. 457*8269e767SBrooks Davis.It Fn WIFEXITED status 458*8269e767SBrooks DavisTrue if the process terminated normally by a call to 459*8269e767SBrooks Davis.Xr _exit 2 460*8269e767SBrooks Davisor 461*8269e767SBrooks Davis.Xr exit 3 . 462*8269e767SBrooks Davis.It Fn WIFSIGNALED status 463*8269e767SBrooks DavisTrue if the process terminated due to receipt of a signal. 464*8269e767SBrooks Davis.It Fn WIFSTOPPED status 465*8269e767SBrooks DavisTrue if the process has not terminated, but has stopped and can be restarted. 466*8269e767SBrooks DavisThis macro can be true only if the wait call specified the 467*8269e767SBrooks Davis.Dv WUNTRACED 468*8269e767SBrooks Davisoption 469*8269e767SBrooks Davisor if the child process is being traced (see 470*8269e767SBrooks Davis.Xr ptrace 2 ) . 471*8269e767SBrooks Davis.El 472*8269e767SBrooks Davis.Pp 473*8269e767SBrooks DavisDepending on the values of those macros, the following macros 474*8269e767SBrooks Davisproduce the remaining status information about the child process: 475*8269e767SBrooks Davis.Bl -tag -width Ds 476*8269e767SBrooks Davis.It Fn WEXITSTATUS status 477*8269e767SBrooks DavisIf 478*8269e767SBrooks Davis.Fn WIFEXITED status 479*8269e767SBrooks Davisis true, evaluates to the low-order 8 bits 480*8269e767SBrooks Davisof the argument passed to 481*8269e767SBrooks Davis.Xr _exit 2 482*8269e767SBrooks Davisor 483*8269e767SBrooks Davis.Xr exit 3 484*8269e767SBrooks Davisby the child. 485*8269e767SBrooks Davis.It Fn WTERMSIG status 486*8269e767SBrooks DavisIf 487*8269e767SBrooks Davis.Fn WIFSIGNALED status 488*8269e767SBrooks Davisis true, evaluates to the number of the signal 489*8269e767SBrooks Davisthat caused the termination of the process. 490*8269e767SBrooks Davis.It Fn WCOREDUMP status 491*8269e767SBrooks DavisIf 492*8269e767SBrooks Davis.Fn WIFSIGNALED status 493*8269e767SBrooks Davisis true, evaluates as true if the termination 494*8269e767SBrooks Davisof the process was accompanied by the creation of a core file 495*8269e767SBrooks Daviscontaining an image of the process when the signal was received. 496*8269e767SBrooks Davis.It Fn WSTOPSIG status 497*8269e767SBrooks DavisIf 498*8269e767SBrooks Davis.Fn WIFSTOPPED status 499*8269e767SBrooks Davisis true, evaluates to the number of the signal 500*8269e767SBrooks Davisthat caused the process to stop. 501*8269e767SBrooks Davis.El 502*8269e767SBrooks Davis.Sh NOTES 503*8269e767SBrooks DavisSee 504*8269e767SBrooks Davis.Xr sigaction 2 505*8269e767SBrooks Davisfor a list of termination signals. 506*8269e767SBrooks DavisA status of 0 indicates normal termination. 507*8269e767SBrooks Davis.Pp 508*8269e767SBrooks DavisIf a parent process terminates without 509*8269e767SBrooks Daviswaiting for all of its child processes to terminate, 510*8269e767SBrooks Davisthe remaining child processes are re-assigned to the reaper 511*8269e767SBrooks Davisof the exiting process as the parent, see 512*8269e767SBrooks Davis.Xr procctl 2 513*8269e767SBrooks Davis.Dv PROC_REAP_ACQUIRE . 514*8269e767SBrooks DavisIf no specific reaper was assigned, the process with ID 1, the init process, 515*8269e767SBrooks Davisbecomes the parent of the orphaned children by default. 516*8269e767SBrooks Davis.Pp 517*8269e767SBrooks DavisIf a signal is caught while any of the 518*8269e767SBrooks Davis.Fn wait 519*8269e767SBrooks Daviscalls are pending, 520*8269e767SBrooks Davisthe call may be interrupted or restarted when the signal-catching routine 521*8269e767SBrooks Davisreturns, 522*8269e767SBrooks Davisdepending on the options in effect for the signal; 523*8269e767SBrooks Davissee discussion of 524*8269e767SBrooks Davis.Dv SA_RESTART 525*8269e767SBrooks Davisin 526*8269e767SBrooks Davis.Xr sigaction 2 . 527*8269e767SBrooks Davis.Pp 528*8269e767SBrooks DavisThe implementation queues one 529*8269e767SBrooks Davis.Dv SIGCHLD 530*8269e767SBrooks Davissignal for each child process whose 531*8269e767SBrooks Davisstatus has changed; if 532*8269e767SBrooks Davis.Fn wait 533*8269e767SBrooks Davisreturns because the status of a child process is available, the pending 534*8269e767SBrooks DavisSIGCHLD signal associated with the process ID of the child process will 535*8269e767SBrooks Davisbe discarded. 536*8269e767SBrooks DavisAny other pending 537*8269e767SBrooks Davis.Dv SIGCHLD 538*8269e767SBrooks Davissignals remain pending. 539*8269e767SBrooks Davis.Pp 540*8269e767SBrooks DavisIf 541*8269e767SBrooks Davis.Dv SIGCHLD 542*8269e767SBrooks Davisis blocked and 543*8269e767SBrooks Davis.Fn wait 544*8269e767SBrooks Davisreturns because the status of a child process is available, the pending 545*8269e767SBrooks Davis.Dv SIGCHLD 546*8269e767SBrooks Davissignal will be cleared unless another status of the child process 547*8269e767SBrooks Davisis available. 548*8269e767SBrooks Davis.Sh RETURN VALUES 549*8269e767SBrooks DavisIf 550*8269e767SBrooks Davis.Fn wait 551*8269e767SBrooks Davisreturns due to a stopped, continued, 552*8269e767SBrooks Davisor terminated child process, the process ID of the child 553*8269e767SBrooks Davisis returned to the calling process. 554*8269e767SBrooks DavisOtherwise, a value of \-1 555*8269e767SBrooks Davisis returned and 556*8269e767SBrooks Davis.Va errno 557*8269e767SBrooks Davisis set to indicate the error. 558*8269e767SBrooks Davis.Pp 559*8269e767SBrooks DavisIf 560*8269e767SBrooks Davis.Fn wait6 , 561*8269e767SBrooks Davis.Fn wait4 , 562*8269e767SBrooks Davis.Fn wait3 , 563*8269e767SBrooks Davisor 564*8269e767SBrooks Davis.Fn waitpid 565*8269e767SBrooks Davisreturns due to a stopped, continued, 566*8269e767SBrooks Davisor terminated child process, the process ID of the child 567*8269e767SBrooks Davisis returned to the calling process. 568*8269e767SBrooks DavisIf there are no children not previously awaited, 569*8269e767SBrooks Davis-1 is returned with 570*8269e767SBrooks Davis.Va errno 571*8269e767SBrooks Davisset to 572*8269e767SBrooks Davis.Er ECHILD . 573*8269e767SBrooks DavisOtherwise, if 574*8269e767SBrooks Davis.Dv WNOHANG 575*8269e767SBrooks Davisis specified and there are 576*8269e767SBrooks Davisno stopped, continued or exited children, 577*8269e767SBrooks Davis0 is returned. 578*8269e767SBrooks DavisIf an error is detected or a caught signal aborts the call, 579*8269e767SBrooks Davisa value of -1 580*8269e767SBrooks Davisis returned and 581*8269e767SBrooks Davis.Va errno 582*8269e767SBrooks Davisis set to indicate the error. 583*8269e767SBrooks Davis.Pp 584*8269e767SBrooks DavisIf 585*8269e767SBrooks Davis.Fn waitid 586*8269e767SBrooks Davisreturns because one or more processes have a state change to report, 587*8269e767SBrooks Davis0 is returned. 588*8269e767SBrooks DavisIf an error is detected, 589*8269e767SBrooks Davisa value of -1 590*8269e767SBrooks Davisis returned and 591*8269e767SBrooks Davis.Va errno 592*8269e767SBrooks Davisis set to indicate the error. 593*8269e767SBrooks DavisIf 594*8269e767SBrooks Davis.Dv WNOHANG 595*8269e767SBrooks Davisis specified and there are 596*8269e767SBrooks Davisno stopped, continued or exited children, 597*8269e767SBrooks Davis0 is returned. 598*8269e767SBrooks DavisThe 599*8269e767SBrooks Davis.Fa si_signo 600*8269e767SBrooks Davisand 601*8269e767SBrooks Davis.Fa si_pid 602*8269e767SBrooks Davisfields of 603*8269e767SBrooks Davis.Fa infop 604*8269e767SBrooks Davismust be checked against zero to determine if a process reported status. 605*8269e767SBrooks Davis.Pp 606*8269e767SBrooks DavisThe 607*8269e767SBrooks Davis.Fn wait 608*8269e767SBrooks Davisfamily of functions will not return a child process created with 609*8269e767SBrooks Davis.Xr pdfork 2 610*8269e767SBrooks Davisunless specifically directed to do so by specifying its process ID. 611*8269e767SBrooks Davis.Sh ERRORS 612*8269e767SBrooks DavisThe 613*8269e767SBrooks Davis.Fn wait 614*8269e767SBrooks Davisfunction 615*8269e767SBrooks Daviswill fail and return immediately if: 616*8269e767SBrooks Davis.Bl -tag -width Er 617*8269e767SBrooks Davis.It Bq Er ECHILD 618*8269e767SBrooks DavisThe calling process has no existing unwaited-for 619*8269e767SBrooks Davischild processes. 620*8269e767SBrooks Davis.It Bq Er ECHILD 621*8269e767SBrooks DavisNo status from the terminated child process is available 622*8269e767SBrooks Davisbecause the calling process has asked the system to discard 623*8269e767SBrooks Davissuch status by ignoring the signal 624*8269e767SBrooks Davis.Dv SIGCHLD 625*8269e767SBrooks Davisor setting the flag 626*8269e767SBrooks Davis.Dv SA_NOCLDWAIT 627*8269e767SBrooks Davisfor that signal. 628*8269e767SBrooks Davis.It Bq Er EFAULT 629*8269e767SBrooks DavisThe 630*8269e767SBrooks Davis.Fa status 631*8269e767SBrooks Davisor 632*8269e767SBrooks Davis.Fa rusage 633*8269e767SBrooks Davisargument points to an illegal address. 634*8269e767SBrooks Davis(May not be detected before exit of a child process.) 635*8269e767SBrooks Davis.It Bq Er EINTR 636*8269e767SBrooks DavisThe call was interrupted by a caught signal, 637*8269e767SBrooks Davisor the signal did not have the 638*8269e767SBrooks Davis.Dv SA_RESTART 639*8269e767SBrooks Davisflag set. 640*8269e767SBrooks Davis.It Bq Er EINVAL 641*8269e767SBrooks DavisAn invalid value was specified for 642*8269e767SBrooks Davis.Fa options , 643*8269e767SBrooks Davisor 644*8269e767SBrooks Davis.Fa idtype 645*8269e767SBrooks Davisand 646*8269e767SBrooks Davis.Fa id 647*8269e767SBrooks Davisdo not specify a valid set of processes. 648*8269e767SBrooks Davis.El 649*8269e767SBrooks Davis.Sh SEE ALSO 650*8269e767SBrooks Davis.Xr _exit 2 , 651*8269e767SBrooks Davis.Xr procctl 2 , 652*8269e767SBrooks Davis.Xr ptrace 2 , 653*8269e767SBrooks Davis.Xr sigaction 2 , 654*8269e767SBrooks Davis.Xr exit 3 , 655*8269e767SBrooks Davis.Xr siginfo 3 656*8269e767SBrooks Davis.Sh STANDARDS 657*8269e767SBrooks DavisThe 658*8269e767SBrooks Davis.Fn wait , 659*8269e767SBrooks Davis.Fn waitpid , 660*8269e767SBrooks Davisand 661*8269e767SBrooks Davis.Fn waitid 662*8269e767SBrooks Davisfunctions are defined by POSIX; 663*8269e767SBrooks Davis.Fn wait6 , 664*8269e767SBrooks Davis.Fn wait4 , 665*8269e767SBrooks Davisand 666*8269e767SBrooks Davis.Fn wait3 667*8269e767SBrooks Davisare not specified by POSIX. 668*8269e767SBrooks DavisThe 669*8269e767SBrooks Davis.Fn WCOREDUMP 670*8269e767SBrooks Davismacro 671*8269e767SBrooks Davisis an extension to the POSIX interface. 672*8269e767SBrooks Davis.Pp 673*8269e767SBrooks DavisThe ability to use the 674*8269e767SBrooks Davis.Dv WNOWAIT 675*8269e767SBrooks Davisflag with 676*8269e767SBrooks Davis.Fn waitpid 677*8269e767SBrooks Davisis an extension; 678*8269e767SBrooks Davis.Tn POSIX 679*8269e767SBrooks Davisonly permits this flag with 680*8269e767SBrooks Davis.Fn waitid . 681*8269e767SBrooks Davis.Sh HISTORY 682*8269e767SBrooks DavisThe 683*8269e767SBrooks Davis.Fn wait 684*8269e767SBrooks Davisfunction appeared in 685*8269e767SBrooks Davis.At v1 . 686