1/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18/*
19 * POSIX Standard: 3.2.1 Wait for Process Termination <sys/wait.h>
20 */
21
22#ifndef _SYS_WAIT_H
23#define _SYS_WAIT_H 1
24
25#include <features.h>
26
27__BEGIN_DECLS
28
29#include <signal.h>
30
31/* These macros could also be defined in <stdlib.h>. */
32#if !defined _STDLIB_H || (!defined __USE_XOPEN && !defined __USE_XOPEN2K8)
33/* This will define the `W*' macros for the flag
34 bits to `waitpid', `wait3', and `wait4'. */
35# include <bits/waitflags.h>
36
37# ifdef __USE_BSD
38
39/* Lots of hair to allow traditional BSD use of `union wait'
40 as well as POSIX.1 use of `int' for the status word. */
41
42# if defined __GNUC__ && !defined __cplusplus
43# define __WAIT_INT(status) \
44 (__extension__ (((union { __typeof(status) __in; int __i; }) \
45 { .__in = (status) }).__i))
46# else
47# define __WAIT_INT(status) (*(const int *) &(status))
48# endif
49
50/* This is the type of the argument to `wait'. The funky union
51 causes redeclarations with either `int *' or `union wait *' to be
52 allowed without complaint. __WAIT_STATUS_DEFN is the type used in
53 the actual function definitions. */
54
55# if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
56# define __WAIT_STATUS void *
57# define __WAIT_STATUS_DEFN void *
58# else
59/* This works in GCC 2.6.1 and later. */
60typedef union
61 {
62 union wait *__uptr;
63 int *__iptr;
64 } __WAIT_STATUS __attribute__ ((__transparent_union__));
65# define __WAIT_STATUS_DEFN int *
66# endif
67
68# else /* Don't use BSD. */
69
70# define __WAIT_INT(status) (status)
71# define __WAIT_STATUS int *
72# define __WAIT_STATUS_DEFN int *
73
74# endif /* Use BSD. */
75
76/* This will define all the `__W*' macros. */
77# include <bits/waitstatus.h>
78
79# define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status))
80# define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status))
81# define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status))
82# define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status))
83# define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status))
84# define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status))
85# ifdef __WIFCONTINUED
86# define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status))
87# endif
88#endif /* <stdlib.h> not included. */
89
90#ifdef __USE_BSD
91# define WCOREFLAG __WCOREFLAG
92# define WCOREDUMP(status) __WCOREDUMP (__WAIT_INT (status))
93# define W_EXITCODE(ret, sig) __W_EXITCODE (ret, sig)
94# define W_STOPCODE(sig) __W_STOPCODE (sig)
95#endif
96
97/* Wait for a child to die. When one does, put its status in *STAT_LOC
98 and return its process ID. For errors, return (pid_t) -1.
99
100 This function is a cancellation point and therefore not marked with
101 __THROW. */
102extern __pid_t wait (__WAIT_STATUS __stat_loc);
103
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
109
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
123 This function is a cancellation point and therefore not marked with
124 __THROW. */
125extern __pid_t waitpid (__pid_t __pid, int *__stat_loc, int __options);
126
127#if defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8
128# ifndef __id_t_defined
129# include <bits/types.h>
130typedef __id_t id_t;
131# define __id_t_defined
132# endif
133
134# define __need_siginfo_t
135# include <bits/siginfo.h>
136
137/* Wait for a childing matching IDTYPE and ID to change the status and
138 place appropriate information in *INFOP.
139 If IDTYPE is P_PID, match any process whose process ID is ID.
140 If IDTYPE is P_PGID, match any process whose process group is ID.
141 If IDTYPE is P_ALL, match any process.
142 If the WNOHANG bit is set in OPTIONS, and that child
143 is not already dead, clear *INFOP and return 0. If successful, store
144 exit code and status in *INFOP.
145
146 This function is a cancellation point and therefore not marked with
147 __THROW. */
148extern int waitid (idtype_t __idtype, __id_t __id, siginfo_t *__infop,
149 int __options);
150#endif
151
152#if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
153/* This being here makes the prototypes valid whether or not
154 we have already included <sys/resource.h> to define `struct rusage'. */
155struct rusage;
156
157/* Wait for a child to exit. When one does, put its status in *STAT_LOC and
158 return its process ID. For errors return (pid_t) -1. If USAGE is not
159 nil, store information about the child's resource usage there. If the
160 WUNTRACED bit is set in OPTIONS, return status for stopped children;
161 otherwise don't. */
162extern __pid_t wait3 (__WAIT_STATUS __stat_loc, int __options,
163 struct rusage * __usage) __THROWNL;
164#endif
165
166#ifdef __USE_BSD
167/* PID is like waitpid. Other args are like wait3. */
168extern __pid_t wait4 (__pid_t __pid, __WAIT_STATUS __stat_loc, int __options,
169 struct rusage *__usage) __THROWNL;
170#endif /* Use BSD. */
171
172
173__END_DECLS
174
175#endif /* sys/wait.h */
176