Skip to main content

Module pidfd

Module pidfd 

Source
Expand description

Process file descriptors (Linux pidfd) for race-free child kill.

kill(pid, sig) sends a signal to whatever process currently has that PID. After the kernel reaps the original child, the PID may be reused by an unrelated process — so a delayed kill() from our cancel/timeout path can signal the wrong target. Linux 5.3+ provides pidfd_open to obtain a generation-bound handle and pidfd_send_signal to deliver signals to it, eliminating the race for the direct child.

Process-group kills (killpg) have no pidfd-equivalent; grandchildren still go through PID-based delivery and retain the (small) reuse window.

On non-Linux unix targets, KillTarget degrades gracefully to PID-based kill() so the call sites stay portable.

Structs§

KillTarget
A bundle of identifiers for killing a child process.