1 /* $NetBSD: wait.h,v 1.17 2001/07/18 19:10:26 thorpej Exp $ */ 2 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. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by the University of 18 * California, Berkeley and its contributors. 19 * 4. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)wait.h 8.2 (Berkeley) 7/10/94 36 */ 37 38 #ifndef _SYS_WAIT_H_ 39 #define _SYS_WAIT_H_ 40 41 /* 42 * This file holds definitions relevent 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 *)(void *)&(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) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff) 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) ((int)(((unsigned int)_W_INT(x)) >> 8) & 0xff) 65 #ifndef _POSIX_SOURCE 66 #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 67 68 #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 69 #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 70 #endif 71 72 /* 73 * Option bits for the third argument of wait4. WNOHANG causes the 74 * wait to not hang if there are no stopped or terminated processes, rather 75 * returning an error indication in this case (pid==0). WUNTRACED 76 * indicates that the caller should receive status about untraced children 77 * which stop due to signals. If children are stopped and a wait without 78 * this option is done, it is as though they were still running... nothing 79 * about them is returned. 80 */ 81 #define WNOHANG 0x00000001 /* don't hang in wait */ 82 #define WUNTRACED 0x00000002 /* tell about stopped, 83 untraced children */ 84 #ifndef _POSIX_SOURCE 85 #define WALTSIG 0x00000004 /* wait for processes that exit 86 with an alternate signal (i.e. 87 not SIGCHLD) */ 88 #define WALLSIG 0x00000008 /* wait for processes that exit 89 with any signal, i.e. SIGCHLD 90 and alternates */ 91 92 /* 93 * These are the Linux names of some of the above flags, for compatibility 94 * with Linux's clone(2) API. 95 */ 96 #define __WCLONE WALTSIG 97 #define __WALL WALLSIG 98 #endif /* ! _POSIX_SOURCE */ 99 100 #ifndef _POSIX_SOURCE 101 /* POSIX extensions and 4.2/4.3 compatibility: */ 102 103 /* 104 * Tokens for special values of the "pid" parameter to wait4. 105 */ 106 #define WAIT_ANY (-1) /* any process */ 107 #define WAIT_MYPGRP 0 /* any process in my process group */ 108 109 #include <sys/types.h> 110 111 /* 112 * Deprecated: 113 * Structure of the information in the status word returned by wait4. 114 * If w_stopval==WSTOPPED, then the second structure describes 115 * the information returned, else the first. 116 */ 117 union wait { 118 int w_status; /* used in syscall */ 119 /* 120 * Terminated process status. 121 */ 122 struct { 123 #if BYTE_ORDER == LITTLE_ENDIAN 124 unsigned int w_Termsig:7, /* termination signal */ 125 w_Coredump:1, /* core dump indicator */ 126 w_Retcode:8, /* exit code if w_termsig==0 */ 127 w_Filler:16; /* upper bits filler */ 128 #endif 129 #if BYTE_ORDER == BIG_ENDIAN 130 unsigned int w_Filler:16, /* upper bits filler */ 131 w_Retcode:8, /* exit code if w_termsig==0 */ 132 w_Coredump:1, /* core dump indicator */ 133 w_Termsig:7; /* termination signal */ 134 #endif 135 } w_T; 136 /* 137 * Stopped process status. Returned 138 * only for traced children unless requested 139 * with the WUNTRACED option bit. 140 */ 141 struct { 142 #if BYTE_ORDER == LITTLE_ENDIAN 143 unsigned int w_Stopval:8, /* == W_STOPPED if stopped */ 144 w_Stopsig:8, /* signal that stopped us */ 145 w_Filler:16; /* upper bits filler */ 146 #endif 147 #if BYTE_ORDER == BIG_ENDIAN 148 unsigned int w_Filler:16, /* upper bits filler */ 149 w_Stopsig:8, /* signal that stopped us */ 150 w_Stopval:8; /* == W_STOPPED if stopped */ 151 #endif 152 } w_S; 153 }; 154 #define w_termsig w_T.w_Termsig 155 #define w_coredump w_T.w_Coredump 156 #define w_retcode w_T.w_Retcode 157 #define w_stopval w_S.w_Stopval 158 #define w_stopsig w_S.w_Stopsig 159 160 #define WSTOPPED _WSTOPPED 161 #endif /* _POSIX_SOURCE */ 162 163 #ifndef _KERNEL 164 #include <sys/cdefs.h> 165 166 __BEGIN_DECLS 167 struct rusage; /* forward declaration */ 168 169 pid_t wait __P((int *)); 170 pid_t waitpid __P((pid_t, int *, int)); 171 #ifndef _POSIX_SOURCE 172 pid_t wait3 __P((int *, int, struct rusage *)); 173 pid_t wait4 __P((pid_t, int *, int, struct rusage *)); 174 #endif 175 __END_DECLS 176 #endif 177 178 #endif /* !_SYS_WAIT_H_ */ 179