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
pidset to0β that clears the caller's "ptracer process ID". bye boo π - call it with
pidset toPR_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βpidis not0, notPR_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
- Copyright 2013-2015, 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