Skip to content

Commit 8a2fa92

Browse files
committed
Update README
Signed-off-by: Levente Kurusa <[email protected]>
1 parent dd621ea commit 8a2fa92

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
# cgroups-rs ![Build](https://travis-ci.org/levex/cgroups-rs.svg?branch=master)
22
Native Rust library for managing control groups under Linux
33

4-
# Example
4+
Right now the crate only support the original, V1 hierarchy, however support
5+
is planned for the Unified hierarchy.
56

6-
## Create a control group, and limit the pid resource
7+
# Examples
8+
9+
## Create a control group using the builder pattern
710

811
``` rust
912
// Acquire a handle for the V1 cgroup hierarchy.
1013
let hier = ::hierarchies::V1::new();
11-
// Create a control group named "example" in the hierarchy.
12-
let cg = Cgroup::new(&hier, String::from("example"), 0);
13-
{
14-
// Get a handle to the pids controller of the control group.
15-
let pids: &PidController = cg.controller_of().expect("No pids controller in V1 hierarchy!");
16-
// Set the maximum amount of processes in the cgroup.
17-
pids.set_pid_max(PidMax::Value(10));
18-
// Check that this has had the desired effect by reading the value back from the kernel.
19-
assert_eq!(pids.get_pid_max(), Some(PidMax::Value(10)));
20-
}
21-
// Once done, delete the control group (and its associated controllers).
14+
15+
// Use the builder pattern (see the documentation to create the control group)
16+
//
17+
// This creates a control group named "example" in the V1 hierarchy.
18+
let cg: Cgroup = CgroupBuilder::new("example", &v1)
19+
.cpu()
20+
.shares(85)
21+
.done()
22+
.build();
23+
24+
// Now `cg` is a control group that gets 85% of the CPU time in relative to
25+
// other control groups.
26+
27+
// Get a handle to the CPU controller.
28+
let cpus: &CpuController = cg.controller_of().unwrap();
29+
cpus.add_task(1234u64);
30+
31+
// [...]
32+
33+
// Finally, clean up and delete the control group.
2234
cg.delete();
35+
36+
// Note that `Cgroup` does not implement `Drop` and therefore when the
37+
// structure is dropped, the Cgroup will stay around. This is because, later
38+
// you can then re-create the `Cgroup` using `load()`. We aren't too set on
39+
// this behavior, so it might change in the feature. Rest assured, it will be a
40+
// major version change.
2341
```
2442

2543
# Disclaimer
2644

2745
This crate is licensed under:
2846

2947
- MIT License (see LICENSE-MIT); or
30-
- Apache 2.0 LIcense (see LICENSE-Apache-2.0),
48+
- Apache 2.0 License (see LICENSE-Apache-2.0),
3149

3250
at your option.
3351

0 commit comments

Comments
 (0)