PR_SET_CHILD_SUBREAPER(2const)

πŸ’– PR_SET_CHILD_SUBREAPER β€” the prctl(2const) page, bestie edition πŸ’–

okay so you found PR_SET_CHILD_SUBREAPER(2const) and honestly? iconic of you. this lives in the prctl corner of the Linux manual, and it's all about making your process the certified mom friend of its whole little process family tree. let's get into it. 🫢


✨ LIBRARY ✨

Standard C library (libc, -lc) β€” the usual, nothing spicy here. πŸ’…


🌸 SYNOPSIS 🌸

#include <linux/prctl.h>  /* Definition of PR_* constants */
#include <sys/prctl.h>

int prctl(PR_SET_CHILD_SUBREAPER, long set);

πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea. if set is nonzero, you're setting the "child subreaper" attribute on the calling process. if set is zero, you're unsetting it. that's the whole toggle. simple, clean, slay. ✨

now what even is a subreaper, you ask? a subreaper literally fulfills the role of init(1) for its descendant processes. like, it's stepping into the main character role. πŸ‘‘

here's how it goes down: when a process becomes orphaned (meaning its immediate parent terminates β€” sad, tragic, we've all been there 😭), that process gets reparented to the nearest still living ancestor subreaper.

and then? every subsequent call to getppid(2) inside that orphaned process will now return the PID of the subreaper process. not the original parent, bestie. the subreaper. and when the orphan finally terminates, it's the subreaper process that receives the SIGCHLD signal πŸ”” and gets to call wait(2) on the process to discover its termination status. so the subreaper always knows what happened. no cap.

important detail tho: the setting of the "child subreaper" attribute is not inherited by children created by fork(2) and clone(2). the vibes do not pass down, fr fr. but the setting is preserved across execve(2). so it survives the transformation. πŸ’«

why would you even want this? establishing a subreaper process is useful in session management frameworks, where a hierarchical group of processes is managed by a subreaper process that needs to be informed when one of the processesβ€” for example, a double-forked daemon β€” terminates (perhaps so that it can restart that process). and some init(1) frameworks (e.g., systemd(1)) employ a subreaper process for similar reasons. so yes, this is real production energy, not just a cute experiment. πŸ”₯


πŸ’œ RETURN VALUE πŸ’œ

  • on success, 0 is returned. πŸŽ‰
  • on error, -1 is returned, and errno is set to indicate the error. πŸ™ˆ

🌈 STANDARDS 🌈

Linux. that's it. that's the standard. 🐧


⭐ HISTORY ⭐

Linux 3.4. vintage-ish, but still eating. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


and that's the whole page, bestie!! this came from Linux man-pages 6.20, dated 2026-02-08 β€” so when you cite your sources, you cite them correctly, periodt. πŸ’–βœ¨ go forth and subreap responsibly πŸŽ€

πŸ“¦ 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