wait.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* Copyright (C) 1991-2021 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. <https://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 <bits/types.h>
  22. #ifndef __pid_t_defined
  23. typedef __pid_t pid_t;
  24. # define __pid_t_defined
  25. #endif
  26. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  27. # include <signal.h>
  28. #endif
  29. #if defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K8
  30. /* Some older standards require the contents of struct rusage to be
  31. defined here. */
  32. # include <bits/types/struct_rusage.h>
  33. #endif
  34. /* These macros could also be defined in <stdlib.h>. */
  35. #if !defined _STDLIB_H || (!defined __USE_XOPEN && !defined __USE_XOPEN2K8)
  36. /* This will define the `W*' macros for the flag
  37. bits to `waitpid', `wait3', and `wait4'. */
  38. # include <bits/waitflags.h>
  39. /* This will define all the `__W*' macros. */
  40. # include <bits/waitstatus.h>
  41. # define WEXITSTATUS(status) __WEXITSTATUS (status)
  42. # define WTERMSIG(status) __WTERMSIG (status)
  43. # define WSTOPSIG(status) __WSTOPSIG (status)
  44. # define WIFEXITED(status) __WIFEXITED (status)
  45. # define WIFSIGNALED(status) __WIFSIGNALED (status)
  46. # define WIFSTOPPED(status) __WIFSTOPPED (status)
  47. # ifdef __WIFCONTINUED
  48. # define WIFCONTINUED(status) __WIFCONTINUED (status)
  49. # endif
  50. #endif /* <stdlib.h> not included. */
  51. #ifdef __USE_MISC
  52. # define WCOREFLAG __WCOREFLAG
  53. # define WCOREDUMP(status) __WCOREDUMP (status)
  54. # define W_EXITCODE(ret, sig) __W_EXITCODE (ret, sig)
  55. # define W_STOPCODE(sig) __W_STOPCODE (sig)
  56. #endif
  57. /* The following values are used by the `waitid' function. */
  58. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  59. typedef enum
  60. {
  61. P_ALL, /* Wait for any child. */
  62. P_PID, /* Wait for specified process. */
  63. P_PGID /* Wait for members of process group. */
  64. } idtype_t;
  65. #endif
  66. /* Wait for a child to die. When one does, put its status in *STAT_LOC
  67. and return its process ID. For errors, return (pid_t) -1.
  68. This function is a cancellation point and therefore not marked with
  69. __THROW. */
  70. extern __pid_t wait (int *__stat_loc);
  71. #ifdef __USE_MISC
  72. /* Special values for the PID argument to `waitpid' and `wait4'. */
  73. # define WAIT_ANY (-1) /* Any process. */
  74. # define WAIT_MYPGRP 0 /* Any process in my process group. */
  75. #endif
  76. /* Wait for a child matching PID to die.
  77. If PID is greater than 0, match any process whose process ID is PID.
  78. If PID is (pid_t) -1, match any process.
  79. If PID is (pid_t) 0, match any process with the
  80. same process group as the current process.
  81. If PID is less than -1, match any process whose
  82. process group is the absolute value of PID.
  83. If the WNOHANG bit is set in OPTIONS, and that child
  84. is not already dead, return (pid_t) 0. If successful,
  85. return PID and store the dead child's status in STAT_LOC.
  86. Return (pid_t) -1 for errors. If the WUNTRACED bit is
  87. set in OPTIONS, return status for stopped children; otherwise don't.
  88. This function is a cancellation point and therefore not marked with
  89. __THROW. */
  90. extern __pid_t waitpid (__pid_t __pid, int *__stat_loc, int __options);
  91. #if defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K8
  92. # ifndef __id_t_defined
  93. typedef __id_t id_t;
  94. # define __id_t_defined
  95. # endif
  96. # include <bits/types/siginfo_t.h>
  97. /* Wait for a childing matching IDTYPE and ID to change the status and
  98. place appropriate information in *INFOP.
  99. If IDTYPE is P_PID, match any process whose process ID is ID.
  100. If IDTYPE is P_PGID, match any process whose process group is ID.
  101. If IDTYPE is P_ALL, match any process.
  102. If the WNOHANG bit is set in OPTIONS, and that child
  103. is not already dead, clear *INFOP and return 0. If successful, store
  104. exit code and status in *INFOP.
  105. This function is a cancellation point and therefore not marked with
  106. __THROW. */
  107. extern int waitid (idtype_t __idtype, __id_t __id, siginfo_t *__infop,
  108. int __options);
  109. #endif
  110. #if defined __USE_MISC \
  111. || (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K)
  112. /* This being here makes the prototypes valid whether or not
  113. we have already included <sys/resource.h> to define `struct rusage'. */
  114. struct rusage;
  115. /* Wait for a child to exit. When one does, put its status in *STAT_LOC and
  116. return its process ID. For errors return (pid_t) -1. If USAGE is not
  117. nil, store information about the child's resource usage there. If the
  118. WUNTRACED bit is set in OPTIONS, return status for stopped children;
  119. otherwise don't. */
  120. extern __pid_t wait3 (int *__stat_loc, int __options,
  121. struct rusage * __usage) __THROWNL;
  122. #endif
  123. #ifdef __USE_MISC
  124. /* PID is like waitpid. Other args are like wait3. */
  125. extern __pid_t wait4 (__pid_t __pid, int *__stat_loc, int __options,
  126. struct rusage *__usage) __THROWNL;
  127. #endif /* Use misc. */
  128. __END_DECLS
  129. #endif /* sys/wait.h */