Expand description
§2.Group Manipulation API
Functions:
- cgroup_new_cgroup
- cgroup_add_controller
- cgroup_get_controller
- cgroup_free
- cgroup_free_controllers
- cgroup_create_cgroup
- cgroup_create_cgroup_from_parent
- cgroup_modify_cgroup
- cgroup_delete_cgroup
- cgroup_delete_cgroup_ext
- cgroup_get_cgroup
- cgroup_copy_cgroup
- cgroup_compare_cgroup
- cgroup_compare_controllers
- cgroup_set_uid_gid
- cgroup_get_uid_gid
- cgroup_add_value_*
- cgroup_get_value_*
- cgroup_set_value_*
- cgroup_get_value_name_count
- cgroup_get_value_name
Usage(Create):
use libcgroup_rs::initialization::CGroupInitializer;
use libcgroup_rs::manipulation::CGroupBuilder;
use libcgroup_rs::error::{cg_get_error, C_EC_GROUP_NOT_ALLOWED};
fn main()->Result<(),Box<dyn std::error::Error>>{
CGroupInitializer::init()?;
let container_name = "foo";
let cg = CGroupBuilder::new(container_name)?;
println!("Source CG = {:?}",cg);
// append controller
println!("Add Controller = {:?}",cg.add_controller("cpu")?);
println!("Get Controller = {:?}",cg.get_controller("cpu")?);
//only root
match cg.create(0) {
Ok(_) => (),
Err(e) if e.kind().eq(&cg_get_error(C_EC_GROUP_NOT_ALLOWED).kind()) =>{
println!("Only root! = use sudo ?");
return Ok(());
}
Err(e) => return Err(Box::new(e))
}
Ok(())
}Usage(Create with params):
use libcgroup_rs::initialization::CGroupInitializer;
use libcgroup_rs::manipulation::CGroupBuilder;
use libcgroup_rs::error::{cg_get_error, C_EC_GROUP_NOT_ALLOWED};
fn main()->Result<(),Box<dyn std::error::Error>>{
CGroupInitializer::init()?;
let container_name = "foo";
let container = CGroupBuilder::new(container_name)?;
println!("Container = {:?}",container);
let ctrl = container.add_controller("cpu")?;
println!("Controller = {:?}",ctrl);
// cfg = /cgroups/foo/cpu/cfs_quota_us
ctrl.add_u64("cpu.cfs_quota_us",50000)?;
// cfg = /cgroups/foo/cpu/cfs_period_us
ctrl.add_u64("cpu.cfs_period_us",100000)?;
// create
container.create(0)?;
Ok(())
}