diff --git a/src/cgroup.rs b/src/cgroup.rs index 13308a8..8e6dd97 100644 --- a/src/cgroup.rs +++ b/src/cgroup.rs @@ -233,6 +233,13 @@ impl<'b> Cgroup<'b> { } } + /// Attach a task to the control group by thread group id. + pub fn add_task_by_tgid(&self, pid: CgroupPid) -> Result<()> { + self.subsystems() + .iter() + .try_for_each(|sub| sub.to_controller().add_task_by_tgid(&pid)) + } + /// Returns an Iterator that can be used to iterate over the tasks that are currently in the /// control group. pub fn tasks(&self) -> Vec { diff --git a/src/lib.rs b/src/lib.rs index 0761631..c94f73e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -219,6 +219,9 @@ pub trait Controller { /// Attach a task to this controller. fn add_task(&self, pid: &CgroupPid) -> Result<()>; + /// Attach a task to this controller. + fn add_task_by_tgid(&self, pid: &CgroupPid) -> Result<()>; + /// Get the list of tasks that this controller has. fn tasks(&self) -> Vec; @@ -278,6 +281,14 @@ where }) } + /// Attach a task to this controller by thread group id. + fn add_task_by_tgid(&self, pid: &CgroupPid) -> Result<()> { + self.open_path("cgroup.procs", true).and_then(|mut file| { + file.write_all(pid.pid.to_string().as_ref()) + .map_err(|e| Error::with_cause(ErrorKind::WriteFailed, e)) + }) + } + /// Get the list of tasks that this controller has. fn tasks(&self) -> Vec { let mut file = "tasks";