Expand description
Proc Connector Process Cache + Process Tree
Two data structures:
- ProcCache: PID → {cmd, user, ppid, tgid} from Exec events (existing)
- PidTree: PID → {ppid, cmd} for ancestor lookups (new, handles Fork/Exec/Exit)
The PidTree is populated from three sources:
- Startup snapshot:
/proc/*/status→ seed existing processes - Fork events: parent→child relationship (no cmd yet)
- Exec events: update cmd for the child
Structs§
- Cache
Params - Parameters for process caches (ProcCache and PidTree).
- PidNode
- A node in the process tree. cmd starts empty (from Fork) and fills on Exec.
- Proc
Info - Cached process info: command name, user, ppid, tgid.
Constants§
- PID_
TREE_ CAP - Capacity for process tree cache.
- PID_
TREE_ TTL_ SECS - TTL for process tree entries.
- PROC_
CACHE_ CAP - Capacity for process info cache. Covers typical active PID ranges with headroom.
- PROC_
CACHE_ TTL_ SECS - TTL for process info entries. Exited processes are evicted after this time.
Functions§
- build_
chain - Build a chain string from the process tree. Format: “102|touch|root;101|sh|root;100|openclaw|root;1|systemd|root” Falls back to reading /proc if a PID is not in the tree.
- handle_
proc_ events - Process proc connector events. Handles Exec (update ProcCache + PidTree cmd), Fork (insert PidTree), and Exit (optional, no cleanup needed for correct lookups).
- is_
descendant - Check if
pidis a descendant of any process whose cmd ==target_cmd. Walks up the tree via ppid until hitting root (pid=1, pid=0, self-loop, or cycle). - new_
cache - Create a new ProcCache with the configured capacity and TTL.
- new_
cache_ with - Create a ProcCache with explicit capacity and TTL overrides.
- new_
pid_ tree - Create a new PidTree with the configured capacity and TTL.
- new_
pid_ tree_ with - Create a PidTree with explicit capacity and TTL overrides.
- read_
proc_ start_ time_ ns - snapshot_
process_ tree - Snapshot all existing processes from /proc on daemon start.
Reads
/proc/*/statusto seed the tree with current PIDs and their ppid/cmd. - try_
create_ connector