wait.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Copyright (C) 1991, 1992 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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If
  13. not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
  14. Cambridge, MA 02139, 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. #include <errno.h>
  22. __BEGIN_DECLS
  23. #include <gnu/types.h>
  24. /* This will define the `W*' macros for the flag
  25. bits to `waitpid', `wait3', and `wait4'. */
  26. #include <waitflags.h>
  27. #ifdef __USE_BSD
  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. #ifdef __GNUC__
  31. #define __WAIT_INT(status) \
  32. (__extension__ ({ union { __typeof(status) __in; int __i; } __u; \
  33. __u.__in = (status); __u.__i; }))
  34. #else
  35. #define __WAIT_INT(status) (*(int *) &(status))
  36. #endif
  37. /* This is the type of the argument to `wait'. With GCC 2.6.1 and later,
  38. the funky union causes redeclarations with either `int *' or `union wait
  39. *' to be allowed without complaint. __WAIT_STATUS_DEFN is the type used
  40. in the actual function definitions. */
  41. /* g++ in gcc 2.6.1 doesn't work. Maybe 2.7.x. H.J. */
  42. #if !defined (__GNUC__) || defined (__cplusplus) || \
  43. __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6) || \
  44. (defined(_MIT_POSIX_THREADS) && _MIT_POSIX_THREADS > 0)
  45. #define __WAIT_STATUS __ptr_t
  46. #define __WAIT_STATUS_DEFN __ptr_t
  47. #else
  48. /* This works in GCC 2.6.1 and later. */
  49. typedef union
  50. {
  51. union wait *__uptr;
  52. int *__iptr;
  53. } __WAIT_STATUS __attribute__ ((transparent_union));
  54. #define __WAIT_STATUS_DEFN int *
  55. #endif
  56. #else /* Don't use BSD. */
  57. #define __WAIT_INT(status) (status)
  58. #define __WAIT_STATUS int *
  59. #endif /* Use BSD. */
  60. /* This will define all the `__W*' macros. */
  61. #include <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. #ifdef __USE_BSD
  69. #define WCOREDUMP(status) __WCOREDUMP(__WAIT_INT(status))
  70. #define W_EXITCODE(ret, sig) __W_EXITCODE(ret, sig)
  71. #define W_STOPCODE(sig) __W_STOPCODE(sig)
  72. #endif
  73. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  74. and return its process ID. For errors, return (pid_t) -1. */
  75. extern __pid_t __wait __P ((__WAIT_STATUS __stat_loc));
  76. extern __pid_t wait __P ((__WAIT_STATUS __stat_loc));
  77. #ifdef __USE_BSD
  78. /* Special values for the PID argument to `waitpid' and `wait4'. */
  79. #define WAIT_ANY (-1) /* Any process. */
  80. #define WAIT_MYPGRP 0 /* Any process in my process group. */
  81. #endif
  82. /* Wait for a child matching PID to die.
  83. If PID is greater than 0, match any process whose process ID is PID.
  84. If PID is (pid_t) -1, match any process.
  85. If PID is (pid_t) 0, match any process with the
  86. same process group as the current process.
  87. If PID is less than -1, match any process whose
  88. process group is the absolute value of PID.
  89. If the WNOHANG bit is set in OPTIONS, and that child
  90. is not already dead, return (pid_t) 0. If successful,
  91. return PID and store the dead child's status in STAT_LOC.
  92. Return (pid_t) -1 for errors. If the WUNTRACED bit is
  93. set in OPTIONS, return status for stopped children; otherwise don't. */
  94. extern __pid_t __waitpid __P ((__pid_t __pid, int *__stat_loc,
  95. int __options));
  96. extern __pid_t waitpid __P ((__pid_t __pid, int *__stat_loc,
  97. int __options));
  98. #ifdef __USE_BSD
  99. /* This being here makes the prototypes valid whether or not
  100. we have already included <sys/resource.h> to define `struct rusage'. */
  101. struct rusage;
  102. /* Wait for a child to exit. When one does, put its status in *STAT_LOC and
  103. return its process ID. For errors return (pid_t) -1. If USAGE is not
  104. nil, store information about the child's resource usage there. If the
  105. WUNTRACED bit is set in OPTIONS, return status for stopped children;
  106. otherwise don't. */
  107. extern __pid_t __wait3 __P ((__WAIT_STATUS __stat_loc,
  108. int __options, struct rusage * __usage));
  109. extern __pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
  110. int __options, struct rusage * __usage));
  111. /* PID is like waitpid. Other args are like wait3. */
  112. extern __pid_t __wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
  113. int __options, struct rusage *__usage));
  114. extern __pid_t wait4 __P ((__pid_t __pid, __WAIT_STATUS __stat_loc,
  115. int __options, struct rusage *__usage));
  116. #endif /* Use BSD. */
  117. __END_DECLS
  118. #endif /* sys/wait.h */