1 /* 2 * Copyright (c) 1982, 1986, 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)wait.h 7.7 (Berkeley) 08/26/89 18 */ 19 20 /* 21 * This file holds definitions relevent to the wait4 system call 22 * and the alternate interfaces that use it (wait, wait3, waitpid). 23 */ 24 25 /* 26 * Macros to test the exit status returned by wait 27 * and extract the relevant values. 28 */ 29 #ifdef _POSIX_SOURCE 30 #define _WSTATUS(x) ((x) & 0377) /* 0, _WSTOPPED, or signal */ 31 #else 32 #define _W_INT(x) (*(int *)(x)) /* convert union wait to int */ 33 #define _WSTATUS(x) (_W_INT(x) & 0177) 34 #endif 35 36 #define _WSTOPPED 0177 /* _WSTATUS if process is stopped */ 37 #define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED) 38 #define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0) 39 #define WTERMSIG(x) (_WSTATUS(x)) 40 #define WIFEXITED(x) (_WSTATUS(x) == 0) 41 42 #ifdef _POSIX_SOURCE 43 #define WSTOPSIG(x) ((x) >> 8) 44 #define WEXITSTATUS(x) ((x) >> 8) 45 46 #else /* _POSIX_SOURCE */ 47 #define WSTOPSIG(x) (_W_INT(x) >> 8) 48 #define WCOREDUMP(x) (_W_INT(x) & 0200) 49 #define WEXITSTATUS(x) (_W_INT(x) >> 8) 50 #endif /* _POSIX_SOURCE */ 51 52 /* 53 * Option bits for the second argument of wait4. WNOHANG causes the 54 * wait to not hang if there are no stopped or terminated processes, rather 55 * returning an error indication in this case (pid==0). WUNTRACED 56 * indicates that the caller should receive status about untraced children 57 * which stop due to signals. If children are stopped and a wait without 58 * this option is done, it is as though they were still running... nothing 59 * about them is returned. By default, a blocking wait call will be 60 * aborted by receipt of a signal that is caught (POSIX); the option 61 * WSIGRESTART causes the call to restart instead of failing with error EINTR. 62 */ 63 #define WNOHANG 1 /* dont hang in wait */ 64 #define WUNTRACED 2 /* tell about stopped, untraced children */ 65 66 #ifndef _POSIX_SOURCE /* extensions/compat follow: */ 67 /* additional option bit for wait4: */ 68 #define WSIGRESTART 4 /* restart wait if signal is received */ 69 70 /* 71 * Tokens for special values of the "pid" parameter to wait4. 72 */ 73 #define WAIT_ANY (-1) /* any process */ 74 #define WAIT_MYPGRP 0 /* any process in my process group */ 75 76 #ifndef BYTE_ORDER 77 #include <machine/endian.h> 78 #endif 79 80 /* 81 * Deprecated: 82 * Structure of the information in the status word returned by wait4. 83 * If w_stopval==WSTOPPED, then the second structure describes 84 * the information returned, else the first. 85 */ 86 union wait { 87 int w_status; /* used in syscall */ 88 /* 89 * Terminated process status. 90 */ 91 struct { 92 #if BYTE_ORDER == LITTLE_ENDIAN 93 unsigned short w_Termsig:7; /* termination signal */ 94 unsigned short w_Coredump:1; /* core dump indicator */ 95 unsigned short w_Retcode:8; /* exit code if w_termsig==0 */ 96 #endif 97 #if BYTE_ORDER == BIG_ENDIAN 98 unsigned short w_Filler; /* upper bits filler */ 99 unsigned char w_Retcode; /* exit code if w_termsig==0 */ 100 unsigned char w_Coredump:1; /* core dump indicator */ 101 unsigned char w_Termsig:7; /* termination signal */ 102 #endif 103 } w_T; 104 /* 105 * Stopped process status. Returned 106 * only for traced children unless requested 107 * with the WUNTRACED option bit. 108 */ 109 struct { 110 #if BYTE_ORDER == LITTLE_ENDIAN 111 unsigned short w_Stopval:8; /* == W_STOPPED if stopped */ 112 unsigned short w_Stopsig:8; /* signal that stopped us */ 113 #else 114 unsigned short w_Filler; /* upper bits filler */ 115 unsigned char w_Stopsig; /* signal that stopped us */ 116 unsigned char w_Stopval; /* == W_STOPPED if stopped */ 117 #endif 118 } w_S; 119 }; 120 #define w_termsig w_T.w_Termsig 121 #define w_coredump w_T.w_Coredump 122 #define w_retcode w_T.w_Retcode 123 #define w_stopval w_S.w_Stopval 124 #define w_stopsig w_S.w_Stopsig 125 126 #define WSTOPPED _WSTOPPED 127 #endif /* _POSIX_SOURCE */ 128