wait.h 6.2 KB

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