github.com/alexfalkowski/go-linux/v2/process adds Linux orphan adoption and wait-any reaping for a dedicated worker supervisor or PID namespace init.
Call process.EnableChildSubreaper() before starting the worker tree. When a parent exits, Linux reparents its children to the closest living subreaper ancestor in their PID namespace, or to that namespace’s init process. All threads observe the same flag. process.IsChildSubreaper() reports the flag, which survives exec and starts clear in newly created child processes. process.DisableChildSubreaper() clears it for future adoptions. Children already adopted stay with the supervisor. PID namespace init already adopts orphans when the flag is clear. Linux 7.0 reparenting implementation.
Use process.Wait() to block until one eligible child has exited and consume its status. process.TryWait() collects one exited child without blocking. If eligible children are still alive and none has exited, TryWait returns Exit{}, false, and nil. If there are no eligible children, either call returns an error matching syscall.ECHILD. Kernel errors such as EINTR remain available through errors.Is. Both calls report normal exit codes or signal termination (Code == -1 and a terminating Signal). CoreDump records the kernel’s CLD_DUMPED status. The returned PID is in the caller’s namespace and may be reused immediately after reaping.
Designate one reaper for every eligible child. Either wait-any call can consume a direct child’s status. If an intermediate launcher uses exec.Cmd, complete Cmd.Wait and its pipe cleanup before starting the wait-any loop. A child started through os.StartProcess can have wait-any as its only reaper. Release that child’s os.Process after collection. Use pidfd for stable identity, signaling, or observing an identified child’s exit with WaitReady. Stop and continue events, resource-usage accounting, and nonstandard clone exit signals are outside the package’s scope. See the executable supervisor example.
Keep ptrace supervision in a separate process. Linux can consume a ptrace stop during wait-any even with exit-only selection. Both wait-any calls return an error matching errors.ErrUnsupported if Linux delivers a nonterminal status. Linux 7.0 wait implementation.
Use os/signal.Notify in PID 1 to receive catchable signals such as SIGTERM from the parent namespace. The application chooses which identified workers to signal through their pidfds. If the supervisor uses SIGCHLD as a wakeup, call TryWait until ready is false or ECHILD indicates that the wait set is empty. One signal can represent multiple exits. Blocking Wait has no context or deadline and may occupy an OS thread. See the PID 1 integration scenario and namespace runner requirements.