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