]>
Commit | Line | Data |
---|---|---|
dfd2257a | 1 | /* Copyright (C) 1991, 92, 93, 94, 96, 97 Free Software Foundation, Inc. |
2c6fe0bd | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
2c6fe0bd UD |
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. | |
28f540f4 | 8 | |
2c6fe0bd UD |
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. | |
28f540f4 | 13 | |
2c6fe0bd UD |
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. */ | |
28f540f4 RM |
18 | |
19 | /* | |
20 | * POSIX Standard: 3.2.1 Wait for Process Termination <sys/wait.h> | |
21 | */ | |
22 | ||
23 | #ifndef _SYS_WAIT_H | |
28f540f4 | 24 | #define _SYS_WAIT_H 1 |
5107cf1d | 25 | |
28f540f4 RM |
26 | #include <features.h> |
27 | ||
28 | __BEGIN_DECLS | |
29 | ||
5107cf1d | 30 | #include <bits/types.h> |
28f540f4 | 31 | |
9756dfe1 UD |
32 | #if defined __USE_UNIX98 && !defined pid_t |
33 | typedef __pid_t pid_t; | |
34 | # define pid_t pid_t | |
35 | #endif | |
36 | ||
28f540f4 RM |
37 | /* This will define the `W*' macros for the flag |
38 | bits to `waitpid', `wait3', and `wait4'. */ | |
5107cf1d | 39 | #include <bits/waitflags.h> |
28f540f4 RM |
40 | |
41 | #ifdef __USE_BSD | |
42 | ||
43 | /* Lots of hair to allow traditional BSD use of `union wait' | |
44 | as well as POSIX.1 use of `int' for the status word. */ | |
45 | ||
04be94a8 | 46 | # if defined __GNUC__ && !defined __cplusplus |
dfd2257a | 47 | # define __WAIT_INT(status) \ |
28f540f4 RM |
48 | (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \ |
49 | __u.__in = (status); __u.__i; })) | |
dfd2257a UD |
50 | # else |
51 | # define __WAIT_INT(status) (*(int *) &(status)) | |
52 | # endif | |
53 | ||
54 | /* This is the type of the argument to `wait'. The funky union | |
55 | causes redeclarations with ether `int *' or `union wait *' to be | |
56 | allowed without complaint. __WAIT_STATUS_DEFN is the type used in | |
57 | the actual function definitions. */ | |
58 | ||
d71b808a | 59 | # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus |
dfd2257a UD |
60 | # define __WAIT_STATUS __ptr_t |
61 | # define __WAIT_STATUS_DEFN __ptr_t | |
62 | # else | |
28f540f4 RM |
63 | /* This works in GCC 2.6.1 and later. */ |
64 | typedef union | |
65 | { | |
66 | union wait *__uptr; | |
67 | int *__iptr; | |
cbdee279 | 68 | } __WAIT_STATUS __attribute__ ((__transparent_union__)); |
dfd2257a | 69 | # define __WAIT_STATUS_DEFN int * |
28f540f4 RM |
70 | #endif |
71 | ||
72 | #else /* Don't use BSD. */ | |
73 | ||
dfd2257a UD |
74 | # define __WAIT_INT(status) (status) |
75 | # define __WAIT_STATUS int * | |
76 | # define __WAIT_STATUS_DEFN int * | |
28f540f4 RM |
77 | |
78 | #endif /* Use BSD. */ | |
79 | ||
80 | /* This will define all the `__W*' macros. */ | |
5107cf1d | 81 | #include <bits/waitstatus.h> |
28f540f4 RM |
82 | |
83 | #define WEXITSTATUS(status) __WEXITSTATUS(__WAIT_INT(status)) | |
84 | #define WTERMSIG(status) __WTERMSIG(__WAIT_INT(status)) | |
85 | #define WSTOPSIG(status) __WSTOPSIG(__WAIT_INT(status)) | |
86 | #define WIFEXITED(status) __WIFEXITED(__WAIT_INT(status)) | |
87 | #define WIFSIGNALED(status) __WIFSIGNALED(__WAIT_INT(status)) | |
88 | #define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status)) | |
89 | ||
90 | #ifdef __USE_BSD | |
dfd2257a UD |
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) | |
28f540f4 RM |
95 | #endif |
96 | ||
bd355af0 UD |
97 | /* The following values are used by the `waitid' function. */ |
98 | #if defined __USE_SVID || defined __USE_XOPEN | |
99 | typedef enum | |
100 | { | |
101 | P_ALL, /* Wait for any child. */ | |
102 | P_PID, /* Wait for specified process. */ | |
103 | P_PGID /* Wait for members of process group. */ | |
104 | } idtype_t; | |
105 | #endif | |
106 | ||
28f540f4 RM |
107 | |
108 | /* Wait for a child to die. When one does, put its status in *STAT_LOC | |
109 | and return its process ID. For errors, return (pid_t) -1. */ | |
110 | extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc)); | |
111 | extern __pid_t wait __P ((__WAIT_STATUS __stat_loc)); | |
112 | ||
113 | #ifdef __USE_BSD | |
114 | /* Special values for the PID argument to `waitpid' and `wait4'. */ | |
dfd2257a UD |
115 | # define WAIT_ANY (-1) /* Any process. */ |
116 | # define WAIT_MYPGRP 0 /* Any process in my process group. */ | |
28f540f4 RM |
117 | #endif |
118 | ||
119 | /* Wait for a child matching PID to die. | |
120 | If PID is greater than 0, match any process whose process ID is PID. | |
121 | If PID is (pid_t) -1, match any process. | |
122 | If PID is (pid_t) 0, match any process with the | |
123 | same process group as the current process. | |
124 | If PID is less than -1, match any process whose | |
125 | process group is the absolute value of PID. | |
126 | If the WNOHANG bit is set in OPTIONS, and that child | |
127 | is not already dead, return (pid_t) 0. If successful, | |
128 | return PID and store the dead child's status in STAT_LOC. | |
129 | Return (pid_t) -1 for errors. If the WUNTRACED bit is | |
130 | set in OPTIONS, return status for stopped children; otherwise don't. */ | |
131 | extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc, | |
132 | int __options)); | |
133 | extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc, | |
134 | int __options)); | |
2c6fe0bd | 135 | |
bd355af0 UD |
136 | #if defined __USE_SVID || defined __USE_XOPEN |
137 | # define __need_siginfo_t | |
138 | # include <bits/siginfo.h> | |
139 | /* Wait for a childing matching IDTYPE and ID to change the status and | |
140 | place appropriate information in *INFOP. | |
141 | If IDTYPE is P_PID, match any process whose process ID is ID. | |
142 | If IDTYPE is P_PGID, match any process whose process group is ID. | |
143 | If IDTYPE is P_ALL, match any process. | |
144 | If the WNOHANG bit is set in OPTIONS, and that child | |
145 | is not already dead, clear *INFOP and return 0. If successful, store | |
146 | exit code and status in *INFOP. */ | |
147 | extern int waitid __P ((idtype_t __idtype, __id_t __id, siginfo_t *__infop, | |
148 | int __options)); | |
149 | #endif | |
150 | ||
dfd2257a | 151 | #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED |
28f540f4 RM |
152 | /* This being here makes the prototypes valid whether or not |
153 | we have already included <sys/resource.h> to define `struct rusage'. */ | |
154 | struct rusage; | |
155 | ||
156 | /* Wait for a child to exit. When one does, put its status in *STAT_LOC and | |
157 | return its process ID. For errors return (pid_t) -1. If USAGE is not | |
158 | nil, store information about the child's resource usage there. If the | |
159 | WUNTRACED bit is set in OPTIONS, return status for stopped children; | |
160 | otherwise don't. */ | |
161 | extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc, | |
162 | int __options, struct rusage * __usage)); | |
163 | extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc, | |
164 | int __options, struct rusage * __usage)); | |
2c6fe0bd UD |
165 | #endif |
166 | ||
167 | #ifdef __USE_BSD | |
168 | /* This being here makes the prototypes valid whether or not | |
169 | we have already included <sys/resource.h> to define `struct rusage'. */ | |
170 | struct rusage; | |
28f540f4 RM |
171 | |
172 | /* PID is like waitpid. Other args are like wait3. */ | |
173 | extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc, | |
174 | int __options, struct rusage *__usage)); | |
175 | extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc, | |
176 | int __options, struct rusage *__usage)); | |
177 | #endif /* Use BSD. */ | |
178 | ||
179 | ||
180 | __END_DECLS | |
181 | ||
182 | #endif /* sys/wait.h */ |