PR_SET_PTRACER(2const)

πŸ’– PR_SET_PTRACER πŸ’–

okay bestie so this one lives in the prctl(2) family of constants, and it's the one that lets you be like "hey, this process? yeah, they're allowed to trace me." it's giving chosen family energy fr fr. ✨

πŸ“š LIBRARY

Standard C library (libc, -lc) πŸŽ€


✨ SYNOPSIS ✨

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

int prctl(PR_SET_PTRACER, long pid);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the thing: this call is only meaningful when the Yama LSM is enabled and sitting in mode 1, aka "restricted ptrace", which you can peek at via /proc/sys/kernel/yama/ptrace_scope. no Yama, no drama, no effect β€” periodt.

when you hand it a "ptracer process ID" in pid, what you're actually doing is declaring that the ptracer process gets to ptrace(2) the calling process as if it were a direct process ancestor. like, "yes officer, they're with me." 🫢

each and every PR_SET_PTRACER operation replaces the previous "ptracer process ID". there's no little list, girlie, it's one slot and you keep overwriting it. πŸ’…

and the two special cases, because of course there are two special cases:

  • call it with pid set to 0 β†’ that clears the caller's "ptracer process ID". bye boo πŸ‘‹
  • call it with pid set to PR_SET_PTRACER_ANY β†’ the ptrace restrictions that Yama introduced are effectively disabled for the calling process. yes literally all of them. no cap. that's a big vibe, handle with care, bestie 😭

πŸ’« RETURN VALUE πŸ’«

slay = 0 on success πŸŽ€

not slay = -1 on error, and errno gets set to tell you what went wrong. πŸ’€


🚨 ERRORS 🚨

  • EINVAL β€” pid is not 0, not PR_SET_PTRACER_ANY, and nor the PID of an existing process. so basically you pointed at a ghost. it said no. πŸ™ˆ

πŸ‘‘ STANDARDS πŸ‘‘

Linux. that's it, that's the whole row. πŸ’œ


🌈 HISTORY 🌈

Linux 3.4. an elder. iconic. 🌸


πŸŽ€ SEE ALSO πŸŽ€

and for the deep lore, the actual kernel source file: Documentation/admin-guide/LSM/Yama.rst β€” iykyk πŸ“–βœ¨


okay that's the whole page, bestie, you ate it up πŸ“ this was PR_SET_PTRACER(2const), brought to you by Linux man-pages 6.20, dated 2026-02-08. go forth and ptrace responsibly, ily bye πŸ’–πŸ§š

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