1
0

wait.h 6.6 KB

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