Skip to main content

spawn_supervised

Function spawn_supervised 

Source
pub fn spawn_supervised(cmd: Command) -> Result<u32>
Expand description

Spawns cmd as a detached child that the kernel terminates if this process dies, and returns its PID.

Every child is spawned on one dedicated thread. That is load-bearing, not tidiness: PR_SET_PDEATHSIG is delivered when the thread that forked exits, not when the process does. Forking from a tokio worker would tie a live agent’s lifetime to whichever worker happened to poll the spawn, and a worker exiting early would kill a healthy child. This thread is created once and never joined, so the signal fires only on real process death.

The child’s Child handle is dropped without waiting, so it is never reaped here — see is_zombie, which liveness probes must consult.

On non-Linux targets this is a plain spawn: there is no parent-death signal, so a supervisor that dies without draining leaves the child running.