xref: /freebsd/sys/sys/wait.h (revision d0b2dbfa)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1982, 1986, 1989, 1993, 1994
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  *	@(#)wait.h	8.2 (Berkeley) 7/10/94
32  */
33 
34 #ifndef _SYS_WAIT_H_
35 #define _SYS_WAIT_H_
36 
37 #include <sys/cdefs.h>
38 
39 /*
40  * This file holds definitions relevant to the wait4 system call and the
41  * alternate interfaces that use it (wait, wait3, waitpid).
42  */
43 
44 /*
45  * Macros to test the exit status returned by wait and extract the relevant
46  * values.
47  */
48 #if __BSD_VISIBLE
49 #define	WCOREFLAG	0200
50 #endif
51 #define	_W_INT(i)	(i)
52 
53 #define	_WSTATUS(x)	(_W_INT(x) & 0177)
54 #define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */
55 #define	WIFSTOPPED(x)	(_WSTATUS(x) == _WSTOPPED)
56 #define	WSTOPSIG(x)	(_W_INT(x) >> 8)
57 #define	WIFSIGNALED(x)	(_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0 && (x) != 0x13)
58 #define	WTERMSIG(x)	(_WSTATUS(x))
59 #define	WIFEXITED(x)	(_WSTATUS(x) == 0)
60 #define	WEXITSTATUS(x)	(_W_INT(x) >> 8)
61 #define	WIFCONTINUED(x)	(x == 0x13)	/* 0x13 == SIGCONT */
62 #if __BSD_VISIBLE
63 #define	WCOREDUMP(x)	(_W_INT(x) & WCOREFLAG)
64 
65 #define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig))
66 #define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED)
67 #endif
68 
69 /*
70  * Option bits for the third argument of wait4.  WNOHANG causes the
71  * wait to not hang if there are no stopped or terminated processes, rather
72  * returning an error indication in this case (pid==0).  WUNTRACED
73  * indicates that the caller should receive status about untraced children
74  * which stop due to signals.  If children are stopped and a wait without
75  * this option is done, it is as though they were still running... nothing
76  * about them is returned. WNOWAIT only request information about zombie,
77  * leaving the proc around, available for later waits.
78  */
79 #define	WNOHANG		1	/* Don't hang in wait. */
80 #define	WUNTRACED	2	/* Tell about stopped, untraced children. */
81 #define	WSTOPPED	WUNTRACED   /* SUS compatibility */
82 #define	WCONTINUED	4	/* Report a job control continued process. */
83 #define	WNOWAIT		8	/* Poll only. Don't delete the proc entry. */
84 #define	WEXITED		16	/* Wait for exited processes. */
85 #define	WTRAPPED	32	/* Wait for a process to hit a trap or
86 				   a breakpoint. */
87 
88 #if __BSD_VISIBLE
89 #define	WLINUXCLONE 0x80000000	/* Wait for kthread spawned from linux_clone. */
90 #endif
91 
92 #ifndef _IDTYPE_T_DECLARED
93 typedef enum
94 #if __BSD_VISIBLE
95 	idtype		/* pollutes XPG4.2 namespace */
96 #endif
97 		{
98 	/*
99 	 * These names were mostly lifted from Solaris source code and
100 	 * still use Solaris style naming to avoid breaking any
101 	 * OpenSolaris code which has been ported to FreeBSD.  There
102 	 * is no clear FreeBSD counterpart for all of the names, but
103 	 * some have a clear correspondence to FreeBSD entities.
104 	 *
105 	 * The numerical values are kept synchronized with the Solaris
106 	 * values.
107 	 */
108 	P_PID,			/* A process identifier. */
109 	P_PPID,			/* A parent process identifier.	*/
110 	P_PGID,			/* A process group identifier. */
111 	P_SID,			/* A session identifier. */
112 	P_CID,			/* A scheduling class identifier. */
113 	P_UID,			/* A user identifier. */
114 	P_GID,			/* A group identifier. */
115 	P_ALL,			/* All processes. */
116 	P_LWPID,		/* An LWP identifier. */
117 	P_TASKID,		/* A task identifier. */
118 	P_PROJID,		/* A project identifier. */
119 	P_POOLID,		/* A pool identifier. */
120 	P_JAILID,		/* A zone identifier. */
121 	P_CTID,			/* A (process) contract identifier. */
122 	P_CPUID,		/* CPU identifier. */
123 	P_PSETID		/* Processor set identifier. */
124 } idtype_t;			/* The type of id_t we are using. */
125 
126 #if __BSD_VISIBLE
127 #define	P_ZONEID	P_JAILID
128 #endif
129 #define	_IDTYPE_T_DECLARED
130 #endif
131 
132 /*
133  * Tokens for special values of the "pid" parameter to wait4.
134  * Extended struct __wrusage to collect rusage for both the target
135  * process and its children within one wait6() call.
136  */
137 #if __BSD_VISIBLE
138 #define	WAIT_ANY	(-1)	/* any process */
139 #define	WAIT_MYPGRP	0	/* any process in my process group */
140 #endif /* __BSD_VISIBLE */
141 
142 #if defined(_KERNEL) || defined(_WANT_KW_EXITCODE)
143 
144 /*
145  * Clamp the return code to the low 8 bits from full 32 bit value.
146  * Should be used in kernel to construct the wait(2)-compatible process
147  * status to usermode.
148  */
149 #define	KW_EXITCODE(ret, sig)	W_EXITCODE((ret) & 0xff, (sig))
150 
151 #endif	/* _KERNEL || _WANT_KW_EXITCODE */
152 
153 #ifndef _KERNEL
154 
155 #include <sys/types.h>
156 
157 __BEGIN_DECLS
158 struct __siginfo;
159 pid_t	wait(int *);
160 pid_t	waitpid(pid_t, int *, int);
161 #if __POSIX_VISIBLE >= 200112
162 int	waitid(idtype_t, id_t, struct __siginfo *, int);
163 #endif
164 #if __BSD_VISIBLE
165 struct rusage;
166 struct __wrusage;
167 pid_t	wait3(int *, int, struct rusage *);
168 pid_t	wait4(pid_t, int *, int, struct rusage *);
169 pid_t	wait6(idtype_t, id_t, int *, int, struct __wrusage *,
170 	    struct __siginfo *);
171 #endif
172 __END_DECLS
173 #endif /* !_KERNEL */
174 
175 #endif /* !_SYS_WAIT_H_ */
176