go-linux

process design decisions

Part of the accepted-design index. See the usage guide for calling contracts.

Keep reaping ownership with the supervisor

Subreaper state belongs to the Linux process. A scoped callback would imply exclusive control and restoration, yet another thread can change the flag and clearing it leaves previously adopted children in place. Explicit inspection, enable, and disable operations reflect those lifetimes. Namespace PID 1 already adopts orphans through the kernel’s fallback. Linux 7.0 prctl implementation, reparenting implementation.

The process and pidfd packages both consume a child status through waitid(WEXITED) and share an internal SIGCHLD decoder. process selects any eligible child and returns its numeric PID. pidfd keeps stable identity outside the wait and retains its existing result type. Each package depends on the decoder, with no dependency on the other’s API. WNOHANG preserves the distinction between no child ready and ECHILD. Linux 7.0 wait selectors.

Use the existing x/sys Linux constants and bindings. The subreaper query writes through a pointer in the second argument, so it uses Go’s pointer-aware syscall entry point. The setter and wait operations use the maintained x/sys wrappers.

Linux wait-any cannot select only children adopted after reparenting. A dedicated supervisor owns the eligible wait set, uses standard Go startup and signal handling, and coordinates any separately reaped startup children before invoking wait-any. Wait can block an OS thread and reports interruptions the kernel returns. TryWait lets an application drain exits in its own signal loop. Signal forwarding, restart, and shutdown policy stay at the call site.

Linux can deliver a ptrace stop with WEXITED. Rejecting nonterminal records keeps a stopped task from being reported as reaped. Tracing needs a separate process because wait-any can consume the tracing notification. Linux 7.0 wait implementation.