Skip to main content

siblings

Function siblings 

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

Get siblings of a PID (processes with the same parent).

Excludes the given pid itself.

use proc_tree::{DefaultTree, siblings, 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: 1, cmd: "b".into() });
tree.insert_node(300, PidNode { ppid: 1, cmd: "c".into() });

let mut sibs = siblings(&tree, 100);
sibs.sort();
assert_eq!(sibs, vec![200, 300]);
assert!(siblings(&tree, 1).is_empty()); // init has no siblings