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