pub struct Cgroup<'b> { /* private fields */ }
Expand description
A control group is the central structure to this crate.
What are control groups?
Lifting over from the Linux kernel sources:
Control Groups provide a mechanism for aggregating/partitioning sets of tasks, and all their future children, into hierarchical groups with specialized behaviour.
This crate is an attempt at providing a Rust-native way of managing these cgroups.
Implementations
sourceimpl<'b> Cgroup<'b>
impl<'b> Cgroup<'b>
sourcepub fn new<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup<'_>
pub fn new<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup<'_>
Create a new control group in the hierarchy hier
, with name path
.
Returns a handle to the control group that can be used to manipulate it.
Note that if the handle goes out of scope and is dropped, the control group is not destroyed.
sourcepub fn load<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup<'_>
pub fn load<P: AsRef<Path>>(hier: &dyn Hierarchy, path: P) -> Cgroup<'_>
Create a handle for a control group in the hierarchy hier
, with name path
.
Returns a handle to the control group (that possibly does not exist until create()
has
been called on the cgroup.
Note that if the handle goes out of scope and is dropped, the control group is not destroyed.
sourcepub fn subsystems(&self) -> &Vec<Subsystem>
pub fn subsystems(&self) -> &Vec<Subsystem>
The list of subsystems that this control group supports.
sourcepub fn delete(self)
pub fn delete(self)
Deletes the control group.
Note that this function makes no effort in cleaning up the descendant and the underlying system call will fail if there are any descendants. Thus, one should check whether it was actually removed, and remove the descendants first if not. In the future, this behavior will change.
sourcepub fn apply(&self, res: &Resources) -> Result<()>
pub fn apply(&self, res: &Resources) -> Result<()>
Apply a set of resource limits to the control group.
sourcepub fn controller_of<'a, T>(&'a self) -> Option<&'a T>where
&'a T: From<&'a Subsystem>,
T: Controller + ControllIdentifier,
pub fn controller_of<'a, T>(&'a self) -> Option<&'a T>where
&'a T: From<&'a Subsystem>,
T: Controller + ControllIdentifier,
Retrieve a container based on type inference.
Example:
let pids: &PidController = control_group.controller_of()
.expect("No pids controller attached!");
let cpu: &CpuController = control_group.controller_of()
.expect("No cpu controller attached!");
sourcepub fn remove_task(&self, pid: CgroupPid)
pub fn remove_task(&self, pid: CgroupPid)
Removes a task from the control group.
Note that this means that the task will be moved back to the root control group in the hierarchy and any rules applied to that control group will still apply to the task.