LinuxCommandLibrary

cgcreate

Create new control groups

TLDR

Create a new group

$ cgcreate -g [group_type]:[group_name]
copy

Create a new group with multiple cgroup types
$ cgcreate -g [group_type1],[group_type2]:[group_name]
copy

Create a subgroup
$ mkdir /sys/fs/cgroup/[group_type]/[group_name]/[subgroup_name]
copy

SYNOPSIS

cgcreate [-t owner:group] [-a owner:group] [-g controllers:path]

PARAMETERS

-t owner:group
    Specifies the owner and group for the tasks file in the created cgroup. owner and group are the user and group names or IDs. This setting determines which user or group has permission to add tasks to this cgroup.

-a owner:group
    Specifies the owner and group for the administrative files in the created cgroup. owner and group are the user and group names or IDs. This setting determines who can modify the cgroup's parameters using commands like cgset.

-g controllers:path
    Specifies the controllers (subsystems) to be attached to the cgroup and the path where the cgroup should be created. The controllers are a comma-separated list of subsystems (e.g., 'cpu,memory') and path is the absolute path within the cgroup hierarchy (e.g., '/mygroup').

DESCRIPTION

The cgcreate command is used to create new control groups (cgroups) within the Linux kernel. Cgroups are a powerful mechanism for resource management, allowing you to limit, isolate, and monitor the resource usage (CPU, memory, I/O, etc.) of groups of processes. Using cgcreate requires understanding the cgroup hierarchy and desired resource limits. Cgroups are organized in a hierarchical structure, and cgcreate adds new groups to this tree. The user typically specifies the path where the new cgroup should be located, along with the controllers (subsystems) that should be attached to it. Proper configuration often involves creating a cgroup and then setting resource limits via cgset. cgcreate alone only creates the directory structure, the configuration is completed using other commands such as cgset and cgconfigparser. You need the appropriate permissions to create cgroups, usually root privileges. Without proper configuration tools using cgcreate alone will not provide any resource management.

CAVEATS

Requires root privileges or appropriate cgroup permissions. Incorrect paths can lead to unexpected behavior. Cgroups v2 is the current implementation, but this command usually refers to the v1 implementation.

CONTROLLERS

Common controllers include: cpu (CPU time allocation), memory (memory usage limits), blkio (block I/O control), cpuset (CPU and memory affinity), devices (device access control), freezer (pausing/resuming processes), and net_cls (network traffic classification).

Each controller manages a specific type of resource.

CGROUP HIERARCHY

Cgroups are organized as a filesystem hierarchy. cgcreate creates directories within this hierarchy. The root of the hierarchy is typically mounted at /sys/fs/cgroup or a similar location, but this location may vary by distribution.

HISTORY

The cgcreate command is part of the cgroup-tools package, which was developed to provide a set of utilities for managing Linux control groups. Its primary purpose was to simplify the creation and management of cgroups, offering a command-line interface to the underlying cgroup filesystem. It was primarily designed for cgroups v1, older implementations of cgroups.

SEE ALSO

cgset(1), cgexec(1), cgconfigparser(1)

Copied to clipboard