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§
- Default
Store - Generic store backed by
HashMap<Mutex>with optional TTL eviction. - PidNode
- A node in the process tree.
- Proc
Info - Cached process info for a single PID.
- Process
Link - A single entry in a process ancestry chain.
Enums§
- Proc
Event - A process lifecycle event. Decoupled from any specific event source (proc-connector, audit, etc.) so users can adapt their own events.
Traits§
- Cache
Store - Trait for process info cache.
- Tree
Store - 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
pidis 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§
- Default
Cache - Process info cache. See
DefaultStore. - Default
Tree - Process tree store. See
DefaultStore.