mirror of
https://github.com/kata-containers/cgroups-rs.git
synced 2026-08-05 02:13:23 +00:00
add add_task_by_tgid
Add task by writing thread group id to cgroup.procs. Signed-off-by: Yang, Wei <wei.yang1@linux.alibaba.com> Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
@@ -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<CgroupPid> {
|
||||
|
||||
11
src/lib.rs
11
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<CgroupPid>;
|
||||
|
||||
@@ -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<CgroupPid> {
|
||||
let mut file = "tasks";
|
||||
|
||||
Reference in New Issue
Block a user