Skip to main content

Crate ur_taking_me_with_you

Crate ur_taking_me_with_you 

Source
Expand description

Ensure child processes die when their parent dies.

Child processes normally continue running even after their parent exits (on Unix they get reparented to init/PID 1). This crate provides mechanisms to ensure child processes are terminated when their parent dies, even if the parent is killed with SIGKILL.

§Platform Support

  • Linux: Uses prctl(PR_SET_PDEATHSIG, SIGKILL) - the child receives SIGKILL when its parent thread dies
  • macOS: Uses a pipe-based approach - the child monitors a pipe from the parent and exits when the pipe closes (indicating parent death)
  • Windows: Uses job objects with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE - all processes in the job are terminated when the last handle closes

§Usage

§For the child process (call early in main):

ur_taking_me_with_you::die_with_parent();

§For spawning children with std::process::Command:

use std::process::Command;

let mut cmd = Command::new("my-plugin");
cmd.arg("--foo");

let child = ur_taking_me_with_you::spawn_dying_with_parent(cmd)
    .expect("failed to spawn");

Functions§

die_with_parent
Configure the current process to die when its parent dies.
spawn_dying_with_parent
Spawn a child process that will die when this (parent) process dies.