Documentation
¶
Overview ¶
Package childproc spawns child processes that cannot outlive their parent.
exec.CommandContext alone is not enough for long-running, memory-hungry children. Its cancellation is a user-space watcher goroutine in the parent: if the parent dies abnormally — OOM-kill, SIGKILL, a closed stdout pipe — the watcher never runs and the child is orphaned, holding its working set until it finishes on its own. It also signals only the direct child, so any grandchildren the child spawned survive the kill.
The commands built here close both gaps:
- the child leads its own process group, and cancellation kills the whole group rather than the single process;
- on Linux the kernel is asked to SIGKILL the child when the parent dies (PR_SET_PDEATHSIG), which is the only mechanism that survives the parent being killed without warning.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandContext ¶
CommandContext returns an exec.Cmd for name/args that is hardened against orphaning, as described in the package documentation. The caller owns every other field, including Stdout, Stderr, Dir, Env and WaitDelay; nothing here changes how output is captured.
Cancellation runs before the standard kill, so ctx expiry terminates the whole process group.
func Run ¶
Run runs name with args as a hardened child, capturing stderr, and returns what the child wrote there alongside the exec error. A non-zero exit, a context deadline or a kill all produce a non-nil error.
Unlike CommandContext this also sets a WaitDelay, so a wedged pipe cannot keep the caller blocked after the child is gone.
Types ¶
This section is empty.