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