Skip to main content

kill_process_tree

Function kill_process_tree 

Source
fn kill_process_tree(pid: u32)
Expand description

Kill pid AND every descendant it spawned, not just the one process. Supplements ChildKiller::kill() (portable-pty’s Windows impl is a bare TerminateProcess on a single handle, no job object — see the caller’s comment) — without this, a wrapped command whose direct child forks further (a pipeline, or git spawning less as a child) can leave an orphaned grandchild running and still attached to the PTY slave after the “kill” (reagent P1, PR #2156).

agentmux_common::process::force_kill_tree does the killing, by PID only:

Windows: taskkill /F /T /PID <pid> (console flash suppressed) walks the OS-level parent-PID tree, independent of shell job control, and force-kills every process in it.

Unix: SIGKILL to the child’s process group. portable-pty makes the PTY child a session and group leader (setsid), so its pgid is its pid and the group holds the command, its pipeline and what it backgrounded with &. portable-pty’s own ChildKiller only SIGHUPs the one pid, which a nohup’d child ignores. A child that started its own session is out of reach here; the agent’s process tracker ends it with the agent.