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