Product SiteDocumentation Site

2.8. Moving a Process to a Control Group

Move a process into a cgroup by running the cgclassify command:
~]# cgclassify -g cpu,memory:group1 1701
The syntax for cgclassify is:
cgclassify -g subsystems:path_to_cgroup pidlist
You can also add the --sticky option before the pid to keep any child processes in the same cgroup. If you do not set this option and the cgred daemon is running, child processes will be allocated to cgroups based on the settings found in /etc/cgrules.conf. The process itself, however, will remain in the cgroup 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 cgroup 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 cgroup directly, write its PID to the tasks file of the cgroup. For example, to move a process with the PID 1701 into a cgroup at /cgroup/lab1/group1/:
~]# echo 1701 > /cgroup/lab1/group1/tasks

2.8.1. The cgred Daemon

Cgred is a daemon that moves tasks into cgroups 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 subsystems control_group
  • user:command subsystems 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 cgroup. To associate particular commands with particular cgroups, 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 cgroup in the hierarchy that contains the devices subsystem. Note, however, that the daemon moves the process to the cgroup 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		%		%