1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! # proc-tree
//!
//! Linux process tree: snapshot, incremental maintenance via fork/exec events,
//! ancestry chain queries, and PID reuse detection.
//!
//! ## Quick Start
//!
//! ```rust
//! use proc_tree::{ProcessStore, ProcessInfo, ProcEvent};
//! use proc_tree::{snapshot, resolve, handle_events, build_chain_string};
//!
//! // Implement your own storage (or use a provided example)
//! # struct MyStore;
//! # impl ProcessStore for MyStore {
//! # fn get_process(&self, pid: u32) -> Option<ProcessInfo> { None }
//! # fn insert_process(&self, pid: u32, info: ProcessInfo) {}
//! # fn remove_process(&self, pid: u32) -> Option<ProcessInfo> { None }
//! # fn all_pids(&self) -> Vec<u32> { vec![] }
//! # fn children_of(&self, pid: u32) -> Vec<u32> { vec![] }
//! # }
//!
//! let store = MyStore;
//!
//! // Seed from /proc
//! snapshot(&store);
//!
//! // Resolve a PID
//! if let Some(info) = resolve(&store, 1) {
//! println!("PID 1: cmd={}, user={}", info.cmd, info.user);
//! }
//!
//! // Build ancestry chain
//! let s = build_chain_string(&store, 1234);
//! println!("Chain: {}", s);
//!
//! // Handle events (returns ExitedProcess handles)
//! let exited = handle_events(&store, &[
//! ProcEvent::Fork { child_pid: 200, parent_pid: 100, timestamp_ns: 0 },
//! ]);
//! // Caller decides when to remove exited processes
//! for ep in exited {
//! ep.remove(&store);
//! }
//! ```
//!
//! ## PID Reuse Detection
//!
//! When a process exits and its PID is reused by a new process, cached data
//! becomes stale. `ProcessStore` implementations should compare `start_time_ns`
//! with the current `/proc` value to detect reuse.
// Public API — types
pub use ProcessInfo;
// Public API — traits
pub use ProcessStore;
// Public API — default implementations
pub use DefaultStore;
// Public API — tree types
pub use ;
// Public API — operations
pub use ;
// Public API — proc utilities
pub use proc::;