Linux Control Groups, commonly referred to as cgroups, is a feature in the Linux kernel that provides a way to organise and manage system resources for processes. It allows you to allocate and limit resources like CPU, memory, and I/O bandwidth among different processes or groups of processes.
There are two versions of cgroups, the original version 1 and the `unified`, version 2.
User `<forza>` can now create new nested cgroups in `/sys/fs/cgroup/user/forza` and attach processes to it.
The catch-22 of cgroups is that all programs by default reside in in the root `/sys/fs/cgroup/cgroup.procs`, and even though a user can write to its own cgroup, they can not remove themselves from the root cgroup.
One solution is to let the user start a `screen` or `tmux` session and then use root/sudo to move it to the user's cgroup.
Then as root, check what `pids` belong to the uaer session and add them to the user cgroup:
Now, the user's screen session is in the `main` cgroup and the user can create additional cgroups and move processes started from within this session to that cgroup.
The `user_cgroup` helper utility can automate the process of setting of user cgroups.
-`user_cgroup.initd` is an OpenRC init script that creates a cgroup hierarchy for specified users.
-`user_cgroup.confd` is the configuration file for OpenRC.
-`user_cgroup.sudoersd` is a sudo config file for allowing users to use the `user_cgroup` utility.
-`user_cgroup` small tool to move a uaer's shell to the user cgroup.
The sudo file is optional, but allows a user to put the script in `~/.bash_profile` for automatic use.
Once installed, a user can simply run `user_cgroup` to move itselslf to the user cgroup. Now it is possible for the user to create its own sub cgroups with `cgexec`.