xref: /original-bsd/sys/sys/wait.h (revision dbe44373)
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.8 (Berkeley) 02/22/90
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	_W_INT(i)	(i)
31 #else
32 #define	_W_INT(w)	(*(int *)&(w))	/* convert union wait to int */
33 #define	WCOREFLAG	0200
34 #endif
35 
36 #define	_WSTATUS(x)	(_W_INT(x) & 0177)
37 #define	_WSTOPPED	0177		/* _WSTATUS if process is stopped */
38 #define WIFSTOPPED(x)	(_WSTATUS(x) == _WSTOPPED)
39 #define WSTOPSIG(x)	(_W_INT(x) >> 8)
40 #define WIFSIGNALED(x)	(_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
41 #define WTERMSIG(x)	(_WSTATUS(x))
42 #define WIFEXITED(x)	(_WSTATUS(x) == 0)
43 #define WEXITSTATUS(x)	(_W_INT(x) >> 8)
44 #ifndef _POSIX_SOURCE
45 #define WCOREDUMP(x)	(_W_INT(x) & WCOREFLAG)
46 
47 #define	W_EXITCODE(ret, sig)	((ret) << 8 | (sig))
48 #define	W_STOPCODE(sig)		((sig) << 8 | _WSTOPPED)
49 #endif
50 
51 /*
52  * Option bits for the second argument of wait4.  WNOHANG causes the
53  * wait to not hang if there are no stopped or terminated processes, rather
54  * returning an error indication in this case (pid==0).  WUNTRACED
55  * indicates that the caller should receive status about untraced children
56  * which stop due to signals.  If children are stopped and a wait without
57  * this option is done, it is as though they were still running... nothing
58  * about them is returned.
59  */
60 #define WNOHANG		1	/* dont hang in wait */
61 #define WUNTRACED	2	/* tell about stopped, untraced children */
62 
63 #ifndef _POSIX_SOURCE
64 /* POSIX extensions and 4.2/4.3 compatability: */
65 
66 /*
67  * Tokens for special values of the "pid" parameter to wait4.
68  */
69 #define	WAIT_ANY	(-1)	/* any process */
70 #define	WAIT_MYPGRP	0	/* any process in my process group */
71 
72 #ifndef BYTE_ORDER
73 #include <machine/endian.h>
74 #endif
75 
76 /*
77  * Deprecated:
78  * Structure of the information in the status word returned by wait4.
79  * If w_stopval==WSTOPPED, then the second structure describes
80  * the information returned, else the first.
81  */
82 union wait {
83 	int	w_status;		/* used in syscall */
84 	/*
85 	 * Terminated process status.
86 	 */
87 	struct {
88 #if BYTE_ORDER == LITTLE_ENDIAN
89 		unsigned short	w_Termsig:7;	/* termination signal */
90 		unsigned short	w_Coredump:1;	/* core dump indicator */
91 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
92 #endif
93 #if BYTE_ORDER == BIG_ENDIAN
94 		unsigned short	w_Filler;	/* upper bits filler */
95 		unsigned char	w_Retcode;	/* exit code if w_termsig==0 */
96 		unsigned char	w_Coredump:1;	/* core dump indicator */
97 		unsigned char	w_Termsig:7;	/* termination signal */
98 #endif
99 	} w_T;
100 	/*
101 	 * Stopped process status.  Returned
102 	 * only for traced children unless requested
103 	 * with the WUNTRACED option bit.
104 	 */
105 	struct {
106 #if BYTE_ORDER == LITTLE_ENDIAN
107 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
108 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
109 #else
110 		unsigned short	w_Filler;	/* upper bits filler */
111 		unsigned char	w_Stopsig;	/* signal that stopped us */
112 		unsigned char	w_Stopval;	/* == W_STOPPED if stopped */
113 #endif
114 	} w_S;
115 };
116 #define	w_termsig	w_T.w_Termsig
117 #define w_coredump	w_T.w_Coredump
118 #define w_retcode	w_T.w_Retcode
119 #define w_stopval	w_S.w_Stopval
120 #define w_stopsig	w_S.w_Stopsig
121 
122 #define	WSTOPPED	_WSTOPPED
123 #endif /* _POSIX_SOURCE */
124