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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms