Update.
[platform/upstream/glibc.git] / posix / sys / wait.h
1 /* Copyright (C) 1991, 92, 93, 94, 96, 97 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 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.
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    Library General Public License for more details.
13
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.  */
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 <bits/types.h>
31
32 /* This will define the `W*' macros for the flag
33    bits to `waitpid', `wait3', and `wait4'.  */
34 #include <bits/waitflags.h>
35
36 #ifdef  __USE_BSD
37
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.  */
40
41 # if defined __GNUC__ && !defined __cplusplus
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
48
49 /* This is the type of the argument to `wait'.  The funky union
50    causes redeclarations with ether `int *' or `union wait *' to be
51    allowed without complaint.  __WAIT_STATUS_DEFN is the type used in
52    the actual function definitions.  */
53
54 # if !defined __GNUC__ || __GNUC__ < 2
55 #  define __WAIT_STATUS         __ptr_t
56 #  define __WAIT_STATUS_DEFN    __ptr_t
57 # else
58 /* This works in GCC 2.6.1 and later.  */
59 typedef union
60   {
61     union wait *__uptr;
62     int *__iptr;
63   } __WAIT_STATUS __attribute__ ((__transparent_union__));
64 # define __WAIT_STATUS_DEFN     int *
65 #endif
66
67 #else /* Don't use BSD.  */
68
69 # define __WAIT_INT(status)     (status)
70 # define __WAIT_STATUS          int *
71 # define __WAIT_STATUS_DEFN     int *
72
73 #endif /* Use BSD.  */
74
75 /* This will define all the `__W*' macros.  */
76 #include <bits/waitstatus.h>
77
78 #define WEXITSTATUS(status)     __WEXITSTATUS(__WAIT_INT(status))
79 #define WTERMSIG(status)        __WTERMSIG(__WAIT_INT(status))
80 #define WSTOPSIG(status)        __WSTOPSIG(__WAIT_INT(status))
81 #define WIFEXITED(status)       __WIFEXITED(__WAIT_INT(status))
82 #define WIFSIGNALED(status)     __WIFSIGNALED(__WAIT_INT(status))
83 #define WIFSTOPPED(status)      __WIFSTOPPED(__WAIT_INT(status))
84
85 #ifdef  __USE_BSD
86 # define WCOREFLAG              __WCOREFLAG
87 # define WCOREDUMP(status)      __WCOREDUMP(__WAIT_INT(status))
88 # define W_EXITCODE(ret, sig)   __W_EXITCODE(ret, sig)
89 # define W_STOPCODE(sig)        __W_STOPCODE(sig)
90 #endif
91
92
93 /* Wait for a child to die.  When one does, put its status in *STAT_LOC
94    and return its process ID.  For errors, return (pid_t) -1.  */
95 extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc));
96 extern __pid_t wait __P ((__WAIT_STATUS __stat_loc));
97
98 #ifdef  __USE_BSD
99 /* Special values for the PID argument to `waitpid' and `wait4'.  */
100 # define WAIT_ANY       (-1)    /* Any process.  */
101 # define WAIT_MYPGRP    0       /* Any process in my process group.  */
102 #endif
103
104 /* Wait for a child matching PID to die.
105    If PID is greater than 0, match any process whose process ID is PID.
106    If PID is (pid_t) -1, match any process.
107    If PID is (pid_t) 0, match any process with the
108    same process group as the current process.
109    If PID is less than -1, match any process whose
110    process group is the absolute value of PID.
111    If the WNOHANG bit is set in OPTIONS, and that child
112    is not already dead, return (pid_t) 0.  If successful,
113    return PID and store the dead child's status in STAT_LOC.
114    Return (pid_t) -1 for errors.  If the WUNTRACED bit is
115    set in OPTIONS, return status for stopped children; otherwise don't.  */
116 extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc,
117                                int __options));
118 extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc,
119                              int __options));
120
121 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
122 /* This being here makes the prototypes valid whether or not
123    we have already included <sys/resource.h> to define `struct rusage'.  */
124 struct rusage;
125
126 /* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
127    return its process ID.  For errors return (pid_t) -1.  If USAGE is not
128    nil, store information about the child's resource usage there.  If the
129    WUNTRACED bit is set in OPTIONS, return status for stopped children;
130    otherwise don't.  */
131 extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc,
132                              int __options, struct rusage * __usage));
133 extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
134                            int __options, struct rusage * __usage));
135 #endif
136
137 #ifdef __USE_BSD
138 /* This being here makes the prototypes valid whether or not
139    we have already included <sys/resource.h> to define `struct rusage'.  */
140 struct rusage;
141
142 /* PID is like waitpid.  Other args are like wait3.  */
143 extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
144                              int __options, struct rusage *__usage));
145 extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
146                            int __options, struct rusage *__usage));
147 #endif /* Use BSD.  */
148
149
150 __END_DECLS
151
152 #endif /* sys/wait.h  */