Add a forward declaration of struct rusage.
[unix-history] / usr / src / sys / sys / wait.h
CommitLineData
da7c5cc6 1/*
651fed09
MK
2 * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
3 * All rights reserved.
da7c5cc6 4 *
6dc0e27a 5 * %sccs.include.redist.c%
651fed09 6 *
9b90173d 7 * @(#)wait.h 7.16 (Berkeley) %G%
da7c5cc6 8 */
f7300f91
SL
9
10/*
651fed09
MK
11 * This file holds definitions relevent to the wait4 system call
12 * and the alternate interfaces that use it (wait, wait3, waitpid).
f7300f91
SL
13 */
14
af55001e
MK
15/*
16 * Macros to test the exit status returned by wait
17 * and extract the relevant values.
18 */
19#ifdef _POSIX_SOURCE
348d07de 20#define _W_INT(i) (i)
af55001e 21#else
348d07de
MK
22#define _W_INT(w) (*(int *)&(w)) /* convert union wait to int */
23#define WCOREFLAG 0200
8dc8eea2
MK
24#endif
25
348d07de 26#define _WSTATUS(x) (_W_INT(x) & 0177)
af55001e
MK
27#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
28#define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
348d07de 29#define WSTOPSIG(x) (_W_INT(x) >> 8)
af55001e
MK
30#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
31#define WTERMSIG(x) (_WSTATUS(x))
32#define WIFEXITED(x) (_WSTATUS(x) == 0)
af55001e 33#define WEXITSTATUS(x) (_W_INT(x) >> 8)
348d07de
MK
34#ifndef _POSIX_SOURCE
35#define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
36
37#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
38#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
39#endif
af55001e
MK
40
41/*
42 * Option bits for the second argument of wait4. WNOHANG causes the
43 * wait to not hang if there are no stopped or terminated processes, rather
44 * returning an error indication in this case (pid==0). WUNTRACED
45 * indicates that the caller should receive status about untraced children
46 * which stop due to signals. If children are stopped and a wait without
47 * this option is done, it is as though they were still running... nothing
348d07de 48 * about them is returned.
af55001e
MK
49 */
50#define WNOHANG 1 /* dont hang in wait */
51#define WUNTRACED 2 /* tell about stopped, untraced children */
52
348d07de
MK
53#ifndef _POSIX_SOURCE
54/* POSIX extensions and 4.2/4.3 compatability: */
af55001e 55
f7300f91 56/*
651fed09
MK
57 * Tokens for special values of the "pid" parameter to wait4.
58 */
af55001e
MK
59#define WAIT_ANY (-1) /* any process */
60#define WAIT_MYPGRP 0 /* any process in my process group */
61
62#ifndef BYTE_ORDER
63#include <machine/endian.h>
64#endif
651fed09
MK
65
66/*
af55001e 67 * Deprecated:
651fed09
MK
68 * Structure of the information in the status word returned by wait4.
69 * If w_stopval==WSTOPPED, then the second structure describes
af55001e 70 * the information returned, else the first.
f7300f91 71 */
651fed09 72union wait {
f7300f91
SL
73 int w_status; /* used in syscall */
74 /*
75 * Terminated process status.
76 */
77 struct {
f8b9a4f5 78#if BYTE_ORDER == LITTLE_ENDIAN
f7300f91
SL
79 unsigned short w_Termsig:7; /* termination signal */
80 unsigned short w_Coredump:1; /* core dump indicator */
81 unsigned short w_Retcode:8; /* exit code if w_termsig==0 */
8dc8eea2 82#endif
f8b9a4f5 83#if BYTE_ORDER == BIG_ENDIAN
8dc8eea2
MK
84 unsigned short w_Filler; /* upper bits filler */
85 unsigned char w_Retcode; /* exit code if w_termsig==0 */
86 unsigned char w_Coredump:1; /* core dump indicator */
87 unsigned char w_Termsig:7; /* termination signal */
88#endif
f7300f91
SL
89 } w_T;
90 /*
91 * Stopped process status. Returned
92 * only for traced children unless requested
93 * with the WUNTRACED option bit.
94 */
95 struct {
f8b9a4f5 96#if BYTE_ORDER == LITTLE_ENDIAN
f7300f91
SL
97 unsigned short w_Stopval:8; /* == W_STOPPED if stopped */
98 unsigned short w_Stopsig:8; /* signal that stopped us */
8dc8eea2
MK
99#else
100 unsigned short w_Filler; /* upper bits filler */
101 unsigned char w_Stopsig; /* signal that stopped us */
102 unsigned char w_Stopval; /* == W_STOPPED if stopped */
103#endif
f7300f91
SL
104 } w_S;
105};
106#define w_termsig w_T.w_Termsig
107#define w_coredump w_T.w_Coredump
108#define w_retcode w_T.w_Retcode
109#define w_stopval w_S.w_Stopval
110#define w_stopsig w_S.w_Stopsig
111
af55001e 112#define WSTOPPED _WSTOPPED
47d6c3f1 113#endif /* _POSIX_SOURCE */
82c2b826 114
740eafd7 115#ifndef KERNEL
0f9e0ffb 116#include <sys/types.h>
91befe9c
KB
117#include <sys/cdefs.h>
118
119__BEGIN_DECLS
9b90173d
DS
120struct rusage; /* forward declaration */
121
91befe9c 122pid_t wait __P((int *));
844002d9
DS
123pid_t waitpid __P((pid_t, int *, int));
124#ifndef _POSIX_SOURCE
91befe9c
KB
125pid_t wait3 __P((int *, int, struct rusage *));
126pid_t wait4 __P((pid_t, int *, int, struct rusage *));
844002d9 127#endif
91befe9c 128__END_DECLS
740eafd7 129#endif