Xuewei Niu 799d02d266 Merge pull request #169 from kata-containers/ci/test-cgroup-v1-v2
ci: Test cgroup v1 and v2 in QEMU
2026-07-30 15:08:59 +08:00
2025-07-08 23:56:57 +08:00
2026-07-28 06:23:16 -05:00
2026-07-28 06:23:16 -05:00
2023-07-31 15:01:17 +08:00
2026-07-14 04:51:40 -05:00
2018-08-30 00:04:53 +02:00
2018-08-30 00:04:53 +02:00
2025-07-18 15:17:12 +08:00

cgroups-rs

Crate

Native Rust library for managing Linux control groups. Supports both cgroups v1 and v2.

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!

Description
No description provided
Readme 678 KiB
Languages
Rust 96.5%
Shell 3.2%
Makefile 0.3%