Start of man-pages-5.14: renaming .Announce and .lsm files
[man-pages.git] / man2 / wait4.2
blob3bd60367e29de36f1c86f74bee6c4d1bdd8340e5
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\" and Copyright (c) 2004 by Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified Sat Jul 24 13:32:44 1993 by Rik Faith (faith@cs.unc.edu)
27 .\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR.
28 .\" Modified Tue Jul  7 12:26:42 1998 by aeb - changed return value wait3
29 .\" Modified 2004-11-11, Michael Kerrisk <mtk.manpages@gmail.com>
30 .\"     Rewrote much of this page, and removed much duplicated text,
31 .\"             replacing with pointers to wait.2
32 .\"
33 .TH WAIT4 2  2021-03-22 "Linux" "Linux Programmer's Manual"
34 .SH NAME
35 wait3, wait4 \- wait for process to change state, BSD style
36 .SH SYNOPSIS
37 .nf
38 .B #include <sys/wait.h>
39 .PP
40 .BI "pid_t wait3(int *" "wstatus" ", int " options ", struct rusage *" rusage );
41 .BI "pid_t wait4(pid_t " pid ", int *" wstatus ", int " options ,
42 .BI "            struct rusage *" rusage );
43 .fi
44 .PP
45 .RS -4
46 Feature Test Macro Requirements for glibc (see
47 .BR feature_test_macros (7)):
48 .RE
49 .PP
50 .BR wait3 ():
51 .nf
52     Since glibc 2.26:
53         _DEFAULT_SOURCE
54             || (_XOPEN_SOURCE >= 500 &&
55                 ! (_POSIX_C_SOURCE >= 200112L
56                    || _XOPEN_SOURCE >= 600))
57     From glibc 2.19 to 2.25:
58         _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
59     Glibc 2.19 and earlier:
60         _BSD_SOURCE || _XOPEN_SOURCE >= 500
61 .\"          || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
62 .fi
63 .PP
64 .BR wait4 ():
65 .nf
66     Since glibc 2.19:
67         _DEFAULT_SOURCE
68     Glibc 2.19 and earlier:
69         _BSD_SOURCE
70 .fi
71 .SH DESCRIPTION
72 These functions are nonstandard; in new programs, the use of
73 .BR waitpid (2)
75 .BR waitid (2)
76 is preferable.
77 .PP
78 The
79 .BR wait3 ()
80 and
81 .BR wait4 ()
82 system calls are similar to
83 .BR waitpid (2),
84 but additionally return resource usage information about the
85 child in the structure pointed to by
86 .IR rusage .
87 .PP
88 Other than the use of the
89 .I rusage
90 argument, the following
91 .BR wait3 ()
92 call:
93 .PP
94 .in +4n
95 .EX
96 wait3(wstatus, options, rusage);
97 .EE
98 .in
99 .PP
100 is equivalent to:
102 .in +4n
104 waitpid(\-1, wstatus, options);
108 Similarly, the following
109 .BR wait4 ()
110 call:
112 .in +4n
114 wait4(pid, wstatus, options, rusage);
118 is equivalent to:
120 .in +4n
122 waitpid(pid, wstatus, options);
126 In other words,
127 .BR wait3 ()
128 waits of any child, while
129 .BR wait4 ()
130 can be used to select a specific child, or children, on which to wait.
132 .BR wait (2)
133 for further details.
136 .I rusage
137 is not NULL, the
138 .I struct rusage
139 to which it points will be filled with accounting information
140 about the child.
142 .BR getrusage (2)
143 for details.
144 .SH RETURN VALUE
145 As for
146 .BR waitpid (2).
147 .SH ERRORS
148 As for
149 .BR waitpid (2).
150 .SH CONFORMING TO
151 4.3BSD.
153 SUSv1 included a specification of
154 .BR wait3 ();
155 SUSv2 included
156 .BR wait3 (),
157 but marked it LEGACY;
158 SUSv3 removed it.
159 .SH NOTES
160 Including
161 .I <sys/time.h>
162 is not required these days, but increases portability.
163 (Indeed,
164 .I <sys/resource.h>
165 defines the
166 .I rusage
167 structure with fields of type
168 .I struct timeval
169 defined in
170 .IR <sys/time.h> .)
171 .SS C library/kernel differences
172 On Linux,
173 .BR wait3 ()
174 is a library function implemented on top of the
175 .BR wait4 ()
176 system call.
177 .SH SEE ALSO
178 .BR fork (2),
179 .BR getrusage (2),
180 .BR sigaction (2),
181 .BR signal (2),
182 .BR wait (2),
183 .BR signal (7)