Debian Codegraph @

upstream/debian-unstable/man2/wait4.2

raw
1 .\" Copyright 1993, Thomas Koenig <[email protected]>
2 .\" Copyright 2004, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH wait4 2 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 wait3, wait4 \- wait for process to change state, BSD style
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <sys/wait.h>
16 .P
17 .BI "pid_t wait3(int *_Nullable " "wstatus" ", int " options ,
18 .BI " struct rusage *_Nullable " rusage );
19 .BI "pid_t wait4(pid_t " pid ", int *_Nullable " wstatus ", int " options ,
20 .BI " struct rusage *_Nullable " rusage );
21 .fi
22 .P
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .P
28 .BR wait3 ():
29 .nf
30 Since glibc 2.26:
31 _DEFAULT_SOURCE
32 || (_XOPEN_SOURCE >= 500 &&
33 ! (_POSIX_C_SOURCE >= 200112L
34 || _XOPEN_SOURCE >= 600))
35 From glibc 2.19 to glibc 2.25:
36 _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
37 glibc 2.19 and earlier:
38 _BSD_SOURCE || _XOPEN_SOURCE >= 500
39 .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
40 .fi
41 .P
42 .BR wait4 ():
43 .nf
44 Since glibc 2.19:
45 _DEFAULT_SOURCE
46 glibc 2.19 and earlier:
47 _BSD_SOURCE
48 .fi
49 .SH DESCRIPTION
50 These functions are nonstandard;
51 in new programs,
52 the use of
53 .BR waitpid (2)
54 or
55 .BR waitid (2)
56 is preferable.
57 .P
58 The
59 .BR wait3 ()
60 and
61 .BR wait4 ()
62 system calls are similar to
63 .BR waitpid (2),
64 but additionally return resource usage information about the
65 child in the structure pointed to by
66 .IR rusage .
67 .P
68 Other than the use of the
69 .I rusage
70 argument, the following
71 .BR wait3 ()
72 call:
73 .P
74 .in +4n
75 .EX
76 wait3(wstatus, options, rusage);
77 .EE
78 .in
79 .P
80 is equivalent to:
81 .P
82 .in +4n
83 .EX
84 waitpid(\-1, wstatus, options);
85 .EE
86 .in
87 .P
88 Similarly, the following
89 .BR wait4 ()
90 call:
91 .P
92 .in +4n
93 .EX
94 wait4(pid, wstatus, options, rusage);
95 .EE
96 .in
97 .P
98 is equivalent to:
99 .P
100 .in +4n
101 .EX
102 waitpid(pid, wstatus, options);
103 .EE
104 .in
105 .P
106 In other words,
107 .BR wait3 ()
108 waits of any child, while
109 .BR wait4 ()
110 can be used to select a specific child, or children, on which to wait.
111 See
112 .BR wait (2)
113 for further details.
114 .P
115 If
116 .I rusage
117 is not NULL, the
118 .I struct rusage
119 to which it points will be filled with accounting information
120 about the child.
121 See
122 .BR getrusage (2)
123 for details.
124 .SH RETURN VALUE
125 As for
126 .BR waitpid (2).
127 .SH ERRORS
128 As for
129 .BR waitpid (2).
130 .SH STANDARDS
131 None.
132 .SH HISTORY
133 4.3BSD.
134 .P
135 SUSv1 included a specification of
136 .BR wait3 ();
137 SUSv2 included
138 .BR wait3 (),
139 but marked it LEGACY;
140 SUSv3 removed it.
141 .P
142 Including
143 .I <sys/time.h>
144 is not required these days, but increases portability.
145 (Indeed,
146 .I <sys/resource.h>
147 defines the
148 .I rusage
149 structure with fields of type
150 .I struct timeval
151 defined in
152 .IR <sys/time.h> .)
153 .SS C library/kernel differences
154 On Linux,
155 .BR wait3 ()
156 is a library function implemented on top of the
157 .BR wait4 ()
158 system call.
159 .SH SEE ALSO
160 .BR fork (2),
161 .BR getrusage (2),
162 .BR sigaction (2),
163 .BR signal (2),
164 .BR wait (2),
165 .BR signal (7)