add get_threads

This commit is contained in:
mii443
2024-10-17 07:42:47 +00:00
parent 8ccd662792
commit 9345d757d9
2 changed files with 11 additions and 2 deletions

View File

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

View File

@ -76,8 +76,16 @@ impl CGroup {
} }
pub fn get_procs(&self) -> Result<Vec<u32>, std::io::Error> { pub fn get_procs(&self) -> Result<Vec<u32>, std::io::Error> {
self.get_u32_list("cgroup.procs")
}
pub fn get_threads(&self) -> Result<Vec<u32>, std::io::Error> {
self.get_u32_list("cgroup.threads")
}
fn get_u32_list(&self, name: &str) -> Result<Vec<u32>, std::io::Error> {
let procs = self let procs = self
.read("cgroup.procs")? .read(name)?
.lines() .lines()
.map(|proc| u32::from_str(proc.trim()).unwrap()) .map(|proc| u32::from_str(proc.trim()).unwrap())
.collect(); .collect();