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.5 (Berkeley) 04/08/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 #ifndef BYTE_ORDER 26 #include <machine/endian.h> 27 #endif 28 29 /* 30 * Tokens for special values of the "pid" parameter to wait4. 31 */ 32 #define WAIT_ANY (-1) /* any process */ 33 #define WAIT_MYPGRP 0 /* any process in my process group */ 34 35 /* 36 * Structure of the information in the status word returned by wait4. 37 * If w_stopval==WSTOPPED, then the second structure describes 38 * the information returned, else the first. See WUNTRACED below. 39 */ 40 union wait { 41 int w_status; /* used in syscall */ 42 /* 43 * Terminated process status. 44 */ 45 struct { 46 #if BYTE_ORDER == LITTLE_ENDIAN 47 unsigned short w_Termsig:7; /* termination signal */ 48 unsigned short w_Coredump:1; /* core dump indicator */ 49 unsigned short w_Retcode:8; /* exit code if w_termsig==0 */ 50 #endif 51 #if BYTE_ORDER == BIG_ENDIAN 52 unsigned short w_Filler; /* upper bits filler */ 53 unsigned char w_Retcode; /* exit code if w_termsig==0 */ 54 unsigned char w_Coredump:1; /* core dump indicator */ 55 unsigned char w_Termsig:7; /* termination signal */ 56 #endif 57 } w_T; 58 /* 59 * Stopped process status. Returned 60 * only for traced children unless requested 61 * with the WUNTRACED option bit. 62 */ 63 struct { 64 #if BYTE_ORDER == LITTLE_ENDIAN 65 unsigned short w_Stopval:8; /* == W_STOPPED if stopped */ 66 unsigned short w_Stopsig:8; /* signal that stopped us */ 67 #else 68 unsigned short w_Filler; /* upper bits filler */ 69 unsigned char w_Stopsig; /* signal that stopped us */ 70 unsigned char w_Stopval; /* == W_STOPPED if stopped */ 71 #endif 72 } w_S; 73 }; 74 #define w_termsig w_T.w_Termsig 75 #define w_coredump w_T.w_Coredump 76 #define w_retcode w_T.w_Retcode 77 #define w_stopval w_S.w_Stopval 78 #define w_stopsig w_S.w_Stopsig 79 80 81 #define WSTOPPED 0177 /* value of s.stopval if process is stopped */ 82 83 /* 84 * Option bits for the second argument of wait4. WNOHANG causes the 85 * wait to not hang if there are no stopped or terminated processes, rather 86 * returning an error indication in this case (pid==0). WUNTRACED 87 * indicates that the caller should receive status about untraced children 88 * which stop due to signals. If children are stopped and a wait without 89 * this option is done, it is as though they were still running... nothing 90 * about them is returned. By default, a blocking wait call will be 91 * aborted by receipt of a signal that is caught (POSIX); the option 92 * WSIGRESTART causes the call to restart instead of failing with error EINTR. 93 */ 94 #define WNOHANG 1 /* dont hang in wait */ 95 #define WUNTRACED 2 /* tell about stopped, untraced children */ 96 #define WSIGRESTART 4 /* restart wait if signal is received */ 97 98 /* 99 * Macros to test the exit status returned by wait 100 * and extract the relevant values. 101 */ 102 #define WIFSTOPPED(x) ((x).w_stopval == WSTOPPED) 103 #define WSTOPSIG(x) ((x).w_stopsig) 104 105 #define WIFSIGNALED(x) ((x).w_stopval != WSTOPPED && (x).w_termsig != 0) 106 #define WTERMSIG(x) ((x).w_termsig) 107 #define WCOREDUMP(x) ((x).w_coredump) 108 109 #define WIFEXITED(x) ((x).w_stopval != WSTOPPED && (x).w_termsig == 0) 110 #define WEXITSTATUS(x) ((x).w_retcode) 111