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