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