Blame man2/wait4.2

Packit 7cfc04
.\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
Packit 7cfc04
.\" and Copyright (c) 2004 by Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified Sat Jul 24 13:32:44 1993 by Rik Faith (faith@cs.unc.edu)
Packit 7cfc04
.\" Modified Mon Jun 23 14:09:52 1997 by aeb - add EINTR.
Packit 7cfc04
.\" Modified Tue Jul  7 12:26:42 1998 by aeb - changed return value wait3
Packit 7cfc04
.\" Modified 2004-11-11, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"	Rewrote much of this page, and removed much duplicated text,
Packit 7cfc04
.\"		replacing with pointers to wait.2
Packit 7cfc04
.\"
Packit 7cfc04
.TH WAIT4 2  2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
wait3, wait4 \- wait for process to change state, BSD style
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.B #include <sys/time.h>
Packit 7cfc04
.B #include <sys/resource.h>
Packit 7cfc04
.B #include <sys/wait.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "pid_t wait3(int *" "wstatus" ", int " options ,
Packit 7cfc04
.BI "            struct rusage *" rusage );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "pid_t wait4(pid_t " pid ", int *" wstatus ", int " options ,
Packit 7cfc04
.BI "            struct rusage *" rusage );
Packit 7cfc04
.fi
Packit 7cfc04
.PP
Packit 7cfc04
.in -4n
Packit 7cfc04
Feature Test Macro Requirements for glibc (see
Packit 7cfc04
.BR feature_test_macros (7)):
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
.ad l
Packit 7cfc04
.BR wait3 ():
Packit 7cfc04
    Since glibc 2.19:
Packit 7cfc04
        _DEFAULT_SOURCE || _XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
    Glibc 2.19 and earlier:
Packit 7cfc04
        _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
Packit 7cfc04
.\"          || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
Packit 7cfc04
.br
Packit 7cfc04
.BR wait4 ():
Packit 7cfc04
    Since glibc 2.19:
Packit 7cfc04
        _DEFAULT_SOURCE
Packit 7cfc04
    Glibc 2.19 and earlier:
Packit 7cfc04
        _BSD_SOURCE
Packit 7cfc04
.ad
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
These functions are obsolete; use
Packit 7cfc04
.BR waitpid (2)
Packit 7cfc04
or
Packit 7cfc04
.BR waitid (2)
Packit 7cfc04
in new programs.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR wait3 ()
Packit 7cfc04
and
Packit 7cfc04
.BR wait4 ()
Packit 7cfc04
system calls are similar to
Packit 7cfc04
.BR waitpid (2),
Packit 7cfc04
but additionally return resource usage information about the
Packit 7cfc04
child in the structure pointed to by
Packit 7cfc04
.IR rusage .
Packit 7cfc04
.PP
Packit 7cfc04
Other than the use of the
Packit 7cfc04
.I rusage
Packit 7cfc04
argument, the following
Packit 7cfc04
.BR wait3 ()
Packit 7cfc04
call:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
wait3(wstatus, options, rusage);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
is equivalent to:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
waitpid(\-1, wstatus, options);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Similarly, the following
Packit 7cfc04
.BR wait4 ()
Packit 7cfc04
call:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
wait4(pid, wstatus, options, rusage);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
is equivalent to:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
waitpid(pid, wstatus, options);
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
In other words,
Packit 7cfc04
.BR wait3 ()
Packit 7cfc04
waits of any child, while
Packit 7cfc04
.BR wait4 ()
Packit 7cfc04
can be used to select a specific child, or children, on which to wait.
Packit 7cfc04
See
Packit 7cfc04
.BR wait (2)
Packit 7cfc04
for further details.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.I rusage
Packit 7cfc04
is not NULL, the
Packit 7cfc04
.I struct rusage
Packit 7cfc04
to which it points will be filled with accounting information
Packit 7cfc04
about the child.
Packit 7cfc04
See
Packit 7cfc04
.BR getrusage (2)
Packit 7cfc04
for details.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
As for
Packit 7cfc04
.BR waitpid (2).
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
As for
Packit 7cfc04
.BR waitpid (2).
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
4.3BSD.
Packit 7cfc04
.PP
Packit 7cfc04
SUSv1 included a specification of
Packit 7cfc04
.BR wait3 ();
Packit 7cfc04
SUSv2 included
Packit 7cfc04
.BR wait3 (),
Packit 7cfc04
but marked it LEGACY;
Packit 7cfc04
SUSv3 removed it.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
Including
Packit 7cfc04
.I <sys/time.h>
Packit 7cfc04
is not required these days, but increases portability.
Packit 7cfc04
(Indeed,
Packit 7cfc04
.I <sys/resource.h>
Packit 7cfc04
defines the
Packit 7cfc04
.I rusage
Packit 7cfc04
structure with fields of type
Packit 7cfc04
.I struct timeval
Packit 7cfc04
defined in
Packit 7cfc04
.IR <sys/time.h> .)
Packit 7cfc04
.SS C library/kernel differences
Packit 7cfc04
On Linux,
Packit 7cfc04
.BR wait3 ()
Packit 7cfc04
is a library function implemented on top of the
Packit 7cfc04
.BR wait4 ()
Packit 7cfc04
system call.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR fork (2),
Packit 7cfc04
.BR getrusage (2),
Packit 7cfc04
.BR sigaction (2),
Packit 7cfc04
.BR signal (2),
Packit 7cfc04
.BR wait (2),
Packit 7cfc04
.BR signal (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.