wait4(2)
π wait4(2) β the BSD-style "wait for your child to change state" page π
okay bestie, pull up a chair, we're in the System Calls Manual and this one is a whole mood. it's wait3 and wait4, the BSD-style girlies. β¨
π NAME π
wait3, wait4 β wait for process to change state, BSD style
no cap, that's literally it. they wait, and they're BSD-flavored. π
π LIBRARY π
Standard C library (libc, -lc)
yes girl, that's the library. you already link it in basically everything. π«Ά
β¨ SYNOPSIS β¨
#include <sys/wait.h>
pid_t wait3(int *_Nullable wstatus, int options,
struct rusage *_Nullable rusage);
pid_t wait4(pid_t pid, int *_Nullable wstatus, int options,
struct rusage *_Nullable rusage);
π¦ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): π¦
listen, this part is giving "bureaucracy" but it's important, so here it is in all its glory:
wait3():
Since glibc 2.26:
_DEFAULT_SOURCE
|| (_XOPEN_SOURCE >= 500 &&
! (_POSIX_C_SOURCE >= 200112L
|| _XOPEN_SOURCE >= 600))
From glibc 2.19 to glibc 2.25:
_DEFAULT_SOURCE || _XOPEN_SOURCE >= 500
glibc 2.19 and earlier:
_BSD_SOURCE || _XOPEN_SOURCE >= 500
wait4():
Since glibc 2.19:
_DEFAULT_SOURCE
glibc 2.19 and earlier:
_BSD_SOURCE
if you forget these, the compiler will be like "who?" and you'll be sad. π
πΈ DESCRIPTION πΈ
first things first, and I need you to hear me on this: these functions are nonstandard. in new programs, using waitpid(2) or waitid(2) is preferable. like, it's not a scandal, they're just old money and we have better options now. π
so what do they even do? the wait3() and wait4() system calls are similar to waitpid(2), BUT β and this is their little extra sparkle β they additionally return resource usage information about the child in the structure pointed to by rusage. it's giving "waiting, but make it informative". π
other than the rusage argument being a whole extra thing, this wait3() call:
wait3(wstatus, options, rusage);
is equivalent to:
waitpid(-1, wstatus, options);
and similarly, this wait4() call:
wait4(pid, wstatus, options, rusage);
is equivalent to:
waitpid(pid, wstatus, options);
in other words (and this is the vibe check you needed):
wait3()waits for any child πwait4()can be used to select a specific child, or children, on which to wait
see wait(2) for further details, bestie, that's where the deep lore lives. π
and if rusage is not NULL, the struct rusage it points to will be filled with accounting information about the child. again: see getrusage(2) for details. it's all connected, iykyk. β¨
π₯ RETURN VALUE π₯
As for waitpid(2).
(that's the whole section. short king. respect.) π
π ERRORS π
As for waitpid(2).
(same energy. we don't reproduce them here, we send you to the source.) π
π STANDARDS π
None.
literally none. zero. it's a lone wolf. not standard anywhere. periodt. π
β HISTORY β
4.3BSD.
the timeline, because we love a documented glow-up:
- SUSv1 included a specification of
wait3() - SUSv2 included
wait3(), but marked it LEGACY (oof, the shade π) - SUSv3 removed it
also, tea time: including <sys/time.h> is not required these days, but it increases portability. (indeed β and this is the receipts, bestie β <sys/resource.h> defines the rusage structure with fields of type struct timeval defined in <sys/time.h>.) so it's optional but it's kind of a considerate move. π
π§ C library/kernel differences π§
on Linux, wait3() is a library function implemented on top of the wait4() system call. so yes, wait3 is basically wait4's little sibling borrowing her outfit. iconic behavior fr fr. π
π SEE ALSO π
fork(2), getrusage(2), sigaction(2), signal(2), wait(2), signal(7)
go read these too, they're the group chat and this page is just one message in it. π¦
and that's the whole page, bestie!! this one shipped from Linux man-pages 6.20, dated 2026-02-08. now go reap your zombies before they start texting you passive-aggressively. mwah. π β¨ππ«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- Copyright 2004, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms