xref: /onnv-gate/usr/src/lib/libbc/inc/include/sys/wait.h (revision 3517:79d66aa80b8b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright 1989 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate  * Copyright (c) 1982, 1986 Regents of the University of California.
80Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate  */
110Sstevel@tonic-gate 
12722Smuffin #ifndef	__sys_wait_h
13722Smuffin #define	__sys_wait_h
14722Smuffin 
150Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
160Sstevel@tonic-gate 
170Sstevel@tonic-gate /*
18*3517Smp204432  * This file holds definitions relevant to the wait system call.
190Sstevel@tonic-gate  * Some of the options here are available only through the ``wait3''
200Sstevel@tonic-gate  * entry point; the old entry point with one argument has more fixed
210Sstevel@tonic-gate  * semantics, never returning status of unstopped children, hanging until
220Sstevel@tonic-gate  * a process terminates if any are outstanding, and never returns
230Sstevel@tonic-gate  * detailed information about process resource utilization (<vtimes.h>).
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_POSIX_SOURCE
270Sstevel@tonic-gate #define	__wait		wait
280Sstevel@tonic-gate #define	w_termsig	__w_termsig
290Sstevel@tonic-gate #define	w_coredump	__w_coredump
300Sstevel@tonic-gate #define	w_retcode	__w_retcode
310Sstevel@tonic-gate #define	w_stopval	__w_stopval
320Sstevel@tonic-gate #define	w_stopsig	__w_stopsig
330Sstevel@tonic-gate #define	WSTOPPED	_WSTOPPED
34722Smuffin #endif	/* !_POSIX_SOURCE */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * Structure of the information in the first word returned by both
380Sstevel@tonic-gate  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
390Sstevel@tonic-gate  * describes the information returned, else the first.  See WUNTRACED below.
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate union __wait	{
420Sstevel@tonic-gate 	int	w_status;		/* used in syscall */
430Sstevel@tonic-gate 	/*
440Sstevel@tonic-gate 	 * Terminated process status.
450Sstevel@tonic-gate 	 */
460Sstevel@tonic-gate 	struct {
470Sstevel@tonic-gate 		unsigned short	w_Fill1:16;	/* high 16 bits unused */
480Sstevel@tonic-gate 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
490Sstevel@tonic-gate 		unsigned short	w_Coredump:1;	/* core dump indicator */
500Sstevel@tonic-gate 		unsigned short	w_Termsig:7;	/* termination signal */
510Sstevel@tonic-gate 	} w_T;
520Sstevel@tonic-gate 	/*
530Sstevel@tonic-gate 	 * Stopped process status.  Returned
540Sstevel@tonic-gate 	 * only for traced children unless requested
550Sstevel@tonic-gate 	 * with the WUNTRACED option bit.
560Sstevel@tonic-gate 	 */
570Sstevel@tonic-gate 	struct {
580Sstevel@tonic-gate 		unsigned short	w_Fill2:16;	/* high 16 bits unused */
590Sstevel@tonic-gate 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
600Sstevel@tonic-gate 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
610Sstevel@tonic-gate 	} w_S;
620Sstevel@tonic-gate };
630Sstevel@tonic-gate #define	__w_termsig	w_T.w_Termsig
640Sstevel@tonic-gate #define	__w_coredump	w_T.w_Coredump
650Sstevel@tonic-gate #define	__w_retcode	w_T.w_Retcode
660Sstevel@tonic-gate #define	__w_stopval	w_S.w_Stopval
670Sstevel@tonic-gate #define	__w_stopsig	w_S.w_Stopsig
680Sstevel@tonic-gate #define	_WSTOPPED	0177	/* value of s.stopval if process is stopped */
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * Option bits for the second argument of wait3.  WNOHANG causes the
720Sstevel@tonic-gate  * wait to not hang if there are no stopped or terminated processes, rather
730Sstevel@tonic-gate  * returning an error indication in this case (pid==0).  WUNTRACED
740Sstevel@tonic-gate  * indicates that the caller should receive status about untraced children
750Sstevel@tonic-gate  * which stop due to signals.  If children are stopped and a wait without
760Sstevel@tonic-gate  * this option is done, it is as though they were still running... nothing
770Sstevel@tonic-gate  * about them is returned.
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate #define	WNOHANG		1	/* dont hang in wait */
800Sstevel@tonic-gate #define	WUNTRACED	2	/* tell about stopped, untraced children */
810Sstevel@tonic-gate 
820Sstevel@tonic-gate #define	WIFSTOPPED(x)	(((union __wait*)&(x))->__w_stopval == _WSTOPPED)
830Sstevel@tonic-gate #define	WIFSIGNALED(x)	(((union __wait*)&(x))->__w_stopval != _WSTOPPED && \
840Sstevel@tonic-gate 			((union __wait*)&(x))->__w_termsig != 0)
850Sstevel@tonic-gate #define	WIFEXITED(x)	(((union __wait*)&(x))->__w_stopval != _WSTOPPED && \
860Sstevel@tonic-gate 			((union __wait*)&(x))->__w_termsig == 0)
870Sstevel@tonic-gate #define	WEXITSTATUS(x)	(((union __wait*)&(x))->__w_retcode)
880Sstevel@tonic-gate #define	WTERMSIG(x)	(((union __wait*)&(x))->__w_termsig)
890Sstevel@tonic-gate #define	WSTOPSIG(x)	(((union __wait*)&(x))->__w_stopsig)
900Sstevel@tonic-gate 
910Sstevel@tonic-gate #include <sys/stdtypes.h>
920Sstevel@tonic-gate 
930Sstevel@tonic-gate pid_t	wait(/* int *loc */);
940Sstevel@tonic-gate pid_t	waitpid(/* pid_t pid, int *loc, int opts */);
950Sstevel@tonic-gate 
960Sstevel@tonic-gate #endif	/* !__sys_wait_h */
97