console_codes.4: tfix
[man-pages.git] / man2 / wait4.2
blob53fb8f639962f0c8de6f5cdb82a390ff0041cde7
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/types.h>
39 .B #include <sys/time.h>
40 .B #include <sys/resource.h>
41 .B #include <sys/wait.h>
42 .PP
43 .BI "pid_t wait3(int *" "wstatus" ", int " options ", struct rusage *" rusage );
44 .BI "pid_t wait4(pid_t " pid ", int *" wstatus ", int " options ,
45 .BI "            struct rusage *" rusage );
46 .fi
47 .PP
48 .RS -4
49 Feature Test Macro Requirements for glibc (see
50 .BR feature_test_macros (7)):
51 .RE
52 .PP
53 .BR wait3 ():
54 .nf
55     Since glibc 2.26:
56         _DEFAULT_SOURCE
57             || (_XOPEN_SOURCE >= 500 &&
58                 ! (_POSIX_C_SOURCE >= 200112L
59                    || _XOPEN_SOURCE >= 600))
60     From glibc 2.19 to 2.25:
61         _DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
62     Glibc 2.19 and earlier:
63         _BSD_SOURCE || _XOPEN_SOURCE >= 500
64 .\"          || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
65 .fi
66 .PP
67 .BR wait4 ():
68 .nf
69     Since glibc 2.19:
70         _DEFAULT_SOURCE
71     Glibc 2.19 and earlier:
72         _BSD_SOURCE
73 .fi
74 .SH DESCRIPTION
75 These functions are nonstandard; in new programs, the use of
76 .BR waitpid (2)
78 .BR waitid (2)
79 is preferable.
80 .PP
81 The
82 .BR wait3 ()
83 and
84 .BR wait4 ()
85 system calls are similar to
86 .BR waitpid (2),
87 but additionally return resource usage information about the
88 child in the structure pointed to by
89 .IR rusage .
90 .PP
91 Other than the use of the
92 .I rusage
93 argument, the following
94 .BR wait3 ()
95 call:
96 .PP
97 .in +4n
98 .EX
99 wait3(wstatus, options, rusage);
103 is equivalent to:
105 .in +4n
107 waitpid(\-1, wstatus, options);
111 Similarly, the following
112 .BR wait4 ()
113 call:
115 .in +4n
117 wait4(pid, wstatus, options, rusage);
121 is equivalent to:
123 .in +4n
125 waitpid(pid, wstatus, options);
129 In other words,
130 .BR wait3 ()
131 waits of any child, while
132 .BR wait4 ()
133 can be used to select a specific child, or children, on which to wait.
135 .BR wait (2)
136 for further details.
139 .I rusage
140 is not NULL, the
141 .I struct rusage
142 to which it points will be filled with accounting information
143 about the child.
145 .BR getrusage (2)
146 for details.
147 .SH RETURN VALUE
148 As for
149 .BR waitpid (2).
150 .SH ERRORS
151 As for
152 .BR waitpid (2).
153 .SH CONFORMING TO
154 4.3BSD.
156 SUSv1 included a specification of
157 .BR wait3 ();
158 SUSv2 included
159 .BR wait3 (),
160 but marked it LEGACY;
161 SUSv3 removed it.
162 .SH NOTES
163 Including
164 .I <sys/time.h>
165 is not required these days, but increases portability.
166 (Indeed,
167 .I <sys/resource.h>
168 defines the
169 .I rusage
170 structure with fields of type
171 .I struct timeval
172 defined in
173 .IR <sys/time.h> .)
174 .SS C library/kernel differences
175 On Linux,
176 .BR wait3 ()
177 is a library function implemented on top of the
178 .BR wait4 ()
179 system call.
180 .SH SEE ALSO
181 .BR fork (2),
182 .BR getrusage (2),
183 .BR sigaction (2),
184 .BR signal (2),
185 .BR wait (2),
186 .BR signal (7)