xref: /illumos-gate/usr/src/ucbhead/sys/wait.h (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
32*7c478bd9Sstevel@tonic-gate  * under license from the Regents of the University of California.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate #ifndef _SYS_WAIT_H
36*7c478bd9Sstevel@tonic-gate #define	_SYS_WAIT_H
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/resource.h>
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
44*7c478bd9Sstevel@tonic-gate extern "C" {
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  * This wait.h is a combination of SunOS's wait.h and SysV wait.h
49*7c478bd9Sstevel@tonic-gate  * The structure 'union wait' is taken from SunOS, while the
50*7c478bd9Sstevel@tonic-gate  * rest of the #define's are from SysV.
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /*
54*7c478bd9Sstevel@tonic-gate  * Structure of the information in the first word returned by both
55*7c478bd9Sstevel@tonic-gate  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
56*7c478bd9Sstevel@tonic-gate  * describes the information returned, else the first.  See WUNTRACED below.
57*7c478bd9Sstevel@tonic-gate  */
58*7c478bd9Sstevel@tonic-gate union wait	{
59*7c478bd9Sstevel@tonic-gate 	int	w_status;		/* used in syscall */
60*7c478bd9Sstevel@tonic-gate 	/*
61*7c478bd9Sstevel@tonic-gate 	 * Terminated process status.
62*7c478bd9Sstevel@tonic-gate 	 */
63*7c478bd9Sstevel@tonic-gate 	struct {
64*7c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
65*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Termsig:7;	/* termination signal */
66*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Coredump:1;	/* core dump indicator */
67*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
68*7c478bd9Sstevel@tonic-gate #else
69*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Fill1:16;	/* high 16 bits unused */
70*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
71*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Coredump:1;	/* core dump indicator */
72*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Termsig:7;	/* termination signal */
73*7c478bd9Sstevel@tonic-gate #endif
74*7c478bd9Sstevel@tonic-gate 	} w_T;
75*7c478bd9Sstevel@tonic-gate 	/*
76*7c478bd9Sstevel@tonic-gate 	 * Stopped process status.  Returned
77*7c478bd9Sstevel@tonic-gate 	 * only for traced children unless requested
78*7c478bd9Sstevel@tonic-gate 	 * with the WUNTRACED option bit.
79*7c478bd9Sstevel@tonic-gate 	 */
80*7c478bd9Sstevel@tonic-gate 	struct {
81*7c478bd9Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
82*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
83*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
84*7c478bd9Sstevel@tonic-gate #else
85*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Fill2:16;	/* high 16 bits unused */
86*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
87*7c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
88*7c478bd9Sstevel@tonic-gate #endif
89*7c478bd9Sstevel@tonic-gate 	} w_S;
90*7c478bd9Sstevel@tonic-gate };
91*7c478bd9Sstevel@tonic-gate #define	w_termsig	w_T.w_Termsig
92*7c478bd9Sstevel@tonic-gate #define	w_coredump	w_T.w_Coredump
93*7c478bd9Sstevel@tonic-gate #define	w_retcode	w_T.w_Retcode
94*7c478bd9Sstevel@tonic-gate #define	w_stopval	w_S.w_Stopval
95*7c478bd9Sstevel@tonic-gate #define	w_stopsig	w_S.w_Stopsig
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate /* ----- begin SysV wait.h ----- */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
100*7c478bd9Sstevel@tonic-gate #ifdef	BUS_OBJERR	/* Namespace conflict */
101*7c478bd9Sstevel@tonic-gate #undef	BUS_OBJERR
102*7c478bd9Sstevel@tonic-gate #endif
103*7c478bd9Sstevel@tonic-gate #include <sys/siginfo.h>
104*7c478bd9Sstevel@tonic-gate #include <sys/procset.h>
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate  * arguments to wait functions
108*7c478bd9Sstevel@tonic-gate  */
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate #define	WEXITED		0001	/* wait for processes that have exite	*/
111*7c478bd9Sstevel@tonic-gate #define	WTRAPPED	0002	/* wait for processes stopped while tracing */
112*7c478bd9Sstevel@tonic-gate #define	N_WSTOPPED	0004	/* wait for processes stopped by signals */
113*7c478bd9Sstevel@tonic-gate #define	WCONTINUED	0010	/* wait for processes continued */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate #define	WUNTRACED	N_WSTOPPED /* for POSIX */
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate #define	WNOHANG		0100	/* non blocking form of wait	*/
118*7c478bd9Sstevel@tonic-gate #define	WNOWAIT		0200	/* non destructive form of wait */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate #define	WOPTMASK	(WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG|WNOWAIT)
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /*
123*7c478bd9Sstevel@tonic-gate  * macros for stat return from wait functions
124*7c478bd9Sstevel@tonic-gate  */
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate #define	WSTOPFLG		0177
127*7c478bd9Sstevel@tonic-gate #define	WSTOPPED		WSTOPFLG
128*7c478bd9Sstevel@tonic-gate 				/* This is for source compatibility w/ SunOS */
129*7c478bd9Sstevel@tonic-gate #define	WCONTFLG		0177777
130*7c478bd9Sstevel@tonic-gate #define	WCOREFLG		0200
131*7c478bd9Sstevel@tonic-gate #define	WSIGMASK		0177
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate #define	WLOBYTE(stat)		((int)((stat)&0377))
134*7c478bd9Sstevel@tonic-gate #define	WHIBYTE(stat)		((int)(((stat)>>8)&0377))
135*7c478bd9Sstevel@tonic-gate #define	WWORD(stat)		((int)((stat))&0177777)
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate #define	WIFEXITED(stat)		(WLOBYTE(stat) == 0)
138*7c478bd9Sstevel@tonic-gate #define	WIFSIGNALED(stat)	(WLOBYTE(stat) > 0 && WHIBYTE(stat) == 0)
139*7c478bd9Sstevel@tonic-gate #define	WIFSTOPPED(stat)	(WLOBYTE(stat) == WSTOPFLG&&WHIBYTE(stat) != 0)
140*7c478bd9Sstevel@tonic-gate #define	WIFCONTINUED(stat)	(WWORD(stat) == WCONTFLG)
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate #define	WEXITSTATUS(stat)	WHIBYTE(stat)
143*7c478bd9Sstevel@tonic-gate #define	WTERMSIG(stat)		(WLOBYTE(stat)&WSIGMASK)
144*7c478bd9Sstevel@tonic-gate #define	WSTOPSIG(stat)		WHIBYTE(stat)
145*7c478bd9Sstevel@tonic-gate #define	WCOREDUMP(stat)		((stat)&WCOREFLG)
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #if !defined(_KERNEL)
150*7c478bd9Sstevel@tonic-gate #if defined(__STDC__)
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate extern pid_t wait(int *);
153*7c478bd9Sstevel@tonic-gate extern pid_t waitpid(pid_t, int *, int);
154*7c478bd9Sstevel@tonic-gate extern int waitid(idtype_t, id_t, siginfo_t *, int);
155*7c478bd9Sstevel@tonic-gate extern pid_t wait4(pid_t, int *, int, struct rusage *);
156*7c478bd9Sstevel@tonic-gate extern pid_t wait3(int *, int, struct rusage *);
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate #else
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate extern pid_t wait();
161*7c478bd9Sstevel@tonic-gate extern pid_t waitpid();
162*7c478bd9Sstevel@tonic-gate extern int waitid();
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
165*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
166*7c478bd9Sstevel@tonic-gate 
167*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
168*7c478bd9Sstevel@tonic-gate }
169*7c478bd9Sstevel@tonic-gate #endif
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_WAIT_H */
172