xref: /original-bsd/sys/sys/wait.h (revision a5a45b47)
1 /*
2  * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)wait.h	7.17 (Berkeley) 06/19/91
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 second 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	/* dont 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 #ifndef BYTE_ORDER
63 #include <machine/endian.h>
64 #endif
65 
66 /*
67  * Deprecated:
68  * Structure of the information in the status word returned by wait4.
69  * If w_stopval==WSTOPPED, then the second structure describes
70  * the information returned, else the first.
71  */
72 union wait {
73 	int	w_status;		/* used in syscall */
74 	/*
75 	 * Terminated process status.
76 	 */
77 	struct {
78 #if BYTE_ORDER == LITTLE_ENDIAN
79 		unsigned int	w_Termsig:7,	/* termination signal */
80 				w_Coredump:1,	/* core dump indicator */
81 				w_Retcode:8,	/* exit code if w_termsig==0 */
82 				w_Filler:16;	/* upper bits filler */
83 #endif
84 #if BYTE_ORDER == BIG_ENDIAN
85 		unsigned int	w_Filler:16,	/* upper bits filler */
86 				w_Retcode:8,	/* exit code if w_termsig==0 */
87 				w_Coredump:1,	/* core dump indicator */
88 				w_Termsig:7;	/* termination signal */
89 #endif
90 	} w_T;
91 	/*
92 	 * Stopped process status.  Returned
93 	 * only for traced children unless requested
94 	 * with the WUNTRACED option bit.
95 	 */
96 	struct {
97 #if BYTE_ORDER == LITTLE_ENDIAN
98 		unsigned int	w_Stopval:8,	/* == W_STOPPED if stopped */
99 				w_Stopsig:8,	/* signal that stopped us */
100 				w_Filler:16;	/* upper bits filler */
101 #endif
102 #if BYTE_ORDER == BIG_ENDIAN
103 		unsigned int	w_Filler:16,	/* upper bits filler */
104 				w_Stopsig:8,	/* signal that stopped us */
105 				w_Stopval:8;	/* == W_STOPPED if stopped */
106 #endif
107 	} w_S;
108 };
109 #define	w_termsig	w_T.w_Termsig
110 #define w_coredump	w_T.w_Coredump
111 #define w_retcode	w_T.w_Retcode
112 #define w_stopval	w_S.w_Stopval
113 #define w_stopsig	w_S.w_Stopsig
114 
115 #define	WSTOPPED	_WSTOPPED
116 #endif /* _POSIX_SOURCE */
117 
118 #ifndef KERNEL
119 #include <sys/types.h>
120 #include <sys/cdefs.h>
121 
122 __BEGIN_DECLS
123 struct rusage;	/* forward declaration */
124 
125 pid_t	wait __P((int *));
126 pid_t	waitpid __P((pid_t, int *, int));
127 #ifndef _POSIX_SOURCE
128 pid_t	wait3 __P((int *, int, struct rusage *));
129 pid_t	wait4 __P((pid_t, int *, int, struct rusage *));
130 #endif
131 __END_DECLS
132 #endif
133