1 /* 2 * Copyright (c) 1982, 1986, 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)wait.h 8.2 (Berkeley) 7/10/94 34 * $FreeBSD: src/sys/sys/wait.h,v 1.11 1999/12/29 04:24:50 peter Exp $ 35 * $DragonFly: src/sys/sys/wait.h,v 1.6 2007/08/30 20:41:00 pavalos Exp $ 36 */ 37 38 #ifndef _SYS_WAIT_H_ 39 #define _SYS_WAIT_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 #ifdef _POSIX_SOURCE 51 #define _W_INT(i) (i) 52 #else 53 #define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */ 54 #define WCOREFLAG 0200 55 #endif 56 57 #define _WSTATUS(x) (_W_INT(x) & 0177) 58 #define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 59 #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 60 #define WSTOPSIG(x) (_W_INT(x) >> 8) 61 #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) 62 #define WTERMSIG(x) (_WSTATUS(x)) 63 #define WIFEXITED(x) (_WSTATUS(x) == 0) 64 #define WEXITSTATUS(x) (_W_INT(x) >> 8) 65 #define WIFCONTINUED(x) (x == 19) /* 19 == SIGCONT */ 66 #ifndef _POSIX_SOURCE 67 #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 68 69 #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 70 #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 71 #endif 72 73 /* 74 * Option bits for the third argument of wait4. WNOHANG causes the 75 * wait to not hang if there are no stopped or terminated processes, rather 76 * returning an error indication in this case (pid==0). WUNTRACED 77 * indicates that the caller should receive status about untraced children 78 * which stop due to signals. If children are stopped and a wait without 79 * this option is done, it is as though they were still running... nothing 80 * about them is returned. 81 */ 82 #define WNOHANG 1 /* don't hang in wait */ 83 #define WUNTRACED 2 /* tell about stopped, untraced children */ 84 #define WCONTINUED 4 /* Report a job control continued process. */ 85 #define WLINUXCLONE 0x80000000 /* wait for kthread spawned from linux_clone */ 86 87 #ifndef _POSIX_SOURCE 88 /* POSIX extensions and 4.2/4.3 compatibility: */ 89 90 /* 91 * Tokens for special values of the "pid" parameter to wait4. 92 */ 93 #define WAIT_ANY (-1) /* any process */ 94 #define WAIT_MYPGRP 0 /* any process in my process group */ 95 96 #ifndef _MACHINE_ENDIAN_H_ 97 #include <machine/endian.h> 98 #endif 99 100 /* 101 * Deprecated: 102 * Structure of the information in the status word returned by wait4. 103 * If w_stopval==WSTOPPED, then the second structure describes 104 * the information returned, else the first. 105 */ 106 union wait { 107 int w_status; /* used in syscall */ 108 /* 109 * Terminated process status. 110 */ 111 struct { 112 #if _BYTE_ORDER == _LITTLE_ENDIAN 113 unsigned int w_Termsig:7, /* termination signal */ 114 w_Coredump:1, /* core dump indicator */ 115 w_Retcode:8, /* exit code if w_termsig==0 */ 116 w_Filler:16; /* upper bits filler */ 117 #elif _BYTE_ORDER == _BIG_ENDIAN 118 unsigned int w_Filler:16, /* upper bits filler */ 119 w_Retcode:8, /* exit code if w_termsig==0 */ 120 w_Coredump:1, /* core dump indicator */ 121 w_Termsig:7; /* termination signal */ 122 #else 123 #error "Byte order not implemented" 124 #endif 125 } w_T; 126 /* 127 * Stopped process status. Returned 128 * only for traced children unless requested 129 * with the WUNTRACED option bit. 130 */ 131 struct { 132 #if _BYTE_ORDER == _LITTLE_ENDIAN 133 unsigned int w_Stopval:8, /* == W_STOPPED if stopped */ 134 w_Stopsig:8, /* signal that stopped us */ 135 w_Filler:16; /* upper bits filler */ 136 #elif _BYTE_ORDER == _BIG_ENDIAN 137 unsigned int w_Filler:16, /* upper bits filler */ 138 w_Stopsig:8, /* signal that stopped us */ 139 w_Stopval:8; /* == W_STOPPED if stopped */ 140 #else 141 #error "Byte order not implemented" 142 #endif 143 } w_S; 144 }; 145 #define w_termsig w_T.w_Termsig 146 #define w_coredump w_T.w_Coredump 147 #define w_retcode w_T.w_Retcode 148 #define w_stopval w_S.w_Stopval 149 #define w_stopsig w_S.w_Stopsig 150 151 #define WSTOPPED _WSTOPPED 152 #endif /* _POSIX_SOURCE */ 153 154 #ifndef _KERNEL 155 #ifndef _SYS_TYPES_H_ 156 #include <sys/types.h> 157 #endif 158 #ifndef _SYS_CDEFS_H_ 159 #include <sys/cdefs.h> 160 #endif 161 162 __BEGIN_DECLS 163 struct rusage; /* forward declaration */ 164 165 pid_t wait (int *); 166 pid_t waitpid (pid_t, int *, int); 167 #ifndef _POSIX_SOURCE 168 pid_t wait3 (int *, int, struct rusage *); 169 pid_t wait4 (pid_t, int *, int, struct rusage *); 170 #endif 171 __END_DECLS 172 #endif 173 174 #endif 175