Expand description
Process containment via OS-level mechanisms.
ContainedProcessGroup ensures all child processes die when the group is
dropped — even on a crash.
- Windows: Uses a Job Object with
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE. Dropping the group closes the handle, and Windows automatically terminates every process still assigned to the job. - Linux: Uses
setpgid(0, 0)to place children in a new process group andPR_SET_PDEATHSIG(SIGKILL)viaprctl()so the kernel kills the child when the parent thread exits. Caveat:PR_SET_PDEATHSIGis reset onexecveof a set-uid/set-gid binary and is tied to the thread that calledfork, not the process leader. If the spawning thread exits before the parent process, children receive the signal prematurely. - macOS: Uses
setpgid(0, 0)for process grouping.PR_SET_PDEATHSIGis not available; parent-death notification is best-effort via pollinggetppid()in the child (not implemented here — the Drop-based SIGKILL to the process group is the primary mechanism).
Containment::Detached spawns a process that intentionally survives the
group’s lifetime (daemon pattern).
§RUNNING_PROCESS_ORIGINATOR environment variable
When an originator is set on a ContainedProcessGroup, all spawned child
processes inherit the environment variable RUNNING_PROCESS_ORIGINATOR with
the format TOOL:PID, where:
- TOOL is the originator name (e.g.,
"CLUD","JUPYTER") - PID is the process ID of the parent that spawned the group
Example value: RUNNING_PROCESS_ORIGINATOR=CLUD:12345
§Purpose
This env var enables cross-process session discovery after crashes.
§Example
use running_process_core::ContainedProcessGroup;
let group = ContainedProcessGroup::with_originator("CLUD").unwrap();
let mut cmd = std::process::Command::new("sleep");
cmd.arg("60");
let child = group.spawn(&mut cmd).unwrap();Structs§
- Contained
Child - A handle to a process spawned inside a
ContainedProcessGroup. - Contained
Process Group - A group of processes that are killed together when the group is dropped.
Enums§
- Containment
- Containment policy for a spawned process.
Constants§
- ORIGINATOR_
ENV_ VAR - The environment variable name injected into child processes for cross-process session discovery.