Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Red Hat Enterprise Linux 9 Essentials Book now available.

Purchase a copy of Red Hat Enterprise Linux 9 (RHEL 9) Essentials

Red Hat Enterprise Linux 9 Essentials Print and eBook (PDF) editions contain 34 chapters and 298 pages

Preview Book

2.8. Moving a Process to a Control Group

Move a process into a control group by running the cgclassify command:
cgclassify -g cpu,memory:group1 1701
The syntax for cgclassify is: cgclassify -g subsystems:path_to_cgroup pidlist, where:
  • subsystems is a comma-separated list of subsystems, or * to launch the process in the hierarchies associated with all available subsystems. Note that if control groups of the same name exist in multiple hierarchies, the -g option moves the processes in each of those groups. Ensure that the cgroup exists within each of the hierarchies whose subsystems you specify here.
  • path_to_cgroup is the path to the control group within its hierarchies
  • pidlist is a space-separated list of process identifier (PIDs)
You can also add the --sticky option before the pid to keep any child processes in the same control group. If you do not set this option and the cgred daemon is running, child processes will be allocated to control groups based on the settings found in /etc/cgrules.conf. The process itself, however, will remain in the control group in which you started it.
Using cgclassify, you can move several processes simultaneously. For example, this command moves the processes with PIDs 1701 and 1138 into control group group1/:
cgclassify -g cpu,memory:group1 1701 1138
Note that the PIDs to be moved are separated by spaces and that the groups specified should be in different hierarchies.

Alternative method

To move a process into a control group directly, write its PID to the tasks file of the control group. For example, to move a process with the PID 1701 into a control group at /cgroup/lab1/group1/:
echo 1701 > /cgroup/lab1/group1/tasks

2.8.1. The cgred Daemon

Cgred is a daemon that moves tasks into control groups according to parameters set in the /etc/cgrules.conf file. Entries in the /etc/cgrules.conf file can take one of the two forms:
  • user hierarchies control_group
  • user:command hierarchies control_group
For example:
maria                   devices         /usergroup/staff
This entry specifies that any processes that belong to the user named maria access the devices subsystem according to the parameters specified in the /usergroup/staff control group. To associate particular commands with particular control groups, add the command parameter, as follows:
maria:ftp               devices         /usergroup/staff/ftp
The entry now specifies that when the user named maria uses the ftp command, the process is automatically moved to the /usergroup/staff/ftp control group in the hierarchy that contains the devices subsystem. Note, however, that the daemon moves the process to the control group only after the appropriate condition is fulfilled. Therefore, the ftp process might run for a short time in the wrong group. Furthermore, if the process quickly spawns children while in the wrong group, these children might not be moved.
Entries in the /etc/cgrules.conf file can include the following extra notation:
  • @ — when prefixed to user, indicates a group instead of an individual user. For example, @admins are all users in the admins group.
  • * — represents "all". For example, * in the subsystem field represents all subsystems.
  • % — represents an item the same as the item in the line above. For example:
    @adminstaff             devices         /admingroup
    @labstaff               %               %

  Published under the terms of the Creative Commons License Design by Interspire