Update readme

Update readme

Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
Tim Zhang
2020-12-03 17:53:46 +08:00
parent 438d774866
commit c254fffbe0

View File

@@ -9,24 +9,29 @@ is planned for the Unified hierarchy.
## Create a control group using the builder pattern ## Create a control group using the builder pattern
``` rust ``` rust
// Acquire a handle for the V1 cgroup hierarchy.
let hier = ::hierarchies::V1::new();
use cgroups::*;
use cgroups::cgroup_builder::*;
// Acquire a handle for the cgroup hierarchy.
let hier = cgroups::hierarchies::auto();
// Use the builder pattern (see the documentation to create the control group) // Use the builder pattern (see the documentation to create the control group)
// //
// This creates a control group named "example" in the V1 hierarchy. // This creates a control group named "example" in the V1 hierarchy.
let cg: Cgroup = CgroupBuilder::new("example", &v1) let cg: Cgroup = CgroupBuilder::new("example")
.cpu() .cpu()
.shares(85) .shares(85)
.done() .done()
.build(); .build(hier);
// Now `cg` is a control group that gets 85% of the CPU time in relative to // Now `cg` is a control group that gets 85% of the CPU time in relative to
// other control groups. // other control groups.
// Get a handle to the CPU controller. // Get a handle to the CPU controller.
let cpus: &CpuController = cg.controller_of().unwrap(); let cpus: &cgroups::cpu::CpuController = cg.controller_of().unwrap();
cpus.add_task(1234u64); cpus.add_task(&CgroupPid::from(1234u64));
// [...] // [...]