Skip to main content

descendants

Function descendants 

Source
pub fn descendants(store: &impl ProcessStore, pid: u32) -> Vec<u32>
Expand description

Get all descendants of a PID (BFS traversal).

use proc_tree::{DefaultStore, descendants, ProcessStore, ProcessInfo};

let store = DefaultStore::new(0);
store.insert_process(1, ProcessInfo { ppid: 0, cmd: "init".into(), user: "root".into(), tgid: 1, start_time_ns: 0 });
store.insert_process(100, ProcessInfo { ppid: 1, cmd: "a".into(), user: "root".into(), tgid: 100, start_time_ns: 0 });
store.insert_process(200, ProcessInfo { ppid: 100, cmd: "b".into(), user: "root".into(), tgid: 200, start_time_ns: 0 });
store.insert_process(300, ProcessInfo { ppid: 200, cmd: "c".into(), user: "root".into(), tgid: 300, start_time_ns: 0 });

let mut desc = descendants(&store, 1);
desc.sort();
assert_eq!(desc, vec![100, 200, 300]);
assert_eq!(descendants(&store, 300), Vec::<u32>::new());