Skip to main content

Module containment

Module containment 

Source
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 and PR_SET_PDEATHSIG(SIGKILL) via prctl() so the kernel kills the child when the parent thread exits. Caveat: PR_SET_PDEATHSIG is reset on execve of a set-uid/set-gid binary and is tied to the thread that called fork, 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_PDEATHSIG is not available; parent-death notification is best-effort via polling getppid() 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§

ContainedChild
A handle to a process spawned inside a ContainedProcessGroup.
ContainedProcessGroup
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.