Skip to main content

descendants

Function descendants 

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

Get all descendants of a PID (BFS traversal).

use proc_tree::{DefaultTree, descendants, TreeStore, PidNode};

let tree = DefaultTree::new(100, 0);
tree.insert_node(1, PidNode { ppid: 0, cmd: "init".into() });
tree.insert_node(100, PidNode { ppid: 1, cmd: "a".into() });
tree.insert_node(200, PidNode { ppid: 100, cmd: "b".into() });
tree.insert_node(300, PidNode { ppid: 200, cmd: "c".into() });

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