Skip to main content

Module process_group

Module process_group 

Source
Expand description

Process-group helpers for reliable child process cleanup.

This module centralizes OS-specific pieces that ensure a spawned command can be cleaned up reliably:

  • set_process_group is called in pre_exec so the child starts its own process group.
  • detach_from_tty starts a new session so non-interactive children do not inherit the controlling TTY.
  • kill_process_group_by_pid targets the whole group (children/grandchildren) instead of a single PID.
  • kill_process_group targets a known process group ID directly.
  • set_parent_death_signal (Linux only) arranges for the child to receive a SIGTERM when the parent exits, and re-checks the parent PID to avoid races during fork/exec.
  • graceful_kill_process_group sends SIGTERM, waits for a grace period, then SIGKILL if still running.

On non-Unix platforms these helpers are no-ops or adapted equivalents.

Inspired by codex-rs/utils/pty process group management patterns.

Enums§

GracefulTerminationResult
Result of a graceful termination attempt.
KillSignal
Signal to send when killing process groups.

Constants§

DEFAULT_GRACEFUL_TIMEOUT_MS
Default grace period for graceful termination (milliseconds).

Functions§

detach_from_tty
Detach from the controlling TTY by starting a new session.
graceful_kill_process_group
Gracefully terminate a process group by PID.
graceful_kill_process_group_default
Gracefully terminate a process group with default settings.
kill_child_process_group
Kill the process group for a tokio child (best-effort).
kill_child_process_group_with_signal
Kill the process group for a tokio child with a specific signal.
kill_process
No-op on non-Windows platforms.
kill_process_group
Kill a specific process group ID (best-effort).
kill_process_group_by_pid
Kill the process group for the given PID (best-effort).
kill_process_group_by_pid_with_signal
Kill the process group for the given PID with a specific signal.
kill_process_group_with_signal
Kill a specific process group ID with a specific signal.
set_parent_death_signal
No-op on non-Linux platforms.
set_process_group
Put the calling process into its own process group.