Skip to main content

detach

Function detach 

Source
fn detach(command: &mut Command)
Expand description

Make command survive the parent and the terminal.

Unix: the child gets its own process group, which takes it out of the terminal’s foreground group. THAT is the isolation that matters: the tty delivers Ctrl+C (SIGINT) to the foreground group only, and a session-leader SIGHUP does not reach background groups. Redirecting stdin to null and stdout/stderr to files complements it — no terminal reads or writes (no SIGTTIN/SIGTTOU exposure), and the daemon’s output lands in the run logs. (Full setsid — leaving the session and dropping the controlling terminal — needs unsafe pre_exec; nothing here touches the tty, so there is nothing it would add.)

Windows: DETACHED_PROCESS (no console) and CREATE_NEW_PROCESS_GROUP (own Ctrl+C group). The flag values are inlined from the CreateProcess documentation so the windows crate is not a dependency for two integers.