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