Product SiteDocumentation Site

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:
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		%		%