| 1 | /*	$OpenBSD: wait.h,v 1.20 2022/12/19 00:22:11 guenther Exp $	*/ |
| 2 | /*	$NetBSD: wait.h,v 1.11 1996/04/09 20:55:51 cgd Exp $	*/ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (c) 1982, 1986, 1989, 1993, 1994 |
| 6 | *	The Regents of the University of California. All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the name of the University nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this software |
| 18 | * without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | * |
| 32 | *	@(#)wait.h	8.2 (Berkeley) 7/10/94 |
| 33 | */ |
| 34 | |
| 35 | #ifndef _SYS_WAIT_H_ |
| 36 | #define _SYS_WAIT_H_ |
| 37 | |
| 38 | #include <sys/cdefs.h> |
| 39 | #include <sys/siginfo.h> |
| 40 | |
| 41 | /* |
| 42 | * This file holds definitions relevant to the wait4 system call |
| 43 | * and the alternate interfaces that use it (wait, wait3, waitpid). |
| 44 | */ |
| 45 | |
| 46 | /* |
| 47 | * Macros to test the exit status returned by wait |
| 48 | * and extract the relevant values. |
| 49 | */ |
| 50 | #define	_WSTATUS(x)	((x) & 0177) |
| 51 | #define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */ |
| 52 | #define	_WCONTINUED	0177777		/* process has continued */ |
| 53 | #define WIFSTOPPED(x)	(((x) & 0xff) == _WSTOPPED) |
| 54 | #define WSTOPSIG(x)	(int)(((unsigned)(x) >> 8) & 0xff) |
| 55 | #define WIFSIGNALED(x)	(_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) |
| 56 | #define WTERMSIG(x)	(_WSTATUS(x)) |
| 57 | #define WIFEXITED(x)	(_WSTATUS(x) == 0) |
| 58 | #define WEXITSTATUS(x)	(int)(((unsigned)(x) >> 8) & 0xff) |
| 59 | #define WIFCONTINUED(x)	(((x) & _WCONTINUED) == _WCONTINUED) |
| 60 | #if __XPG_VISIBLE |
| 61 | #define	WCOREFLAG	0200 |
| 62 | #define WCOREDUMP(x)	((x) & WCOREFLAG) |
| 63 | |
| 64 | #define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig)) |
| 65 | #define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED) |
| 66 | #endif |
| 67 | |
| 68 | /* |
| 69 | * Option bits for the third argument of wait4. WNOHANG causes the |
| 70 | * wait to not hang if there are no stopped or terminated processes, rather |
| 71 | * returning an error indication in this case (pid==0). WUNTRACED |
| 72 | * indicates that the caller should receive status about untraced children |
| 73 | * which stop due to signals. If children are stopped and a wait without |
| 74 | * this option is done, it is as though they were still running... nothing |
| 75 | * about them is returned. WNOWAIT only requests information about zombie, |
| 76 | * leaving the proc around, available for later waits. |
| 77 | */ |
| 78 | #define WNOHANG		0x01	/* don't hang in wait */ |
| 79 | #define WUNTRACED	0x02	/* report stopped-by-signal processes */ |
| 80 | #define WCONTINUED	0x08	/* report job control continued processes */ |
| 81 | #if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE >= 420 |
| 82 | #define WEXITED		0x04	/* report exited processes */ |
| 83 | #define WSTOPPED	WUNTRACED |
| 84 | #define WNOWAIT		0x10	/* poll only */ |
| 85 | #define WTRAPPED	0x20	/* report stopped-by-tracing processes */ |
| 86 | |
| 87 | typedef enum { |
| 88 | 	P_ALL, |
| 89 | 	P_PGID, |
| 90 | 	P_PID |
| 91 | } idtype_t; |
| 92 | #endif |
| 93 | |
| 94 | #if __BSD_VISIBLE |
| 95 | /* |
| 96 | * Tokens for special values of the "pid" parameter to wait4. |
| 97 | */ |
| 98 | #define	WAIT_ANY	(-1)	/* any process */ |
| 99 | #define	WAIT_MYPGRP	0	/* any process in my process group */ |
| 100 | #endif /* __BSD_VISIBLE */ |
| 101 | |
| 102 | #ifndef _KERNEL |
| 103 | #include <sys/types.h> |
| 104 | |
| 105 | __BEGIN_DECLS |
| 106 | struct rusage;	/* forward declaration */ |
| 107 | |
| 108 | pid_t	wait(int *); |
| 109 | pid_t	waitpid(pid_t, int *, int); |
| 110 | #if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE >= 420 |
| 111 | int	waitid(idtype_t, id_t, siginfo_t *, int); |
| 112 | #endif |
| 113 | #if __BSD_VISIBLE |
| 114 | pid_t	wait3(int *, int, struct rusage *); |
| 115 | pid_t	wait4(pid_t, int *, int, struct rusage *); |
| 116 | #endif /* __BSD_VISIBLE */ |
| 117 | __END_DECLS |
| 118 | #endif /* !_KERNEL */ |
| 119 | |
| 120 | #endif /* !_SYS_WAIT_H_ */ |