Snakepit.ProcessKiller (Snakepit v0.8.7)

View Source

Robust OS process management using Erlang primitives. No shell commands, pure Erlang/Elixir.

This module provides POSIX-compliant process management that works across Linux, macOS, and BSD systems without relying on shell-specific features like pkill.

Summary

Functions

Finds all Python processes on the system. Returns a list of OS PIDs.

Gets the command line of a process. POSIX-compliant using /proc on Linux, ps on macOS/BSD.

Gets the process group ID (PGID) for a process.

Kills all processes matching a run ID. Pure Erlang implementation, no pkill.

Kills a process by PID using proper Erlang signals.

Kills a process group by PGID using proper Erlang signals.

Kills a process group with escalation: SIGTERM -> wait -> SIGKILL.

Kills a process with escalation: SIGTERM -> wait -> SIGKILL

Checks if a process is alive. Uses kill -0 (signal 0) which doesn't kill but checks existence.

Returns true if the platform supports process group kill semantics.

Returns the path to the setsid executable, or {:error, :not_found}.

Returns the setsid executable path or raises if not available.

Functions

find_python_processes()

Finds all Python processes on the system. Returns a list of OS PIDs.

get_process_command(os_pid)

Gets the command line of a process. POSIX-compliant using /proc on Linux, ps on macOS/BSD.

get_process_group_id(os_pid)

Gets the process group ID (PGID) for a process.

kill_by_run_id(run_id)

Kills all processes matching a run ID. Pure Erlang implementation, no pkill.

kill_process(os_pid, signal \\ :sigterm)

Kills a process by PID using proper Erlang signals.

Parameters

  • os_pid: OS process ID (integer)
  • signal: :sigterm | :sigkill | :sighup

Returns

  • :ok if kill succeeded
  • {:error, reason} if kill failed

kill_process_group(pgid, signal \\ :sigterm)

Kills a process group by PGID using proper Erlang signals.

Parameters

  • pgid: Process group ID (integer)
  • signal: :sigterm | :sigkill | :sighup

kill_process_group_with_escalation(pgid, timeout_ms \\ 2000)

Kills a process group with escalation: SIGTERM -> wait -> SIGKILL.

kill_with_escalation(os_pid, timeout_ms \\ 2000)

Kills a process with escalation: SIGTERM -> wait -> SIGKILL

process_alive?(os_pid)

Checks if a process is alive. Uses kill -0 (signal 0) which doesn't kill but checks existence.

process_group_supported?()

Returns true if the platform supports process group kill semantics.

setsid_executable()

Returns the path to the setsid executable, or {:error, :not_found}.

setsid_executable!()

Returns the setsid executable path or raises if not available.