LinuxCommandLibrary

cgexec

Run a process in a cgroup

TLDR

Execute a process in a given c[g]roup with given controller

$ cgexec -g [controller]:[cgroup_name] [process_name]
copy

SYNOPSIS

cgexec [-g path:controller[,controller]...] [-r] [-t] [-v] [-X] [--help] [--version] command [args...]

PARAMETERS

-g, --cg ...]
    Place new tasks into control groups at the specified relative path for listed controllers (e.g., -g tasks:cpu,memory).

-r, --sticky
    Ignore path for controllers where the current task is not already in that cgroup.

-t, --task-create-files
    Do not create tasks files in cgroups if they are missing.

-v, --verbose
    Enable verbose output during execution.

-X, --sched
    Run command in a new scheduling domain (requires libcgdb support).

--help
    Display usage information.

--version
    Show version and exit.

DESCRIPTION

The cgexec command, part of the libcgroup package, allows users to run a program or shell command within one or more specified control groups (cgroups). Cgroups provide a mechanism to limit, account for, and isolate resource usage (CPU, memory, disk I/O, network, etc.) for groups of processes in Linux.

By launching tasks via cgexec, the new processes are automatically placed into the designated cgroups, enabling fine-grained resource management without manual intervention using tools like echo to /sys/fs/cgroup tasks files. This is useful for container-like isolation, benchmarking, or enforcing limits on untrusted applications.

Primarily used in environments with cgroup v1 hierarchies, cgexec supports multiple controllers per invocation and relative paths. It creates necessary tasks files if absent (unless disabled), making it straightforward for dynamic workload control. On modern systems with cgroup v2 or systemd, alternatives like systemd-run are preferred for unified delegation.

CAVEATS

Deprecated on systems using cgroup v2 or systemd (use systemd-run); requires libcgroup-tools; paths relative to cgroup root; may fail if cgroup hierarchies are not mounted.

EXAMPLE

cgexec -g memory:/mygroup stress --cpu 2
Runs stress in the memory cgroup at /mygroup.

HISTORY

Introduced in libcgroup ~2008 for early cgroup v1 support in kernel 2.6.24+; maintained until ~2016, now unmaintained as systemd absorbed cgroup management.

SEE ALSO

cgclassify(1), cgcreate(1), cgrulesengd(8), systemd-run(1), systemd-cgtop(1)

Copied to clipboard