17 releases

0.3.4 Oct 25, 2023
0.3.2 Mar 15, 2023
0.2.11 Sep 23, 2022
0.2.10 Jun 29, 2022
0.2.0 Dec 21, 2020

#58 in Unix APIs

Download history 19358/week @ 2024-09-09 20498/week @ 2024-09-16 21994/week @ 2024-09-23 22728/week @ 2024-09-30 24519/week @ 2024-10-07 25114/week @ 2024-10-14 25318/week @ 2024-10-21 21063/week @ 2024-10-28 18593/week @ 2024-11-04 20989/week @ 2024-11-11 21899/week @ 2024-11-18 18673/week @ 2024-11-25 19892/week @ 2024-12-02 18976/week @ 2024-12-09 18832/week @ 2024-12-16 7065/week @ 2024-12-23

65,780 downloads per month
Used in 11 crates (9 directly)

MIT/Apache

255KB
5.5K SLoC

cgroups-rs Build

Native Rust library for managing control groups under Linux

Both v1 and v2 of cgroups are supported.

Examples

Create a control group using the builder pattern



use cgroups_rs::*;
use cgroups_rs::cgroup_builder::*;

// Acquire a handle for the cgroup hierarchy.
let hier = cgroups_rs::hierarchies::auto();

// Use the builder pattern (see the documentation to create the control group)
//
// This creates a control group named "example" in the V1 hierarchy.
    let cg: Cgroup = CgroupBuilder::new("example")
        .cpu()
        .shares(85)
        .done()
        .build(hier);

// Now `cg` is a control group that gets 85% of the CPU time in relative to
// other control groups.

// Get a handle to the CPU controller.
let cpus: &cgroups_rs::cpu::CpuController = cg.controller_of().unwrap();
cpus.add_task(&CgroupPid::from(1234u64));

// [...]

// Finally, clean up and delete the control group.
cg.delete();

// Note that `Cgroup` does not implement `Drop` and therefore when the
// structure is dropped, the Cgroup will stay around. This is because, later
// you can then re-create the `Cgroup` using `load()`. We aren't too set on
// this behavior, so it might change in the feature. Rest assured, it will be a
// major version change.

Disclaimer

This crate is licensed under:

  • MIT License (see LICENSE-MIT); or
  • Apache 2.0 License (see LICENSE-Apache-2.0),

at your option.

Please note that this crate is under heavy development, we will use sematic versioning, but during the 0.0.* phase, no guarantees are made about backwards compatibility.

Regardless, check back often and thanks for taking a look!

Dependencies

~4–5.5MB
~109K SLoC