xref: /xnu-10002.81.5/bsd/sys/wait.h (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1*5e3eaea3SApple OSS Distributions /*
2*5e3eaea3SApple OSS Distributions  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3*5e3eaea3SApple OSS Distributions  *
4*5e3eaea3SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*5e3eaea3SApple OSS Distributions  *
6*5e3eaea3SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*5e3eaea3SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*5e3eaea3SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*5e3eaea3SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*5e3eaea3SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*5e3eaea3SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*5e3eaea3SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*5e3eaea3SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*5e3eaea3SApple OSS Distributions  *
15*5e3eaea3SApple OSS Distributions  * Please obtain a copy of the License at
16*5e3eaea3SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*5e3eaea3SApple OSS Distributions  *
18*5e3eaea3SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*5e3eaea3SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*5e3eaea3SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*5e3eaea3SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*5e3eaea3SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*5e3eaea3SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*5e3eaea3SApple OSS Distributions  * limitations under the License.
25*5e3eaea3SApple OSS Distributions  *
26*5e3eaea3SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*5e3eaea3SApple OSS Distributions  */
28*5e3eaea3SApple OSS Distributions /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
29*5e3eaea3SApple OSS Distributions /*
30*5e3eaea3SApple OSS Distributions  * Copyright (c) 1982, 1986, 1989, 1993, 1994
31*5e3eaea3SApple OSS Distributions  *	The Regents of the University of California.  All rights reserved.
32*5e3eaea3SApple OSS Distributions  *
33*5e3eaea3SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
34*5e3eaea3SApple OSS Distributions  * modification, are permitted provided that the following conditions
35*5e3eaea3SApple OSS Distributions  * are met:
36*5e3eaea3SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
37*5e3eaea3SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
38*5e3eaea3SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
39*5e3eaea3SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
40*5e3eaea3SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
41*5e3eaea3SApple OSS Distributions  * 3. All advertising materials mentioning features or use of this software
42*5e3eaea3SApple OSS Distributions  *    must display the following acknowledgement:
43*5e3eaea3SApple OSS Distributions  *	This product includes software developed by the University of
44*5e3eaea3SApple OSS Distributions  *	California, Berkeley and its contributors.
45*5e3eaea3SApple OSS Distributions  * 4. Neither the name of the University nor the names of its contributors
46*5e3eaea3SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
47*5e3eaea3SApple OSS Distributions  *    without specific prior written permission.
48*5e3eaea3SApple OSS Distributions  *
49*5e3eaea3SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50*5e3eaea3SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51*5e3eaea3SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52*5e3eaea3SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53*5e3eaea3SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54*5e3eaea3SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55*5e3eaea3SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56*5e3eaea3SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57*5e3eaea3SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58*5e3eaea3SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59*5e3eaea3SApple OSS Distributions  * SUCH DAMAGE.
60*5e3eaea3SApple OSS Distributions  *
61*5e3eaea3SApple OSS Distributions  *	@(#)wait.h	8.2 (Berkeley) 7/10/94
62*5e3eaea3SApple OSS Distributions  */
63*5e3eaea3SApple OSS Distributions 
64*5e3eaea3SApple OSS Distributions #ifndef _SYS_WAIT_H_
65*5e3eaea3SApple OSS Distributions #define _SYS_WAIT_H_
66*5e3eaea3SApple OSS Distributions 
67*5e3eaea3SApple OSS Distributions #include <sys/cdefs.h>
68*5e3eaea3SApple OSS Distributions #include <sys/_types.h>
69*5e3eaea3SApple OSS Distributions 
70*5e3eaea3SApple OSS Distributions /*
71*5e3eaea3SApple OSS Distributions  * This file holds definitions relevent to the wait4 system call
72*5e3eaea3SApple OSS Distributions  * and the alternate interfaces that use it (wait, wait3, waitpid).
73*5e3eaea3SApple OSS Distributions  */
74*5e3eaea3SApple OSS Distributions 
75*5e3eaea3SApple OSS Distributions /*
76*5e3eaea3SApple OSS Distributions  * [XSI] The type idtype_t shall be defined as an enumeration type whose
77*5e3eaea3SApple OSS Distributions  * possible values shall include at least P_ALL, P_PID, and P_PGID.
78*5e3eaea3SApple OSS Distributions  */
79*5e3eaea3SApple OSS Distributions typedef enum {
80*5e3eaea3SApple OSS Distributions 	P_ALL,
81*5e3eaea3SApple OSS Distributions 	P_PID,
82*5e3eaea3SApple OSS Distributions 	P_PGID
83*5e3eaea3SApple OSS Distributions } idtype_t;
84*5e3eaea3SApple OSS Distributions 
85*5e3eaea3SApple OSS Distributions /*
86*5e3eaea3SApple OSS Distributions  * [XSI] The id_t and pid_t types shall be defined as described
87*5e3eaea3SApple OSS Distributions  * in <sys/types.h>
88*5e3eaea3SApple OSS Distributions  */
89*5e3eaea3SApple OSS Distributions #include <sys/_types/_pid_t.h>
90*5e3eaea3SApple OSS Distributions #include <sys/_types/_id_t.h>
91*5e3eaea3SApple OSS Distributions 
92*5e3eaea3SApple OSS Distributions /*
93*5e3eaea3SApple OSS Distributions  * [XSI] The siginfo_t type shall be defined as described in <signal.h>
94*5e3eaea3SApple OSS Distributions  * [XSI] The rusage structure shall be defined as described in <sys/resource.h>
95*5e3eaea3SApple OSS Distributions  * [XSI] Inclusion of the <sys/wait.h> header may also make visible all
96*5e3eaea3SApple OSS Distributions  * symbols from <signal.h> and <sys/resource.h>
97*5e3eaea3SApple OSS Distributions  *
98*5e3eaea3SApple OSS Distributions  * NOTE:	This requirement is currently being satisfied by the direct
99*5e3eaea3SApple OSS Distributions  *		inclusion of <sys/signal.h> and <sys/resource.h>, below.
100*5e3eaea3SApple OSS Distributions  *
101*5e3eaea3SApple OSS Distributions  *		Software should not depend on the exposure of anything other
102*5e3eaea3SApple OSS Distributions  *		than the types siginfo_t and struct rusage as a result of
103*5e3eaea3SApple OSS Distributions  *		this inclusion.  If you depend on any types or manifest
104*5e3eaea3SApple OSS Distributions  *		values othe than siginfo_t and struct rusage from either of
105*5e3eaea3SApple OSS Distributions  *		those files, you should explicitly include them yourself, as
106*5e3eaea3SApple OSS Distributions  *		well, or in future releases your stware may not compile
107*5e3eaea3SApple OSS Distributions  *		without modification.
108*5e3eaea3SApple OSS Distributions  */
109*5e3eaea3SApple OSS Distributions #include <sys/signal.h>         /* [XSI] for siginfo_t */
110*5e3eaea3SApple OSS Distributions #include <sys/resource.h>       /* [XSI] for struct rusage */
111*5e3eaea3SApple OSS Distributions 
112*5e3eaea3SApple OSS Distributions /*
113*5e3eaea3SApple OSS Distributions  * Option bits for the third argument of wait4.  WNOHANG causes the
114*5e3eaea3SApple OSS Distributions  * wait to not hang if there are no stopped or terminated processes, rather
115*5e3eaea3SApple OSS Distributions  * returning an error indication in this case (pid==0).  WUNTRACED
116*5e3eaea3SApple OSS Distributions  * indicates that the caller should receive status about untraced children
117*5e3eaea3SApple OSS Distributions  * which stop due to signals.  If children are stopped and a wait without
118*5e3eaea3SApple OSS Distributions  * this option is done, it is as though they were still running... nothing
119*5e3eaea3SApple OSS Distributions  * about them is returned.
120*5e3eaea3SApple OSS Distributions  */
121*5e3eaea3SApple OSS Distributions #define WNOHANG         0x00000001  /* [XSI] no hang in wait/no child to reap */
122*5e3eaea3SApple OSS Distributions #define WUNTRACED       0x00000002  /* [XSI] notify on stop, untraced child */
123*5e3eaea3SApple OSS Distributions 
124*5e3eaea3SApple OSS Distributions /*
125*5e3eaea3SApple OSS Distributions  * Macros to test the exit status returned by wait
126*5e3eaea3SApple OSS Distributions  * and extract the relevant values.
127*5e3eaea3SApple OSS Distributions  */
128*5e3eaea3SApple OSS Distributions #if defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE)
129*5e3eaea3SApple OSS Distributions #define _W_INT(i)       (i)
130*5e3eaea3SApple OSS Distributions #else
131*5e3eaea3SApple OSS Distributions #define _W_INT(w)       (*(int *)&(w))  /* convert union wait to int */
132*5e3eaea3SApple OSS Distributions #define WCOREFLAG       0200
133*5e3eaea3SApple OSS Distributions #endif /* (_POSIX_C_SOURCE && !_DARWIN_C_SOURCE) */
134*5e3eaea3SApple OSS Distributions 
135*5e3eaea3SApple OSS Distributions /* These macros are permited, as they are in the implementation namespace */
136*5e3eaea3SApple OSS Distributions #define _WSTATUS(x)     (_W_INT(x) & 0177)
137*5e3eaea3SApple OSS Distributions #define _WSTOPPED       0177            /* _WSTATUS if process is stopped */
138*5e3eaea3SApple OSS Distributions 
139*5e3eaea3SApple OSS Distributions /*
140*5e3eaea3SApple OSS Distributions  * [XSI] The <sys/wait.h> header shall define the following macros for
141*5e3eaea3SApple OSS Distributions  * analysis of process status values
142*5e3eaea3SApple OSS Distributions  */
143*5e3eaea3SApple OSS Distributions #if __DARWIN_UNIX03
144*5e3eaea3SApple OSS Distributions #define WEXITSTATUS(x)  ((_W_INT(x) >> 8) & 0x000000ff)
145*5e3eaea3SApple OSS Distributions #else /* !__DARWIN_UNIX03 */
146*5e3eaea3SApple OSS Distributions #define WEXITSTATUS(x)  (_W_INT(x) >> 8)
147*5e3eaea3SApple OSS Distributions #endif /* !__DARWIN_UNIX03 */
148*5e3eaea3SApple OSS Distributions /* 0x13 == SIGCONT */
149*5e3eaea3SApple OSS Distributions #define WSTOPSIG(x)     (_W_INT(x) >> 8)
150*5e3eaea3SApple OSS Distributions #define WIFCONTINUED(x) (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) == 0x13)
151*5e3eaea3SApple OSS Distributions #define WIFSTOPPED(x)   (_WSTATUS(x) == _WSTOPPED && WSTOPSIG(x) != 0x13)
152*5e3eaea3SApple OSS Distributions #define WIFEXITED(x)    (_WSTATUS(x) == 0)
153*5e3eaea3SApple OSS Distributions #define WIFSIGNALED(x)  (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
154*5e3eaea3SApple OSS Distributions #define WTERMSIG(x)     (_WSTATUS(x))
155*5e3eaea3SApple OSS Distributions #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
156*5e3eaea3SApple OSS Distributions #define WCOREDUMP(x)    (_W_INT(x) & WCOREFLAG)
157*5e3eaea3SApple OSS Distributions 
158*5e3eaea3SApple OSS Distributions #define W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
159*5e3eaea3SApple OSS Distributions #define W_STOPCODE(sig)         ((sig) << 8 | _WSTOPPED)
160*5e3eaea3SApple OSS Distributions #endif /* (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
161*5e3eaea3SApple OSS Distributions 
162*5e3eaea3SApple OSS Distributions /*
163*5e3eaea3SApple OSS Distributions  * [XSI] The following symbolic constants shall be defined as possible
164*5e3eaea3SApple OSS Distributions  * values for the fourth argument to waitid().
165*5e3eaea3SApple OSS Distributions  */
166*5e3eaea3SApple OSS Distributions /* WNOHANG already defined for wait4() */
167*5e3eaea3SApple OSS Distributions /* WUNTRACED defined for wait4() but not for waitid() */
168*5e3eaea3SApple OSS Distributions #define WEXITED         0x00000004  /* [XSI] Processes which have exitted */
169*5e3eaea3SApple OSS Distributions #if __DARWIN_UNIX03
170*5e3eaea3SApple OSS Distributions /* waitid() parameter */
171*5e3eaea3SApple OSS Distributions #define WSTOPPED        0x00000008  /* [XSI] Any child stopped by signal */
172*5e3eaea3SApple OSS Distributions #endif
173*5e3eaea3SApple OSS Distributions #define WCONTINUED      0x00000010  /* [XSI] Any child stopped then continued */
174*5e3eaea3SApple OSS Distributions #define WNOWAIT         0x00000020  /* [XSI] Leave process returned waitable */
175*5e3eaea3SApple OSS Distributions 
176*5e3eaea3SApple OSS Distributions 
177*5e3eaea3SApple OSS Distributions #if (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
178*5e3eaea3SApple OSS Distributions /* POSIX extensions and 4.2/4.3 compatability: */
179*5e3eaea3SApple OSS Distributions 
180*5e3eaea3SApple OSS Distributions /*
181*5e3eaea3SApple OSS Distributions  * Tokens for special values of the "pid" parameter to wait4.
182*5e3eaea3SApple OSS Distributions  */
183*5e3eaea3SApple OSS Distributions #define WAIT_ANY        (-1)    /* any process */
184*5e3eaea3SApple OSS Distributions #define WAIT_MYPGRP     0       /* any process in my process group */
185*5e3eaea3SApple OSS Distributions 
186*5e3eaea3SApple OSS Distributions #include <machine/endian.h>
187*5e3eaea3SApple OSS Distributions 
188*5e3eaea3SApple OSS Distributions /*
189*5e3eaea3SApple OSS Distributions  * Deprecated:
190*5e3eaea3SApple OSS Distributions  * Structure of the information in the status word returned by wait4.
191*5e3eaea3SApple OSS Distributions  * If w_stopval==_WSTOPPED, then the second structure describes
192*5e3eaea3SApple OSS Distributions  * the information returned, else the first.
193*5e3eaea3SApple OSS Distributions  */
194*5e3eaea3SApple OSS Distributions union wait {
195*5e3eaea3SApple OSS Distributions 	int     w_status;               /* used in syscall */
196*5e3eaea3SApple OSS Distributions 	/*
197*5e3eaea3SApple OSS Distributions 	 * Terminated process status.
198*5e3eaea3SApple OSS Distributions 	 */
199*5e3eaea3SApple OSS Distributions 	struct {
200*5e3eaea3SApple OSS Distributions #if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
201*5e3eaea3SApple OSS Distributions 		unsigned int    w_Termsig:7,    /* termination signal */
202*5e3eaea3SApple OSS Distributions 		    w_Coredump:1,               /* core dump indicator */
203*5e3eaea3SApple OSS Distributions 		    w_Retcode:8,                /* exit code if w_termsig==0 */
204*5e3eaea3SApple OSS Distributions 		    w_Filler:16;                /* upper bits filler */
205*5e3eaea3SApple OSS Distributions #endif
206*5e3eaea3SApple OSS Distributions #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
207*5e3eaea3SApple OSS Distributions 		unsigned int    w_Filler:16,    /* upper bits filler */
208*5e3eaea3SApple OSS Distributions 		    w_Retcode:8,                /* exit code if w_termsig==0 */
209*5e3eaea3SApple OSS Distributions 		    w_Coredump:1,               /* core dump indicator */
210*5e3eaea3SApple OSS Distributions 		    w_Termsig:7;                /* termination signal */
211*5e3eaea3SApple OSS Distributions #endif
212*5e3eaea3SApple OSS Distributions 	} w_T;
213*5e3eaea3SApple OSS Distributions 	/*
214*5e3eaea3SApple OSS Distributions 	 * Stopped process status.  Returned
215*5e3eaea3SApple OSS Distributions 	 * only for traced children unless requested
216*5e3eaea3SApple OSS Distributions 	 * with the WUNTRACED option bit.
217*5e3eaea3SApple OSS Distributions 	 */
218*5e3eaea3SApple OSS Distributions 	struct {
219*5e3eaea3SApple OSS Distributions #if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
220*5e3eaea3SApple OSS Distributions 		unsigned int    w_Stopval:8,    /* == W_STOPPED if stopped */
221*5e3eaea3SApple OSS Distributions 		    w_Stopsig:8,                /* signal that stopped us */
222*5e3eaea3SApple OSS Distributions 		    w_Filler:16;                /* upper bits filler */
223*5e3eaea3SApple OSS Distributions #endif
224*5e3eaea3SApple OSS Distributions #if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
225*5e3eaea3SApple OSS Distributions 		unsigned int    w_Filler:16,    /* upper bits filler */
226*5e3eaea3SApple OSS Distributions 		    w_Stopsig:8,                /* signal that stopped us */
227*5e3eaea3SApple OSS Distributions 		    w_Stopval:8;                /* == W_STOPPED if stopped */
228*5e3eaea3SApple OSS Distributions #endif
229*5e3eaea3SApple OSS Distributions 	} w_S;
230*5e3eaea3SApple OSS Distributions };
231*5e3eaea3SApple OSS Distributions #define w_termsig       w_T.w_Termsig
232*5e3eaea3SApple OSS Distributions #define w_coredump      w_T.w_Coredump
233*5e3eaea3SApple OSS Distributions #define w_retcode       w_T.w_Retcode
234*5e3eaea3SApple OSS Distributions #define w_stopval       w_S.w_Stopval
235*5e3eaea3SApple OSS Distributions #define w_stopsig       w_S.w_Stopsig
236*5e3eaea3SApple OSS Distributions 
237*5e3eaea3SApple OSS Distributions #endif /* (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
238*5e3eaea3SApple OSS Distributions 
239*5e3eaea3SApple OSS Distributions #if !(__DARWIN_UNIX03 - 0)
240*5e3eaea3SApple OSS Distributions /*
241*5e3eaea3SApple OSS Distributions  * Stopped state value; cannot use waitid() parameter of the same name
242*5e3eaea3SApple OSS Distributions  * in the same scope
243*5e3eaea3SApple OSS Distributions  */
244*5e3eaea3SApple OSS Distributions #define WSTOPPED        _WSTOPPED
245*5e3eaea3SApple OSS Distributions #endif /* !__DARWIN_UNIX03 */
246*5e3eaea3SApple OSS Distributions 
247*5e3eaea3SApple OSS Distributions #ifndef KERNEL
248*5e3eaea3SApple OSS Distributions __BEGIN_DECLS
249*5e3eaea3SApple OSS Distributions pid_t   wait(int *) __DARWIN_ALIAS_C(wait);
250*5e3eaea3SApple OSS Distributions pid_t   waitpid(pid_t, int *, int) __DARWIN_ALIAS_C(waitpid);
251*5e3eaea3SApple OSS Distributions #ifndef _ANSI_SOURCE
252*5e3eaea3SApple OSS Distributions int     waitid(idtype_t, id_t, siginfo_t *, int) __DARWIN_ALIAS_C(waitid);
253*5e3eaea3SApple OSS Distributions #endif /* !_ANSI_SOURCE */
254*5e3eaea3SApple OSS Distributions #if  (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
255*5e3eaea3SApple OSS Distributions pid_t   wait3(int *, int, struct rusage *);
256*5e3eaea3SApple OSS Distributions pid_t   wait4(pid_t, int *, int, struct rusage *);
257*5e3eaea3SApple OSS Distributions #endif /* (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) */
258*5e3eaea3SApple OSS Distributions __END_DECLS
259*5e3eaea3SApple OSS Distributions #endif
260*5e3eaea3SApple OSS Distributions #endif /* !_SYS_WAIT_H_ */
261