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
No-op on non-Unix platforms.
graceful_kill_process_group
Graceful termination on non-Unix (best effort).
graceful_kill_process_group_default
Graceful termination with defaults on non-Unix.
kill_child_process_group
No-op on non-Unix platforms.
kill_child_process_group_with_signal
No-op on non-Unix platforms.
kill_process
Kill a process by PID on Windows.
kill_process_group
No-op on non-Unix platforms.
kill_process_group_by_pid
No-op on non-Unix platforms.
kill_process_group_by_pid_with_signal
No-op on non-Unix platforms.
kill_process_group_with_signal
No-op on non-Unix platforms.
set_parent_death_signal
No-op on non-Linux platforms.
set_process_group
No-op on non-Unix platforms.