update from main archive 961105
[glibc.git] / posix / sys / wait.h
bloba13b825638f105b2b174e758c5594c819ebcb5c0
1 /* Copyright (C) 1991, 92, 93, 94, 96 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * POSIX Standard: 3.2.1 Wait for Process Termination <sys/wait.h>
23 #ifndef _SYS_WAIT_H
25 #define _SYS_WAIT_H 1
26 #include <features.h>
28 __BEGIN_DECLS
30 #include <gnu/types.h>
32 /* This will define the `W*' macros for the flag
33 bits to `waitpid', `wait3', and `wait4'. */
34 #include <waitflags.h>
36 #ifdef __USE_BSD
38 /* Lots of hair to allow traditional BSD use of `union wait'
39 as well as POSIX.1 use of `int' for the status word. */
41 #ifdef __GNUC__
42 #define __WAIT_INT(status) \
43 (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \
44 __u.__in = (status); __u.__i; }))
45 #else
46 #define __WAIT_INT(status) (*(int *) &(status))
47 #endif
49 /* This is the type of the argument to `wait'.
51 NOTE: Since this functionality is volatile, I'm disabling the use of it for
52 now.
54 With GCC 2.6.1 and later, the funky union causes redeclarations with either
55 `int *' or `union wait *' to be allowed without complaint.
56 __WAIT_STATUS_DEFN is the type used in the actual function
57 definitions. */
59 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
60 /*(__GNUC__ == 2 && __GNUC_MINOR__ < 6)*/ 1)
61 #define __WAIT_STATUS __ptr_t
62 #define __WAIT_STATUS_DEFN __ptr_t
63 #else
64 /* This works in GCC 2.6.1 and later. */
65 typedef union
67 union wait *__uptr;
68 int *__iptr;
69 } __WAIT_STATUS __attribute__ ((transparent_union));
70 #define __WAIT_STATUS_DEFN int *
71 #endif
73 #else /* Don't use BSD. */
75 #define __WAIT_INT(status) (status)
76 #define __WAIT_STATUS int *
77 #define __WAIT_STATUS_DEFN int *
79 #endif /* Use BSD. */
81 /* This will define all the `__W*' macros. */
82 #include <waitstatus.h>
84 #define WEXITSTATUS(status) __WEXITSTATUS(__WAIT_INT(status))
85 #define WTERMSIG(status) __WTERMSIG(__WAIT_INT(status))
86 #define WSTOPSIG(status) __WSTOPSIG(__WAIT_INT(status))
87 #define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status))
88 #define WIFSIGNALED(status) __WIFSIGNALED(__WAIT_INT(status))
89 #define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status))
91 #ifdef __USE_BSD
92 #define WCOREFLAG __WCOREFLAG
93 #define WCOREDUMP(status) __WCOREDUMP(__WAIT_INT(status))
94 #define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig)
95 #define W_STOPCODE(sig) __W_STOPCODE(sig)
96 #endif
99 /* Wait for a child to die. When one does, put its status in *STAT_LOC
100 and return its process ID. For errors, return (pid_t) -1. */
101 extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc));
102 extern __pid_t wait __P ((__WAIT_STATUS __stat_loc));
104 #ifdef __USE_BSD
105 /* Special values for the PID argument to `waitpid' and `wait4'. */
106 #define WAIT_ANY (-1) /* Any process. */
107 #define WAIT_MYPGRP 0 /* Any process in my process group. */
108 #endif
110 /* Wait for a child matching PID to die.
111 If PID is greater than 0, match any process whose process ID is PID.
112 If PID is (pid_t) -1, match any process.
113 If PID is (pid_t) 0, match any process with the
114 same process group as the current process.
115 If PID is less than -1, match any process whose
116 process group is the absolute value of PID.
117 If the WNOHANG bit is set in OPTIONS, and that child
118 is not already dead, return (pid_t) 0. If successful,
119 return PID and store the dead child's status in STAT_LOC.
120 Return (pid_t) -1 for errors. If the WUNTRACED bit is
121 set in OPTIONS, return status for stopped children; otherwise don't. */
122 extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc,
123 int __options));
124 extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc,
125 int __options));
127 #if defined(__USE_BSD) || defined(__USE_XOPEN_EXTENDED)
128 /* This being here makes the prototypes valid whether or not
129 we have already included <sys/resource.h> to define `struct rusage'. */
130 struct rusage;
132 /* Wait for a child to exit. When one does, put its status in *STAT_LOC and
133 return its process ID. For errors return (pid_t) -1. If USAGE is not
134 nil, store information about the child's resource usage there. If the
135 WUNTRACED bit is set in OPTIONS, return status for stopped children;
136 otherwise don't. */
137 extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc,
138 int __options, struct rusage * __usage));
139 extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
140 int __options, struct rusage * __usage));
141 #endif
143 #ifdef __USE_BSD
144 /* This being here makes the prototypes valid whether or not
145 we have already included <sys/resource.h> to define `struct rusage'. */
146 struct rusage;
148 /* PID is like waitpid. Other args are like wait3. */
149 extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
150 int __options, struct rusage *__usage));
151 extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
152 int __options, struct rusage *__usage));
153 #endif /* Use BSD. */
156 __END_DECLS
158 #endif /* sys/wait.h */