xref: /illumos-gate/usr/src/cmd/csh/wait.h (revision 63360950)
17c478bd9Sstevel@tonic-gate /*
28e3c57a3Sraf  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
48e3c57a3Sraf  */
68e3c57a3Sraf /*
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  *	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T
97c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
127c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley Software License Agreement
137c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
147c478bd9Sstevel@tonic-gate  */
167c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
187c478bd9Sstevel@tonic-gate /*
19*63360950Smp  * This file holds definitions relevant to the wait system call.
207c478bd9Sstevel@tonic-gate  * Some of the options here are available only through the ``wait3''
217c478bd9Sstevel@tonic-gate  * entry point; the old entry point with one argument has more fixed
227c478bd9Sstevel@tonic-gate  * semantics, never returning status of unstopped children, hanging until
237c478bd9Sstevel@tonic-gate  * a process terminates if any are outstanding, and never returns
247c478bd9Sstevel@tonic-gate  * detailed information about process resource utilization (<vtimes.h>).
257c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate #ifndef _sys_wait_h
288e3c57a3Sraf #define	_sys_wait_h
308e3c57a3Sraf #include <sys/isa_defs.h>	/* included for _LITTLE_ENDIAN define	*/
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * Structure of the information in the first word returned by both
347c478bd9Sstevel@tonic-gate  * wait and wait3.  If w_stopval==WSTOPPED, then the second structure
357c478bd9Sstevel@tonic-gate  * describes the information returned, else the first.  See WUNTRACED below.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate union wait	{
387c478bd9Sstevel@tonic-gate 	int	w_status;		/* used in syscall */
397c478bd9Sstevel@tonic-gate 	/*
407c478bd9Sstevel@tonic-gate 	 * Terminated process status.
417c478bd9Sstevel@tonic-gate 	 */
427c478bd9Sstevel@tonic-gate 	struct {
437c478bd9Sstevel@tonic-gate #if	defined(_LITTLE_ENDIAN)
447c478bd9Sstevel@tonic-gate 		unsigned short	w_Termsig:7;	/* termination signal */
457c478bd9Sstevel@tonic-gate 		unsigned short	w_Coredump:1;	/* core dump indicator */
467c478bd9Sstevel@tonic-gate 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
477c478bd9Sstevel@tonic-gate #elif	defined(_BIG_ENDIAN)
487c478bd9Sstevel@tonic-gate 		unsigned short	w_Fill1:16;	/* high 16 bits unused */
497c478bd9Sstevel@tonic-gate 		unsigned short	w_Retcode:8;	/* exit code if w_termsig==0 */
507c478bd9Sstevel@tonic-gate 		unsigned short	w_Coredump:1;	/* core dump indicator */
517c478bd9Sstevel@tonic-gate 		unsigned short	w_Termsig:7;	/* termination signal */
527c478bd9Sstevel@tonic-gate #else
537c478bd9Sstevel@tonic-gate #error	NO ENDIAN defined.
547c478bd9Sstevel@tonic-gate #endif
557c478bd9Sstevel@tonic-gate 	} w_T;
567c478bd9Sstevel@tonic-gate 	/*
577c478bd9Sstevel@tonic-gate 	 * Stopped process status.  Returned
587c478bd9Sstevel@tonic-gate 	 * only for traced children unless requested
597c478bd9Sstevel@tonic-gate 	 * with the WUNTRACED option bit.
607c478bd9Sstevel@tonic-gate 	 */
617c478bd9Sstevel@tonic-gate 	struct {
627c478bd9Sstevel@tonic-gate #if	defined(_LITTLE_ENDIAN)
637c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
647c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
657c478bd9Sstevel@tonic-gate #elif	defined(_BIG_ENDIAN)
667c478bd9Sstevel@tonic-gate 		unsigned short	w_Fill2:16;	/* high 16 bits unused */
677c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopsig:8;	/* signal that stopped us */
687c478bd9Sstevel@tonic-gate 		unsigned short	w_Stopval:8;	/* == W_STOPPED if stopped */
697c478bd9Sstevel@tonic-gate #else
707c478bd9Sstevel@tonic-gate #error	NO ENDIAN defined.
717c478bd9Sstevel@tonic-gate #endif
727c478bd9Sstevel@tonic-gate 	} w_S;
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate #define	w_termsig	w_T.w_Termsig
758e3c57a3Sraf #define	w_coredump	w_T.w_Coredump
768e3c57a3Sraf #define	w_retcode	w_T.w_Retcode
778e3c57a3Sraf #define	w_stopval	w_S.w_Stopval
788e3c57a3Sraf #define	w_stopsig	w_S.w_Stopsig
817c478bd9Sstevel@tonic-gate #define	WSTOPPED	0177	/* value of s.stopval if process is stopped */
828e3c57a3Sraf #define	WCONTFLG	0177777	/* value of w.w_status due to SIGCONT, sysV */
847c478bd9Sstevel@tonic-gate /*
857c478bd9Sstevel@tonic-gate  * Option bits for the second argument of wait3.  WNOHANG causes the
867c478bd9Sstevel@tonic-gate  * wait to not hang if there are no stopped or terminated processes, rather
877c478bd9Sstevel@tonic-gate  * returning an error indication in this case (pid==0).  WUNTRACED
887c478bd9Sstevel@tonic-gate  * indicates that the caller should receive status about untraced children
897c478bd9Sstevel@tonic-gate  * which stop due to signals.  If children are stopped and a wait without
907c478bd9Sstevel@tonic-gate  * this option is done, it is as though they were still running... nothing
917c478bd9Sstevel@tonic-gate  * about them is returned.
927c478bd9Sstevel@tonic-gate  */
938e3c57a3Sraf #define	WNOHANG		1	/* dont hang in wait */
948e3c57a3Sraf #define	WUNTRACED	2	/* tell about stopped, untraced children */
968e3c57a3Sraf #define	WIFSTOPPED(x)	((x).w_stopval == WSTOPPED)
978e3c57a3Sraf #define	WIFSIGNALED(x)	((x).w_stopval != WSTOPPED && (x).w_termsig != 0)
988e3c57a3Sraf #define	WIFEXITED(x)	((x).w_stopval != WSTOPPED && (x).w_termsig == 0)
1008e3c57a3Sraf extern pid_t csh_wait3(union wait *w, int options, struct rusage *rp);
1018e3c57a3Sraf extern pid_t csh_wait_noreap(void);
1038e3c57a3Sraf #endif /* _sys_wait_h */