__ptrace_unlink(9)
β¨ __ptrace_unlink(9) β the kernel API manual glow-up β¨
okay so you're reading the <pink>__ptrace_unlink</pink> page from the Kernel API Manual, and honestly? it's lowkey a banger. it's all about gently letting a traced task go and making sure its execution state is not a whole mess afterwards. let's get into it π«Ά
πΈ NAME πΈ
__ptrace_unlink β unlink ptracee and restore its execution state
like, unlink your traced buddy and put its vibes (execution state) back where they belong π
β¨ SYNOPSIS β¨
void __ptrace_unlink (struct task_struct *child );
π ARGUMENTS π
childβ the ptracee to be unlinked. that's the one getting set free, bestie π¦
π DESCRIPTION π
So here's the tea: this function removes child from the ptrace list, moves it back to the original parent, and restores the execution state so that it conforms to the group stop state. three little steps, all iconic π
Unlinking can happen via two paths β explicit PTRACE_DETACH or ptracer exiting. and ngl these two are not the same vibe:
- for
PTRACE_DETACH, unless the ptracee has been killed betweenptrace_check_attachand here, it's guaranteed to be inTASK_TRACED. - if the ptracer is exiting, the ptracee can be in any state. literally any. main character chaos π
After detach, the ptracee should be in a state which conforms to the group stop. so:
- if the group is stopped or in the process of stopping, the ptracee should be put into
TASK_STOPPED; - otherwise, it should be woken up from
TASK_TRACED.
And now for the part where you gotta pay attention π₯ If the ptracee is in TASK_TRACED and needs to be moved to TASK_STOPPED, it goes through the TRACED -> RUNNING -> STOPPED transition, which is similar to but in the opposite direction of what happens while attaching to a stopped task. cute symmetry, right?
but in this direction, the intermediateRUNNINGstate is not hidden even from the current ptracer β and if it immediately re-attaches and performs aWNOHANGwait(2), it may fail. not me warning you twice π
π CONTEXT π
write_lock_irq(tasklist_lock)
that's the lock situation, no cap. don't forget it π§
π SEE ALSO π
- Kernel file
./kernel/ptrace.c ptracer_access_allowed(9)ptrace_check_attach(9)ptrace_traceme(9)
go read those next, iykyk πβ¨
<div>π okay that's the whole page, you ate that π</div>
this absolute classic lives in ./kernel, and this particular edition is dated October 2026 β and yes, __ptrace_unlink(9) is still the title, we're just saying it with love at the end. bye bestie, slay your kernel debugging ππΈπ«Ά
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms