1 /* 2 * Copyright (c) 1982, 1986, 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)wait.h 8.2 (Berkeley) 07/10/94 8 */ 9 10 /* 11 * This file holds definitions relevent to the wait4 system call 12 * and the alternate interfaces that use it (wait, wait3, waitpid). 13 */ 14 15 /* 16 * Macros to test the exit status returned by wait 17 * and extract the relevant values. 18 */ 19 #ifdef _POSIX_SOURCE 20 #define _W_INT(i) (i) 21 #else 22 #define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */ 23 #define WCOREFLAG 0200 24 #endif 25 26 #define _WSTATUS(x) (_W_INT(x) & 0177) 27 #define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 28 #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 29 #define WSTOPSIG(x) (_W_INT(x) >> 8) 30 #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) 31 #define WTERMSIG(x) (_WSTATUS(x)) 32 #define WIFEXITED(x) (_WSTATUS(x) == 0) 33 #define WEXITSTATUS(x) (_W_INT(x) >> 8) 34 #ifndef _POSIX_SOURCE 35 #define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG) 36 37 #define W_EXITCODE(ret, sig) ((ret) << 8 | (sig)) 38 #define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED) 39 #endif 40 41 /* 42 * Option bits for the third argument of wait4. WNOHANG causes the 43 * wait to not hang if there are no stopped or terminated processes, rather 44 * returning an error indication in this case (pid==0). WUNTRACED 45 * indicates that the caller should receive status about untraced children 46 * which stop due to signals. If children are stopped and a wait without 47 * this option is done, it is as though they were still running... nothing 48 * about them is returned. 49 */ 50 #define WNOHANG 1 /* don't hang in wait */ 51 #define WUNTRACED 2 /* tell about stopped, untraced children */ 52 53 #ifndef _POSIX_SOURCE 54 /* POSIX extensions and 4.2/4.3 compatability: */ 55 56 /* 57 * Tokens for special values of the "pid" parameter to wait4. 58 */ 59 #define WAIT_ANY (-1) /* any process */ 60 #define WAIT_MYPGRP 0 /* any process in my process group */ 61 62 #include <machine/endian.h> 63 64 /* 65 * Deprecated: 66 * Structure of the information in the status word returned by wait4. 67 * If w_stopval==WSTOPPED, then the second structure describes 68 * the information returned, else the first. 69 */ 70 union wait { 71 int w_status; /* used in syscall */ 72 /* 73 * Terminated process status. 74 */ 75 struct { 76 #if BYTE_ORDER == LITTLE_ENDIAN 77 unsigned int w_Termsig:7, /* termination signal */ 78 w_Coredump:1, /* core dump indicator */ 79 w_Retcode:8, /* exit code if w_termsig==0 */ 80 w_Filler:16; /* upper bits filler */ 81 #endif 82 #if BYTE_ORDER == BIG_ENDIAN 83 unsigned int w_Filler:16, /* upper bits filler */ 84 w_Retcode:8, /* exit code if w_termsig==0 */ 85 w_Coredump:1, /* core dump indicator */ 86 w_Termsig:7; /* termination signal */ 87 #endif 88 } w_T; 89 /* 90 * Stopped process status. Returned 91 * only for traced children unless requested 92 * with the WUNTRACED option bit. 93 */ 94 struct { 95 #if BYTE_ORDER == LITTLE_ENDIAN 96 unsigned int w_Stopval:8, /* == W_STOPPED if stopped */ 97 w_Stopsig:8, /* signal that stopped us */ 98 w_Filler:16; /* upper bits filler */ 99 #endif 100 #if BYTE_ORDER == BIG_ENDIAN 101 unsigned int w_Filler:16, /* upper bits filler */ 102 w_Stopsig:8, /* signal that stopped us */ 103 w_Stopval:8; /* == W_STOPPED if stopped */ 104 #endif 105 } w_S; 106 }; 107 #define w_termsig w_T.w_Termsig 108 #define w_coredump w_T.w_Coredump 109 #define w_retcode w_T.w_Retcode 110 #define w_stopval w_S.w_Stopval 111 #define w_stopsig w_S.w_Stopsig 112 113 #define WSTOPPED _WSTOPPED 114 #endif /* _POSIX_SOURCE */ 115 116 #ifndef KERNEL 117 #include <sys/types.h> 118 #include <sys/cdefs.h> 119 120 __BEGIN_DECLS 121 struct rusage; /* forward declaration */ 122 123 pid_t wait __P((int *)); 124 pid_t waitpid __P((pid_t, int *, int)); 125 #ifndef _POSIX_SOURCE 126 pid_t wait3 __P((int *, int, struct rusage *)); 127 pid_t wait4 __P((pid_t, int *, int, struct rusage *)); 128 #endif 129 __END_DECLS 130 #endif 131