add add_threads

This commit is contained in:
mii443
2024-10-17 08:46:24 +00:00
parent 003fc66754
commit b9e66ce79a

View File

@ -146,15 +146,11 @@ impl CGroup {
}
pub fn add_procs(&self, procs: Vec<u32>) -> Result<(), std::io::Error> {
let to_write = procs
.iter()
.map(|proc| proc.to_string())
.collect::<Vec<String>>()
.join("\n");
self.write_list("cgroup.procs", procs)
}
self.write("cgroup.procs", &to_write)?;
Ok(())
pub fn add_threads(&self, threads: Vec<u32>) -> Result<(), std::io::Error> {
self.write_list("cgroup.threads", threads)
}
fn write_value<T>(&self, name: &str, value: T) -> Result<(), std::io::Error>
@ -165,6 +161,21 @@ impl CGroup {
Ok(())
}
fn write_list<T>(&self, name: &str, value: Vec<T>) -> Result<(), std::io::Error>
where
T: fmt::Display,
{
let to_write = value
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join("\n");
self.write(name, &to_write)?;
Ok(())
}
fn get_u32_list(&self, name: &str) -> Result<Vec<u32>, std::io::Error> {
let procs = self
.read(name)?