Skip to main content

Crate proc_tree

Crate proc_tree 

Source
Expand description

§proc-tree

Linux process tree: snapshot, incremental maintenance via fork/exec events, ancestry chain queries, and PID reuse detection.

§Quick Start

use proc_tree::{TreeStore, CacheStore, PidNode, ProcInfo, ProcEvent};
use proc_tree::{snapshot, resolve, handle_events, build_chain_string};

// Implement your own storage (or use a provided example)
}

let tree = MyTree;
let cache = MyCache;

// Seed from /proc
snapshot(&tree, &cache);

// Resolve a PID
if let Some(info) = resolve(&cache, 1) {
    println!("PID 1: cmd={}, user={}", info.cmd, info.user);
}

// Build ancestry chain
let s = build_chain_string(&tree, &cache, 1234);
println!("Chain: {}", s);

// Handle events
handle_events(&tree, &cache, &[
    ProcEvent::Fork { child_pid: 200, parent_pid: 100, timestamp_ns: 0 },
]);

§PID Reuse Detection

When a process exits and its PID is reused by a new process, cached data becomes stale. CacheStore implementations should compare start_time_ns with the current /proc value to detect reuse.

Re-exports§

pub use proc::parse_proc_entry;
pub use proc::read_proc_start_time_ns;

Modules§

proc
Raw /proc reading for process tree construction.

Structs§

DefaultStore
Generic store backed by HashMap<Mutex> with optional TTL eviction.
PidNode
A node in the process tree.
ProcInfo
Cached process info for a single PID.
ProcessLink
A single entry in a process ancestry chain.

Enums§

ProcEvent
A process lifecycle event. Decoupled from any specific event source (proc-connector, audit, etc.) so users can adapt their own events.

Traits§

CacheStore
Trait for process info cache.
TreeStore
Trait for process tree storage.

Functions§

build_chain_links
Build a chain of ProcessLink from the process tree.
build_chain_string
Build a chain string from the process tree.
children
Get direct children of a PID.
descendants
Get all descendants of a PID (BFS traversal).
display
Render a pstree-style display starting from the given root PID.
find_by_cmd
Find all PIDs whose cmd matches the given string.
find_by_user
Find all PIDs whose user matches the given string.
handle_event
Handle a single process lifecycle event.
handle_events
Handle a batch of process lifecycle events.
is_descendant
Check if pid is a descendant of any process whose cmd == target_cmd.
resolve
Resolve a PID to its process info.
siblings
Get siblings of a PID (processes with the same parent).
snapshot
Snapshot all running processes from /proc.
tree_len
Get the number of entries in the tree.

Type Aliases§

DefaultCache
Process info cache. See DefaultStore.
DefaultTree
Process tree store. See DefaultStore.