xref: /titanic_51/usr/src/lib/libbc/inc/include/sys/wait.h (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * Copyright (c) 1982, 1986 Regents of the University of California.
8  * All rights reserved. The Berkeley software License Agreement
9  * specifies the terms and conditions for redistribution.
10  */
11 
12 #pragma ident	"%Z%%M%	%I%	%E% SMI"
13 
14 /*
15  * This file holds definitions relevent to the wait system call.
16  * Some of the options here are available only through the ``wait3''
17  * entry point; the old entry point with one argument has more fixed
18  * semantics, never returning status of unstopped children, hanging until
19  * a process terminates if any are outstanding, and never returns
20  * detailed information about process resource utilization (<vtimes.h>).
21  */
22 
23 #ifndef	__sys_wait_h
24 #define	__sys_wait_h
25 
26 #ifndef	_POSIX_SOURCE
27 #define	__wait		wait
28 #define	w_termsig	__w_termsig
29 #define	w_coredump	__w_coredump
30 #define	w_retcode	__w_retcode
31 #define	w_stopval	__w_stopval
32 #define	w_stopsig	__w_stopsig
33 #define	WSTOPPED	_WSTOPPED
34 #endif	!_POSIX_SOURCE
35 
36 /*
37  * Structure of the information in the first word returned by both
38  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
39  * describes the information returned, else the first.  See WUNTRACED below.
40  */
41 union __wait	{
42 	int	w_status;		/* used in syscall */
43 	/*
44 	 * Terminated process status.
45 	 */
46 	struct {
47 #if	defined(vax) || defined(i386)
48 		unsigned short	w_Termsig:7;	/* termination signal */
49 		unsigned short	w_Coredump:1;	/* core dump indicator */
50 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
51 #endif
52 #if	defined(mc68000) || defined(sparc)
53 		unsigned short	w_Fill1:16;	/* high 16 bits unused */
54 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
55 		unsigned short	w_Coredump:1;	/* core dump indicator */
56 		unsigned short	w_Termsig:7;	/* termination signal */
57 #endif
58 	} w_T;
59 	/*
60 	 * Stopped process status.  Returned
61 	 * only for traced children unless requested
62 	 * with the WUNTRACED option bit.
63 	 */
64 	struct {
65 #if	defined(vax) || defined(i386)
66 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
67 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
68 #endif
69 #if	defined(mc68000) || defined(sparc)
70 		unsigned short	w_Fill2:16;	/* high 16 bits unused */
71 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
72 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
73 #endif
74 	} w_S;
75 };
76 #define	__w_termsig	w_T.w_Termsig
77 #define	__w_coredump	w_T.w_Coredump
78 #define	__w_retcode	w_T.w_Retcode
79 #define	__w_stopval	w_S.w_Stopval
80 #define	__w_stopsig	w_S.w_Stopsig
81 #define	_WSTOPPED	0177	/* value of s.stopval if process is stopped */
82 
83 /*
84  * Option bits for the second argument of wait3.  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.
91  */
92 #define	WNOHANG		1	/* dont hang in wait */
93 #define	WUNTRACED	2	/* tell about stopped, untraced children */
94 
95 #define	WIFSTOPPED(x)	(((union __wait*)&(x))->__w_stopval == _WSTOPPED)
96 #define	WIFSIGNALED(x)	(((union __wait*)&(x))->__w_stopval != _WSTOPPED && \
97 			((union __wait*)&(x))->__w_termsig != 0)
98 #define	WIFEXITED(x)	(((union __wait*)&(x))->__w_stopval != _WSTOPPED && \
99 			((union __wait*)&(x))->__w_termsig == 0)
100 #define	WEXITSTATUS(x)	(((union __wait*)&(x))->__w_retcode)
101 #define	WTERMSIG(x)	(((union __wait*)&(x))->__w_termsig)
102 #define	WSTOPSIG(x)	(((union __wait*)&(x))->__w_stopsig)
103 
104 #if	defined(KERNEL)  &&  !defined(_POSIX_SOURCE)
105 /*
106  * Arguments to wait4() system call, included here so it may be called by
107  * other routines in the kernel.
108  */
109 struct wait4_args {
110 	int pid;
111 	union wait *status;
112 	int options;
113 	struct rusage *rusage;
114 };
115 #endif	KERNEL
116 
117 #ifndef	KERNEL
118 #include <sys/stdtypes.h>
119 
120 pid_t	wait(/* int *loc */);
121 pid_t	waitpid(/* pid_t pid, int *loc, int opts */);
122 #endif
123 
124 #endif	/* !__sys_wait_h */
125