Skip to main content

handle_event

Function handle_event 

Source
pub fn handle_event(
    store: &impl ProcessStore,
    event: &ProcEvent,
) -> Option<ExitedProcess>
Expand description

Handle a single process lifecycle event.

Returns ExitedProcess for Exit events, None for other events. The process info stays in the store — callers decide when to remove it via ExitedProcess::remove.

§Example

use proc_tree::{DefaultStore, handle_event, ProcEvent, ProcessStore};

let store = DefaultStore::new(0);

// Create a process
handle_event(&store, &ProcEvent::Fork {
    child_pid: 100,
    parent_pid: 1,
    timestamp_ns: 0,
});

// Exit returns ExitedProcess handle — process info stays in store
let exited = handle_event(&store, &ProcEvent::Exit { pid: 100 }).unwrap();
assert_eq!(exited.pid, 100);
assert!(store.get_process(100).is_some());

// Caller explicitly removes when done
exited.remove(&store);
assert!(store.get_process(100).is_none());