add get_procs

This commit is contained in:
mii443
2024-10-17 07:01:24 +00:00
parent 17a21606f5
commit 3c2dbeaa93
2 changed files with 11 additions and 1 deletions

View File

@ -1,10 +1,10 @@
use izolilib::cgroup::cgroup::CGroup;
fn main() {
println!("test");
let cgroup = CGroup::new("test").unwrap();
println!("{:?}", cgroup.get_root_path());
println!("{}", cgroup.check_status());
println!("{:?}", cgroup.read("cgroup.type"));
println!("{:?}", cgroup.get_controllers());
println!("{:?}", cgroup.get_procs());
}

View File

@ -66,4 +66,14 @@ impl CGroup {
Ok(controllers)
}
pub fn get_procs(&self) -> Result<Vec<u32>, std::io::Error> {
let procs = self
.read("cgroup.procs")?
.lines()
.map(|proc| u32::from_str(proc.trim()).unwrap())
.collect();
Ok(procs)
}
}