Back to index

glibc  2.9
wait.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-1994,1996-2001,2003,2004,2005,2007
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /*
00021  *     POSIX Standard: 3.2.1 Wait for Process Termination      <sys/wait.h>
00022  */
00023 
00024 #ifndef       _SYS_WAIT_H
00025 #define       _SYS_WAIT_H   1
00026 
00027 #include <features.h>
00028 
00029 __BEGIN_DECLS
00030 
00031 #include <signal.h>
00032 #include <sys/resource.h>
00033 
00034 /* These macros could also be defined in <stdlib.h>.  */
00035 #if !defined _STDLIB_H || !defined __USE_XOPEN
00036 /* This will define the `W*' macros for the flag
00037    bits to `waitpid', `wait3', and `wait4'.  */
00038 # include <bits/waitflags.h>
00039 
00040 # ifdef       __USE_BSD
00041 
00042 /* Lots of hair to allow traditional BSD use of `union wait'
00043    as well as POSIX.1 use of `int' for the status word.  */
00044 
00045 #  if defined __GNUC__ && !defined __cplusplus
00046 #   define __WAIT_INT(status) \
00047   (__extension__ (((union { __typeof(status) __in; int __i; }) \
00048                    { .__in = (status) }).__i))
00049 #  else
00050 #   define __WAIT_INT(status)      (*(__const int *) &(status))
00051 #  endif
00052 
00053 /* This is the type of the argument to `wait'.  The funky union
00054    causes redeclarations with ether `int *' or `union wait *' to be
00055    allowed without complaint.  __WAIT_STATUS_DEFN is the type used in
00056    the actual function definitions.  */
00057 
00058 #  if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
00059 #   define __WAIT_STATUS    void *
00060 #   define __WAIT_STATUS_DEFN      void *
00061 #  else
00062 /* This works in GCC 2.6.1 and later.  */
00063 typedef union
00064   {
00065     union wait *__uptr;
00066     int *__iptr;
00067   } __WAIT_STATUS __attribute__ ((__transparent_union__));
00068 #   define __WAIT_STATUS_DEFN      int *
00069 #  endif
00070 
00071 # else /* Don't use BSD.  */
00072 
00073 #  define __WAIT_INT(status)       (status)
00074 #  define __WAIT_STATUS            int *
00075 #  define __WAIT_STATUS_DEFN       int *
00076 
00077 # endif /* Use BSD.  */
00078 
00079 /* This will define all the `__W*' macros.  */
00080 # include <bits/waitstatus.h>
00081 
00082 # define WEXITSTATUS(status)       __WEXITSTATUS(__WAIT_INT(status))
00083 # define WTERMSIG(status)   __WTERMSIG(__WAIT_INT(status))
00084 # define WSTOPSIG(status)   __WSTOPSIG(__WAIT_INT(status))
00085 # define WIFEXITED(status)  __WIFEXITED(__WAIT_INT(status))
00086 # define WIFSIGNALED(status)       __WIFSIGNALED(__WAIT_INT(status))
00087 # define WIFSTOPPED(status) __WIFSTOPPED(__WAIT_INT(status))
00088 # ifdef __WIFCONTINUED
00089 #  define WIFCONTINUED(status)     __WIFCONTINUED(__WAIT_INT(status))
00090 # endif
00091 #endif /* <stdlib.h> not included.  */
00092 
00093 #ifdef __USE_BSD
00094 # define WCOREFLAG          __WCOREFLAG
00095 # define WCOREDUMP(status)  __WCOREDUMP(__WAIT_INT(status))
00096 # define W_EXITCODE(ret, sig)      __W_EXITCODE(ret, sig)
00097 # define W_STOPCODE(sig)    __W_STOPCODE(sig)
00098 #endif
00099 
00100 /* The following values are used by the `waitid' function.  */
00101 #if defined __USE_SVID || defined __USE_XOPEN
00102 typedef enum
00103 {
00104   P_ALL,             /* Wait for any child.  */
00105   P_PID,             /* Wait for specified process.  */
00106   P_PGID             /* Wait for members of process group.  */
00107 } idtype_t;
00108 #endif
00109 
00110 
00111 /* Wait for a child to die.  When one does, put its status in *STAT_LOC
00112    and return its process ID.  For errors, return (pid_t) -1.
00113 
00114    This function is a cancellation point and therefore not marked with
00115    __THROW.  */
00116 extern __pid_t wait (__WAIT_STATUS __stat_loc);
00117 
00118 #ifdef __USE_BSD
00119 /* Special values for the PID argument to `waitpid' and `wait4'.  */
00120 # define WAIT_ANY    (-1)   /* Any process.  */
00121 # define WAIT_MYPGRP 0      /* Any process in my process group.  */
00122 #endif
00123 
00124 /* Wait for a child matching PID to die.
00125    If PID is greater than 0, match any process whose process ID is PID.
00126    If PID is (pid_t) -1, match any process.
00127    If PID is (pid_t) 0, match any process with the
00128    same process group as the current process.
00129    If PID is less than -1, match any process whose
00130    process group is the absolute value of PID.
00131    If the WNOHANG bit is set in OPTIONS, and that child
00132    is not already dead, return (pid_t) 0.  If successful,
00133    return PID and store the dead child's status in STAT_LOC.
00134    Return (pid_t) -1 for errors.  If the WUNTRACED bit is
00135    set in OPTIONS, return status for stopped children; otherwise don't.
00136 
00137    This function is a cancellation point and therefore not marked with
00138    __THROW.  */
00139 extern __pid_t waitpid (__pid_t __pid, int *__stat_loc, int __options);
00140 
00141 #if defined __USE_SVID || defined __USE_XOPEN
00142 # define __need_siginfo_t
00143 # include <bits/siginfo.h>
00144 /* Wait for a childing matching IDTYPE and ID to change the status and
00145    place appropriate information in *INFOP.
00146    If IDTYPE is P_PID, match any process whose process ID is ID.
00147    If IDTYPE is P_PGID, match any process whose process group is ID.
00148    If IDTYPE is P_ALL, match any process.
00149    If the WNOHANG bit is set in OPTIONS, and that child
00150    is not already dead, clear *INFOP and return 0.  If successful, store
00151    exit code and status in *INFOP.
00152 
00153    This function is a cancellation point and therefore not marked with
00154    __THROW.  */
00155 extern int waitid (idtype_t __idtype, __id_t __id, siginfo_t *__infop,
00156                  int __options);
00157 #endif
00158 
00159 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
00160 /* This being here makes the prototypes valid whether or not
00161    we have already included <sys/resource.h> to define `struct rusage'.  */
00162 struct rusage;
00163 
00164 /* Wait for a child to exit.  When one does, put its status in *STAT_LOC and
00165    return its process ID.  For errors return (pid_t) -1.  If USAGE is not
00166    nil, store information about the child's resource usage there.  If the
00167    WUNTRACED bit is set in OPTIONS, return status for stopped children;
00168    otherwise don't.  */
00169 extern __pid_t wait3 (__WAIT_STATUS __stat_loc, int __options,
00170                     struct rusage * __usage) __THROW;
00171 #endif
00172 
00173 #ifdef __USE_BSD
00174 /* PID is like waitpid.  Other args are like wait3.  */
00175 extern __pid_t wait4 (__pid_t __pid, __WAIT_STATUS __stat_loc, int __options,
00176                     struct rusage *__usage) __THROW;
00177 #endif /* Use BSD.  */
00178 
00179 
00180 __END_DECLS
00181 
00182 #endif /* sys/wait.h  */