wait.h 6.4 KB

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