Skip to main content

speccoder_runtime/
session.rs

1//! Ending a started command and everything it started. Through the sandbox
2//! helper the command leads a session of its own (procage's
3//! `exec_session`): what it starts may form process groups (test runners)
4//! but never leave the session. A plain command leads a process group.
5
6/// Ends every process of the session `pid` leads, then its process group.
7/// Called before reaping `pid` or soon after: while any member lives the id
8/// is no other session's, and once none does there is nothing to end (pids
9/// are handed out in sequence, so another session with it is far off).
10pub fn end(pid: u32) {
11    #[cfg(any(target_os = "macos", target_os = "linux"))]
12    procage::native::end_session(pid);
13    #[cfg(not(any(target_os = "macos", target_os = "linux")))]
14    if let Ok(pid) = i32::try_from(pid) {
15        let _ = nix::sys::signal::killpg(
16            nix::unistd::Pid::from_raw(pid),
17            nix::sys::signal::Signal::SIGKILL,
18        );
19    }
20}