View Source Stdio.Procfs (stdio v0.4.2)

Read data from procfs.

Link to this section Summary

Functions

Get descendents of a process.

Return a snapshot of the current system processes.

Link to this section Types

@type t() :: %{required(String.t()) => String.t()}

Link to this section Functions

Link to this function

children(pid, procfs \\ "/proc")

View Source
@spec children(:prx.pid_t(), Path.t()) :: [:prx.pid_t()]

Get descendents of a process.

Child processes are enumerated by reading proc(5):

  • if the Linux kernel was compiled with CONFIG_PROC_CHILDREN, the /proc/[pid]/task/[pid]/children file is read

  • otherwise, children/1 falls back to walking /proc

examples

Examples

iex> Stdio.Procfs.children(0) |> Enum.sort() |> List.first()
1
@spec ps(Path.t()) :: [t()]

Return a snapshot of the current system processes.

Generates a snapshot of running system processes by walking the procfs filesystem (usually mounted as /proc).

The returned value is a map list of key/value pairs read from /proc/[pid]/status.

examples

Examples

iex> pid = Stdio.Procfs.ps() |> Enum.sort(&(&1["ppid"] < &2["ppid"])) |> List.first()
iex> pid["pid"]
"1"