xref: /minix3/sys/sys/wait.h (revision 256829c7e8cd5df7936bd6ced00a32e3b1b045a3)
1f6aac1c3SLionel Sambuc /*	$NetBSD: wait.h,v 1.26 2009/01/11 02:45:56 christos Exp $	*/
2f6aac1c3SLionel Sambuc 
3f6aac1c3SLionel Sambuc /*
4f6aac1c3SLionel Sambuc  * Copyright (c) 1982, 1986, 1989, 1993, 1994
5f6aac1c3SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
6f6aac1c3SLionel Sambuc  *
7f6aac1c3SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8f6aac1c3SLionel Sambuc  * modification, are permitted provided that the following conditions
9f6aac1c3SLionel Sambuc  * are met:
10f6aac1c3SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12f6aac1c3SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14f6aac1c3SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15f6aac1c3SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
16f6aac1c3SLionel Sambuc  *    may be used to endorse or promote products derived from this software
17f6aac1c3SLionel Sambuc  *    without specific prior written permission.
18f6aac1c3SLionel Sambuc  *
19f6aac1c3SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20f6aac1c3SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21f6aac1c3SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22f6aac1c3SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23f6aac1c3SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24f6aac1c3SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25f6aac1c3SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26f6aac1c3SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27f6aac1c3SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28f6aac1c3SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29f6aac1c3SLionel Sambuc  * SUCH DAMAGE.
30f6aac1c3SLionel Sambuc  *
31f6aac1c3SLionel Sambuc  *	@(#)wait.h	8.2 (Berkeley) 7/10/94
32f6aac1c3SLionel Sambuc  */
33f6aac1c3SLionel Sambuc 
34f6aac1c3SLionel Sambuc #ifndef _SYS_WAIT_H_
35f6aac1c3SLionel Sambuc #define _SYS_WAIT_H_
36f6aac1c3SLionel Sambuc 
37f6aac1c3SLionel Sambuc #include <sys/featuretest.h>
38f6aac1c3SLionel Sambuc 
39*256829c7SBen Gras /*
40*256829c7SBen Gras  * This file holds definitions relevent to the wait4 system call
41*256829c7SBen Gras  * and the alternate interfaces that use it (wait, wait3, waitpid).
42f6aac1c3SLionel Sambuc  */
43f6aac1c3SLionel Sambuc 
44f6aac1c3SLionel Sambuc /*
45f6aac1c3SLionel Sambuc  * Macros to test the exit status returned by wait
46f6aac1c3SLionel Sambuc  * and extract the relevant values.
47f6aac1c3SLionel Sambuc  */
48*256829c7SBen Gras #if !( defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) ) || defined(_KERNEL)
49*256829c7SBen Gras #define	_W_INT(i)	(i)
50*256829c7SBen Gras #else
51*256829c7SBen Gras #define	_W_INT(w)	(*(int *)(void *)&(w))	/* convert union wait to int */
52*256829c7SBen Gras #endif
53f6aac1c3SLionel Sambuc 
54*256829c7SBen Gras #define	_WSTATUS(x)	(_W_INT(x) & 0177)
55*256829c7SBen Gras #define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */
56*256829c7SBen Gras #define WIFSTOPPED(x)	(_WSTATUS(x) == _WSTOPPED)
57*256829c7SBen Gras #define WSTOPSIG(x)	((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
58*256829c7SBen Gras #define WIFSIGNALED(x)	(_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
59*256829c7SBen Gras #define WTERMSIG(x)	(_WSTATUS(x))
60*256829c7SBen Gras #define WIFEXITED(x)	(_WSTATUS(x) == 0)
61*256829c7SBen Gras #define WEXITSTATUS(x)	((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff)
62*256829c7SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE) || defined(_KERNEL)
63*256829c7SBen Gras #define	WCOREFLAG	0200
64*256829c7SBen Gras #define WCOREDUMP(x)	(_W_INT(x) & WCOREFLAG)
65f6aac1c3SLionel Sambuc 
66*256829c7SBen Gras #define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig))
67*256829c7SBen Gras #define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED)
68*256829c7SBen Gras #endif
69f6aac1c3SLionel Sambuc 
70f6aac1c3SLionel Sambuc /*
71*256829c7SBen Gras  * Option bits for the third argument of wait4.  WNOHANG causes the
72f6aac1c3SLionel Sambuc  * wait to not hang if there are no stopped or terminated processes, rather
73f6aac1c3SLionel Sambuc  * returning an error indication in this case (pid==0).  WUNTRACED
74f6aac1c3SLionel Sambuc  * indicates that the caller should receive status about untraced children
75f6aac1c3SLionel Sambuc  * which stop due to signals.  If children are stopped and a wait without
76f6aac1c3SLionel Sambuc  * this option is done, it is as though they were still running... nothing
77f6aac1c3SLionel Sambuc  * about them is returned.
78f6aac1c3SLionel Sambuc  */
79f6aac1c3SLionel Sambuc #define WNOHANG		0x00000001	/* don't hang in wait */
80f6aac1c3SLionel Sambuc #define WUNTRACED	0x00000002	/* tell about stopped,
81f6aac1c3SLionel Sambuc 					   untraced children */
82*256829c7SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
83*256829c7SBen Gras #define	WALTSIG		0x00000004	/* wait for processes that exit
84*256829c7SBen Gras 					   with an alternate signal (i.e.
85*256829c7SBen Gras 					   not SIGCHLD) */
86*256829c7SBen Gras #define	WALLSIG		0x00000008	/* wait for processes that exit
87*256829c7SBen Gras 					   with any signal, i.e. SIGCHLD
88*256829c7SBen Gras 					   and alternates */
89f6aac1c3SLionel Sambuc 
90*256829c7SBen Gras /*
91*256829c7SBen Gras  * These are the Linux names of some of the above flags, for compatibility
92*256829c7SBen Gras  * with Linux's clone(2) API.
93*256829c7SBen Gras  */
94*256829c7SBen Gras #define	__WCLONE	WALTSIG
95*256829c7SBen Gras #define	__WALL		WALLSIG
96*256829c7SBen Gras 
97*256829c7SBen Gras /*
98*256829c7SBen Gras  * These bits are used in order to support SVR4 (etc) functionality
99*256829c7SBen Gras  * without replicating sys_wait4 5 times.
100*256829c7SBen Gras  */
101*256829c7SBen Gras #define	WNOWAIT		0x00010000	/* Don't mark child 'P_WAITED' */
102*256829c7SBen Gras #define	WNOZOMBIE	0x00020000	/* Ignore zombies */
103*256829c7SBen Gras #define	WOPTSCHECKED	0x00040000	/* Compat call, options verified */
104*256829c7SBen Gras #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
105*256829c7SBen Gras 
106*256829c7SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
107f6aac1c3SLionel Sambuc /* POSIX extensions and 4.2/4.3 compatibility: */
108f6aac1c3SLionel Sambuc 
109f6aac1c3SLionel Sambuc /*
110*256829c7SBen Gras  * Tokens for special values of the "pid" parameter to wait4.
111f6aac1c3SLionel Sambuc  */
112f6aac1c3SLionel Sambuc #define	WAIT_ANY	(-1)	/* any process */
113f6aac1c3SLionel Sambuc #define	WAIT_MYPGRP	0	/* any process in my process group */
114f6aac1c3SLionel Sambuc 
115*256829c7SBen Gras #include <sys/types.h>
116*256829c7SBen Gras 
117*256829c7SBen Gras /*
118*256829c7SBen Gras  * Deprecated:
119*256829c7SBen Gras  * Structure of the information in the status word returned by wait4.
120*256829c7SBen Gras  * If w_stopval==WSTOPPED, then the second structure describes
121*256829c7SBen Gras  * the information returned, else the first.
122*256829c7SBen Gras  */
123*256829c7SBen Gras union wait {
124*256829c7SBen Gras 	int	w_status;		/* used in syscall */
125*256829c7SBen Gras 	/*
126*256829c7SBen Gras 	 * Terminated process status.
127*256829c7SBen Gras 	 */
128*256829c7SBen Gras 	struct {
129*256829c7SBen Gras #if BYTE_ORDER == LITTLE_ENDIAN
130*256829c7SBen Gras 		unsigned int	w_Termsig:7,	/* termination signal */
131*256829c7SBen Gras 				w_Coredump:1,	/* core dump indicator */
132*256829c7SBen Gras 				w_Retcode:8,	/* exit code if w_termsig==0 */
133*256829c7SBen Gras 				w_Filler:16;	/* upper bits filler */
134*256829c7SBen Gras #endif
135*256829c7SBen Gras #if BYTE_ORDER == BIG_ENDIAN
136*256829c7SBen Gras 		unsigned int	w_Filler:16,	/* upper bits filler */
137*256829c7SBen Gras 				w_Retcode:8,	/* exit code if w_termsig==0 */
138*256829c7SBen Gras 				w_Coredump:1,	/* core dump indicator */
139*256829c7SBen Gras 				w_Termsig:7;	/* termination signal */
140*256829c7SBen Gras #endif
141*256829c7SBen Gras 	} w_T;
142*256829c7SBen Gras 	/*
143*256829c7SBen Gras 	 * Stopped process status.  Returned
144*256829c7SBen Gras 	 * only for traced children unless requested
145*256829c7SBen Gras 	 * with the WUNTRACED option bit.
146*256829c7SBen Gras 	 */
147*256829c7SBen Gras 	struct {
148*256829c7SBen Gras #if BYTE_ORDER == LITTLE_ENDIAN
149*256829c7SBen Gras 		unsigned int	w_Stopval:8,	/* == W_STOPPED if stopped */
150*256829c7SBen Gras 				w_Stopsig:8,	/* signal that stopped us */
151*256829c7SBen Gras 				w_Filler:16;	/* upper bits filler */
152*256829c7SBen Gras #endif
153*256829c7SBen Gras #if BYTE_ORDER == BIG_ENDIAN
154*256829c7SBen Gras 		unsigned int	w_Filler:16,	/* upper bits filler */
155*256829c7SBen Gras 				w_Stopsig:8,	/* signal that stopped us */
156*256829c7SBen Gras 				w_Stopval:8;	/* == W_STOPPED if stopped */
157*256829c7SBen Gras #endif
158*256829c7SBen Gras 	} w_S;
159*256829c7SBen Gras };
160*256829c7SBen Gras #define	w_termsig	w_T.w_Termsig
161*256829c7SBen Gras #define w_coredump	w_T.w_Coredump
162*256829c7SBen Gras #define w_retcode	w_T.w_Retcode
163*256829c7SBen Gras #define w_stopval	w_S.w_Stopval
164*256829c7SBen Gras #define w_stopsig	w_S.w_Stopsig
165*256829c7SBen Gras 
166*256829c7SBen Gras #define	WSTOPPED	_WSTOPPED
167*256829c7SBen Gras #endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
168*256829c7SBen Gras 
169*256829c7SBen Gras #ifndef _KERNEL
170*256829c7SBen Gras #include <sys/cdefs.h>
171*256829c7SBen Gras 
172f6aac1c3SLionel Sambuc __BEGIN_DECLS
173*256829c7SBen Gras struct rusage;	/* forward declaration */
174*256829c7SBen Gras 
175f6aac1c3SLionel Sambuc pid_t	wait(int *);
176f6aac1c3SLionel Sambuc pid_t	waitpid(pid_t, int *, int);
177*256829c7SBen Gras #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
178*256829c7SBen Gras #ifndef __LIBC12_SOURCE__
179*256829c7SBen Gras pid_t	wait3(int *, int, struct rusage *) __RENAME(__wait350);
180*256829c7SBen Gras pid_t	wait4(pid_t, int *, int, struct rusage *) __RENAME(__wait450);
181*256829c7SBen Gras #endif
182*256829c7SBen Gras #endif
183f6aac1c3SLionel Sambuc __END_DECLS
184*256829c7SBen Gras #endif
185f6aac1c3SLionel Sambuc 
186f6aac1c3SLionel Sambuc #endif /* !_SYS_WAIT_H_ */
187