Trebejo.Proc (Trebejo v1.0.0)

Copy Markdown View Source

Process and executable utilities (shell-based operations).

Process and executable utilities (shell-based operations).

Pure functions (command availability, VM introspection) are implemented inline. Shell-dependent operations: process listing, signalling, lsof, fuser, and log access.

All command execution is routed through Arrea.Command.execute/2 (with validate: false) so consumers get real timeout cancellation, telemetry, and structured errors. The fragile try/rescue blocks are gone — Arrea returns {:error, reason} on timeout / missing binary / etc.

Summary

Functions

Filters a list of commands to only those available on the system.

Returns true if the given command exists in the system PATH.

Lists processes using a specific file or port (fuser wrapper).

Sends a signal to a process by PID.

Returns a map of command => path for all found commands.

Shows recent logs for a process via journalctl (Linux systemd) or log (macOS).

Lists files opened by a process (lsof wrapper). Linux/macOS only.

Returns the OS process ID of the BEAM VM.

Lists running processes (cross-platform via ps).

Returns the number of scheduler threads.

Returns the VM memory usage in bytes.

Returns the VM uptime in milliseconds.

Returns the full path of a command if found, or nil.

Functions

available_commands(commands)

@spec available_commands([String.t()]) :: [String.t()]

Filters a list of commands to only those available on the system.

command_exists?(cmd)

@spec command_exists?(String.t()) :: boolean()

Returns true if the given command exists in the system PATH.

fuser(target)

@spec fuser(String.t()) :: {:ok, [non_neg_integer()]} | {:error, term()}

Lists processes using a specific file or port (fuser wrapper).

kill(pid, signal \\ :term)

@spec kill(non_neg_integer(), atom()) :: :ok | {:error, term()}

Sends a signal to a process by PID.

locate_commands(commands)

@spec locate_commands([String.t()]) :: %{required(String.t()) => String.t()}

Returns a map of command => path for all found commands.

logs(service, opts \\ [])

@spec logs(
  String.t(),
  keyword()
) :: {:ok, String.t()} | {:error, term()}

Shows recent logs for a process via journalctl (Linux systemd) or log (macOS).

lsof(pid)

@spec lsof(non_neg_integer()) :: {:ok, [String.t()]} | {:error, term()}

Lists files opened by a process (lsof wrapper). Linux/macOS only.

os_pid()

@spec os_pid() :: non_neg_integer()

Returns the OS process ID of the BEAM VM.

ps(opts \\ [])

@spec ps(keyword()) :: {:ok, [map()]} | {:error, term()}

Lists running processes (cross-platform via ps).

scheduler_count()

@spec scheduler_count() :: non_neg_integer()

Returns the number of scheduler threads.

vm_memory()

@spec vm_memory() :: non_neg_integer()

Returns the VM memory usage in bytes.

vm_uptime()

@spec vm_uptime() :: non_neg_integer()

Returns the VM uptime in milliseconds.

which(cmd)

@spec which(String.t()) :: String.t() | nil

Returns the full path of a command if found, or nil.