1 /* $OpenBSD: wait.h,v 1.11 2003/08/03 19:25:49 millert 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 /* 39 * This file holds definitions relevent to the wait4 system call 40 * and the alternate interfaces that use it (wait, wait3, waitpid). 41 */ 42 43 /* 44 * Macros to test the exit status returned by wait 45 * and extract the relevant values. 46 */ 47 #ifdef _POSIX_SOURCE 48 #define _W_INT(i) (i) 49 #else 50 #define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */ 51 #define WCOREFLAG 0200 52 #endif 53 54 #define _WSTATUS(x) (_W_INT(x) & 0177) 55 #define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 56 #define _WCONTINUED 0177777 /* process has continued */ 57 #define WIFSTOPPED(x) ((_W_INT(x) & 0xff) == _WSTOPPED) 58 #define WSTOPSIG(x) ((_W_INT(x) >> 8) & 0xff) 59 #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) 60 #define WTERMSIG(x) (_WSTATUS(x)) 61 #define WIFEXITED(x) (_WSTATUS(x) == 0) 62 #define WEXITSTATUS(x) ((_W_INT(x) >> 8) & 0xff) 63 #define WIFCONTINUED(x) ((_W_INT(x) & _WCONTINUED) == _WCONTINUED) 64 #ifndef _POSIX_SOURCE 65 #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 66 67 #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 68 #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 69 #endif 70 71 /* 72 * Option bits for the third argument of wait4. WNOHANG causes the 73 * wait to not hang if there are no stopped or terminated processes, rather 74 * returning an error indication in this case (pid==0). WUNTRACED 75 * indicates that the caller should receive status about untraced children 76 * which stop due to signals. If children are stopped and a wait without 77 * this option is done, it is as though they were still running... nothing 78 * about them is returned. 79 */ 80 #define WNOHANG 1 /* don't hang in wait */ 81 #define WUNTRACED 2 /* tell about stopped, untraced children */ 82 #ifndef _POSIX_SOURCE 83 #define WALTSIG 4 /* wait for child with alternate exit signal */ 84 #endif 85 #define WCONTINUED 8 /* report a job control continued process */ 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 #include <sys/types.h> 97 98 /* 99 * Deprecated: 100 * Structure of the information in the status word returned by wait4. 101 * If w_stopval==WSTOPPED, then the second structure describes 102 * the information returned, else the first. 103 */ 104 union wait { 105 int w_status; /* used in syscall */ 106 /* 107 * Terminated process status. 108 */ 109 struct { 110 #if BYTE_ORDER == LITTLE_ENDIAN 111 unsigned int w_Termsig:7, /* termination signal */ 112 w_Coredump:1, /* core dump indicator */ 113 w_Retcode:8, /* exit code if w_termsig==0 */ 114 w_Filler:16; /* upper bits filler */ 115 #endif 116 #if BYTE_ORDER == BIG_ENDIAN 117 unsigned int w_Filler:16, /* upper bits filler */ 118 w_Retcode:8, /* exit code if w_termsig==0 */ 119 w_Coredump:1, /* core dump indicator */ 120 w_Termsig:7; /* termination signal */ 121 #endif 122 } w_T; 123 /* 124 * Stopped process status. Returned 125 * only for traced children unless requested 126 * with the WUNTRACED option bit. 127 */ 128 struct { 129 #if BYTE_ORDER == LITTLE_ENDIAN 130 unsigned int w_Stopval:8, /* == W_STOPPED if stopped */ 131 w_Stopsig:8, /* signal that stopped us */ 132 w_Filler:16; /* upper bits filler */ 133 #endif 134 #if BYTE_ORDER == BIG_ENDIAN 135 unsigned int w_Filler:16, /* upper bits filler */ 136 w_Stopsig:8, /* signal that stopped us */ 137 w_Stopval:8; /* == W_STOPPED if stopped */ 138 #endif 139 } w_S; 140 }; 141 #define w_termsig w_T.w_Termsig 142 #define w_coredump w_T.w_Coredump 143 #define w_retcode w_T.w_Retcode 144 #define w_stopval w_S.w_Stopval 145 #define w_stopsig w_S.w_Stopsig 146 147 #define WSTOPPED _WSTOPPED 148 #endif /* _POSIX_SOURCE */ 149 150 #ifndef _KERNEL 151 #include <sys/types.h> 152 #include <sys/cdefs.h> 153 154 __BEGIN_DECLS 155 struct rusage; /* forward declaration */ 156 157 pid_t wait(int *); 158 pid_t waitpid(pid_t, int *, int); 159 #ifndef _POSIX_SOURCE 160 pid_t wait3(int *, int, struct rusage *); 161 pid_t wait4(pid_t, int *, int, struct rusage *); 162 #endif 163 __END_DECLS 164 #endif 165 166 #endif /* !_SYS_WAIT_H_ */ 167