wait.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* Copyright (C) 1991-1994,1996-2001,2003,2004,2005,2007,2009
  2. Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. /*
  16. * POSIX Standard: 3.2.1 Wait for Process Termination <sys/wait.h>
  17. */
  18. #ifndef _SYS_WAIT_H
  19. #define _SYS_WAIT_H 1
  20. #include <features.h>
  21. __BEGIN_DECLS
  22. #include <signal.h>
  23. /* These macros could also be defined in <stdlib.h>. */
  24. #if !defined _STDLIB_H || (!defined __USE_XOPEN && !defined __USE_XOPEN2K8)
  25. /* This will define the `W*' macros for the flag
  26. bits to `waitpid', `wait3', and `wait4'. */
  27. # include <bits/waitflags.h>
  28. # ifdef __USE_BSD
  29. /* Lots of hair to allow traditional BSD use of `union wait'
  30. as well as POSIX.1 use of `int' for the status word. */
  31. # if defined __GNUC__ && !defined __cplusplus
  32. # define __WAIT_INT(status) \
  33. (__extension__ (((union { __typeof(status) __in; int __i; }) \
  34. { .__in = (status) }).__i))
  35. # else
  36. # define __WAIT_INT(status) (*(const int *) &(status))
  37. # endif
  38. /* This is the type of the argument to `wait'. The funky union
  39. causes redeclarations with either `int *' or `union wait *' to be
  40. allowed without complaint. __WAIT_STATUS_DEFN is the type used in
  41. the actual function definitions. */
  42. # if !defined __GNUC__ || __GNUC__ < 2 || defined __cplusplus
  43. # define __WAIT_STATUS void *
  44. # define __WAIT_STATUS_DEFN void *
  45. # else
  46. /* This works in GCC 2.6.1 and later. */
  47. typedef union
  48. {
  49. union wait *__uptr;
  50. int *__iptr;
  51. } __WAIT_STATUS __attribute__ ((__transparent_union__));
  52. # define __WAIT_STATUS_DEFN int *
  53. # endif
  54. # else /* Don't use BSD. */
  55. # define __WAIT_INT(status) (status)
  56. # define __WAIT_STATUS int *
  57. # define __WAIT_STATUS_DEFN int *
  58. # endif /* Use BSD. */
  59. /* This will define all the `__W*' macros. */
  60. # include <bits/waitstatus.h>
  61. # define WEXITSTATUS(status) __WEXITSTATUS (__WAIT_INT (status))
  62. # define WTERMSIG(status) __WTERMSIG (__WAIT_INT (status))
  63. # define WSTOPSIG(status) __WSTOPSIG (__WAIT_INT (status))
  64. # define WIFEXITED(status) __WIFEXITED (__WAIT_INT (status))
  65. # define WIFSIGNALED(status) __WIFSIGNALED (__WAIT_INT (status))
  66. # define WIFSTOPPED(status) __WIFSTOPPED (__WAIT_INT (status))
  67. # ifdef __WIFCONTINUED
  68. # define WIFCONTINUED(status) __WIFCONTINUED (__WAIT_INT (status))
  69. # endif
  70. #endif /* <stdlib.h> not included. */
  71. #ifdef __USE_BSD
  72. # define WCOREFLAG __WCOREFLAG
  73. # define WCOREDUMP(status) __WCOREDUMP (__WAIT_INT (status))
  74. # define W_EXITCODE(ret, sig) __W_EXITCODE (ret, sig)
  75. # define W_STOPCODE(sig) __W_STOPCODE (sig)
  76. #endif
  77. /* The following values are used by the `waitid' function. */
  78. #if defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8
  79. typedef enum
  80. {
  81. P_ALL, /* Wait for any child. */
  82. P_PID, /* Wait for specified process. */
  83. P_PGID /* Wait for members of process group. */
  84. } idtype_t;
  85. #endif
  86. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  87. and return its process ID. For errors, return (pid_t) -1.
  88. This function is a cancellation point and therefore not marked with
  89. __THROW. */
  90. extern __pid_t wait (__WAIT_STATUS __stat_loc);
  91. #ifdef __USE_BSD
  92. /* Special values for the PID argument to `waitpid' and `wait4'. */
  93. # define WAIT_ANY (-1) /* Any process. */
  94. # define WAIT_MYPGRP 0 /* Any process in my process group. */
  95. #endif
  96. /* Wait for a child matching PID to die.
  97. If PID is greater than 0, match any process whose process ID is PID.
  98. If PID is (pid_t) -1, match any process.
  99. If PID is (pid_t) 0, match any process with the
  100. same process group as the current process.
  101. If PID is less than -1, match any process whose
  102. process group is the absolute value of PID.
  103. If the WNOHANG bit is set in OPTIONS, and that child
  104. is not already dead, return (pid_t) 0. If successful,
  105. return PID and store the dead child's status in STAT_LOC.
  106. Return (pid_t) -1 for errors. If the WUNTRACED bit is
  107. set in OPTIONS, return status for stopped children; otherwise don't.
  108. This function is a cancellation point and therefore not marked with
  109. __THROW. */
  110. extern __pid_t waitpid (__pid_t __pid, int *__stat_loc, int __options);
  111. #ifdef _LIBC
  112. extern __typeof(waitpid) __waitpid_nocancel attribute_hidden;
  113. libc_hidden_proto(waitpid)
  114. #endif
  115. #if defined __USE_SVID || defined __USE_XOPEN || defined __USE_XOPEN2K8
  116. # ifndef __id_t_defined
  117. # include <bits/types.h>
  118. typedef __id_t id_t;
  119. # define __id_t_defined
  120. # endif
  121. # define __need_siginfo_t
  122. # include <bits/siginfo.h>
  123. /* Wait for a childing matching IDTYPE and ID to change the status and
  124. place appropriate information in *INFOP.
  125. If IDTYPE is P_PID, match any process whose process ID is ID.
  126. If IDTYPE is P_PGID, match any process whose process group is ID.
  127. If IDTYPE is P_ALL, match any process.
  128. If the WNOHANG bit is set in OPTIONS, and that child
  129. is not already dead, clear *INFOP and return 0. If successful, store
  130. exit code and status in *INFOP.
  131. This function is a cancellation point and therefore not marked with
  132. __THROW. */
  133. extern int waitid (idtype_t __idtype, __id_t __id, siginfo_t *__infop,
  134. int __options);
  135. #endif
  136. #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
  137. struct rusage;
  138. /* Wait for a child to exit. When one does, put its status in *STAT_LOC and
  139. return its process ID. For errors return (pid_t) -1. If USAGE is not
  140. nil, store information about the child's resource usage there. If the
  141. WUNTRACED bit is set in OPTIONS, return status for stopped children;
  142. otherwise don't. */
  143. extern __pid_t wait3 (__WAIT_STATUS __stat_loc, int __options,
  144. struct rusage * __usage) __THROWNL;
  145. #endif
  146. #ifdef __USE_BSD
  147. /* PID is like waitpid. Other args are like wait3. */
  148. extern __pid_t wait4 (__pid_t __pid, __WAIT_STATUS __stat_loc, int __options,
  149. struct rusage *__usage) __THROWNL;
  150. #endif /* Use BSD. */
  151. #ifdef _LIBC
  152. extern __pid_t __wait4_nocancel(__pid_t, __WAIT_STATUS, int, struct rusage *) attribute_hidden;
  153. #endif
  154. __END_DECLS
  155. #endif /* sys/wait.h */