xref: /illumos-gate/usr/src/cmd/csh/wait.h (revision 9164a50bf932130cbb5097a16f6986873ce0e6e5)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  *
8  *	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
9  *	  All Rights Reserved
10  *
11  * Copyright (c) 1980 Regents of the University of California.
12  * All rights reserved.  The Berkeley Software License Agreement
13  * specifies the terms and conditions for redistribution.
14  */
15 
16 /*
17  * This file holds definitions relevant to the wait system call.
18  * Some of the options here are available only through the ``wait3''
19  * entry point; the old entry point with one argument has more fixed
20  * semantics, never returning status of unstopped children, hanging until
21  * a process terminates if any are outstanding, and never returns
22  * detailed information about process resource utilization (<vtimes.h>).
23  */
24 
25 #ifndef _sys_wait_h
26 #define	_sys_wait_h
27 
28 #include <sys/isa_defs.h>	/* included for _LITTLE_ENDIAN define	*/
29 
30 /*
31  * Structure of the information in the first word returned by both
32  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
33  * describes the information returned, else the first.  See WUNTRACED below.
34  */
35 union wait	{
36 	int	w_status;		/* used in syscall */
37 	/*
38 	 * Terminated process status.
39 	 */
40 	struct {
41 #if	defined(_LITTLE_ENDIAN)
42 		unsigned short	w_Termsig:7;	/* termination signal */
43 		unsigned short	w_Coredump:1;	/* core dump indicator */
44 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
45 #elif	defined(_BIG_ENDIAN)
46 		unsigned short	w_Fill1:16;	/* high 16 bits unused */
47 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
48 		unsigned short	w_Coredump:1;	/* core dump indicator */
49 		unsigned short	w_Termsig:7;	/* termination signal */
50 #else
51 #error	NO ENDIAN defined.
52 #endif
53 	} w_T;
54 	/*
55 	 * Stopped process status.  Returned
56 	 * only for traced children unless requested
57 	 * with the WUNTRACED option bit.
58 	 */
59 	struct {
60 #if	defined(_LITTLE_ENDIAN)
61 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
62 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
63 #elif	defined(_BIG_ENDIAN)
64 		unsigned short	w_Fill2:16;	/* high 16 bits unused */
65 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
66 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
67 #else
68 #error	NO ENDIAN defined.
69 #endif
70 	} w_S;
71 };
72 #define	w_termsig	w_T.w_Termsig
73 #define	w_coredump	w_T.w_Coredump
74 #define	w_retcode	w_T.w_Retcode
75 #define	w_stopval	w_S.w_Stopval
76 #define	w_stopsig	w_S.w_Stopsig
77 
78 
79 #define	WSTOPPED	0177	/* value of s.stopval if process is stopped */
80 #define	WCONTFLG	0177777	/* value of w.w_status due to SIGCONT, sysV */
81 
82 /*
83  * Option bits for the second argument of wait3.  WNOHANG causes the
84  * wait to not hang if there are no stopped or terminated processes, rather
85  * returning an error indication in this case (pid==0).  WUNTRACED
86  * indicates that the caller should receive status about untraced children
87  * which stop due to signals.  If children are stopped and a wait without
88  * this option is done, it is as though they were still running... nothing
89  * about them is returned.
90  */
91 #define	WNOHANG		1	/* dont hang in wait */
92 #define	WUNTRACED	2	/* tell about stopped, untraced children */
93 
94 #define	WIFSTOPPED(x)	((x).w_stopval == WSTOPPED)
95 #define	WIFSIGNALED(x)	((x).w_stopval != WSTOPPED && (x).w_termsig != 0)
96 #define	WIFEXITED(x)	((x).w_stopval != WSTOPPED && (x).w_termsig == 0)
97 
98 extern pid_t csh_wait3(union wait *w, int options, struct rusage *rp);
99 extern pid_t csh_wait_noreap(void);
100 
101 #endif /* _sys_wait_h */
102