add get_max_descendants

This commit is contained in:
mii443
2024-10-17 08:01:31 +00:00
parent d88b3ea4da
commit acdbb28448
2 changed files with 15 additions and 2 deletions

View File

@ -10,4 +10,6 @@ fn main() {
println!("{:?}", cgroup.get_procs()); println!("{:?}", cgroup.get_procs());
println!("{:?}", cgroup.get_threads()); println!("{:?}", cgroup.get_threads());
println!("{:?}", cgroup.get_stat()); println!("{:?}", cgroup.get_stat());
println!("{:?}", cgroup.get_max_depth());
println!("{:?}", cgroup.get_max_descendants());
} }

View File

@ -100,8 +100,19 @@ impl CGroup {
} }
pub fn get_max_depth(&self) -> Result<CGroupLimitValue<u64>, std::io::Error> { pub fn get_max_depth(&self) -> Result<CGroupLimitValue<u64>, std::io::Error> {
let max = self.read("cgroup.max.depth")?; self.get_limit_value("cgroup.max.depth")
}
Ok(CGroupLimitValue::from_str(&max).unwrap()) pub fn get_max_descendants(&self) -> Result<CGroupLimitValue<u64>, std::io::Error> {
self.get_limit_value("cgroup.max.descendants")
}
fn get_limit_value<T>(&self, name: &str) -> Result<CGroupLimitValue<T>, std::io::Error>
where
T: FromStr,
{
let value = self.read(name)?;
Ok(CGroupLimitValue::from_str(&value).unwrap())
} }
} }