xref: /original-bsd/sys/sys/wait.h (revision d272e02a)
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.16 (Berkeley) 02/23/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 short	w_Termsig:7;	/* termination signal */
80 		unsigned short	w_Coredump:1;	/* core dump indicator */
81 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
82 #endif
83 #if BYTE_ORDER == BIG_ENDIAN
84 		unsigned short	w_Filler;	/* upper bits filler */
85 		unsigned char	w_Retcode;	/* exit code if w_termsig==0 */
86 		unsigned char	w_Coredump:1;	/* core dump indicator */
87 		unsigned char	w_Termsig:7;	/* termination signal */
88 #endif
89 	} w_T;
90 	/*
91 	 * Stopped process status.  Returned
92 	 * only for traced children unless requested
93 	 * with the WUNTRACED option bit.
94 	 */
95 	struct {
96 #if BYTE_ORDER == LITTLE_ENDIAN
97 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
98 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
99 #else
100 		unsigned short	w_Filler;	/* upper bits filler */
101 		unsigned char	w_Stopsig;	/* signal that stopped us */
102 		unsigned char	w_Stopval;	/* == W_STOPPED if stopped */
103 #endif
104 	} w_S;
105 };
106 #define	w_termsig	w_T.w_Termsig
107 #define w_coredump	w_T.w_Coredump
108 #define w_retcode	w_T.w_Retcode
109 #define w_stopval	w_S.w_Stopval
110 #define w_stopsig	w_S.w_Stopsig
111 
112 #define	WSTOPPED	_WSTOPPED
113 #endif /* _POSIX_SOURCE */
114 
115 #ifndef KERNEL
116 #include <sys/types.h>
117 #include <sys/cdefs.h>
118 
119 __BEGIN_DECLS
120 struct rusage;	/* forward declaration */
121 
122 pid_t	wait __P((int *));
123 pid_t	waitpid __P((pid_t, int *, int));
124 #ifndef _POSIX_SOURCE
125 pid_t	wait3 __P((int *, int, struct rusage *));
126 pid_t	wait4 __P((pid_t, int *, int, struct rusage *));
127 #endif
128 __END_DECLS
129 #endif
130