add cgroup enter

This commit is contained in:
mii443
2024-10-18 08:10:15 +00:00
parent b9e66ce79a
commit f171ac10bc
2 changed files with 8 additions and 0 deletions

View File

@ -12,4 +12,6 @@ fn main() {
println!("{:?}", cgroup.get_stat()); println!("{:?}", cgroup.get_stat());
println!("{:?}", cgroup.get_max_depth()); println!("{:?}", cgroup.get_max_depth());
println!("{:?}", cgroup.get_max_descendants()); println!("{:?}", cgroup.get_max_descendants());
cgroup.enter().unwrap();
} }

View File

@ -30,6 +30,12 @@ impl CGroup {
fs::create_dir_all(root) fs::create_dir_all(root)
} }
pub fn enter(&self) -> Result<(), std::io::Error> {
let pid = std::process::id();
self.add_procs(vec![pid])
}
pub fn read(&self, name: &str) -> Result<String, std::io::Error> { pub fn read(&self, name: &str) -> Result<String, std::io::Error> {
let path = self.get_file_path(name); let path = self.get_file_path(name);
let mut file = File::open(path)?; let mut file = File::open(path)?;