Skip to main content

siblings

Function siblings 

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

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

Excludes the given pid itself.

use proc_tree::{DefaultStore, siblings, 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: 1, cmd: "b".into(), user: "root".into(), tgid: 200, start_time_ns: 0 });
store.insert_process(300, ProcessInfo { ppid: 1, cmd: "c".into(), user: "root".into(), tgid: 300, start_time_ns: 0 });

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