2.9. Starting a Process in a Control Group
cpuset.memsparameters must be defined for that cgroup.
cgexeccommand. For example, this command launches the firefox web browser within the
group1cgroup, subject to the limitations imposed on that group by the
cgexec -g cpu:group1 firefox http://www.redhat.com
-gsubsystems:path_to_cgroup command arguments
- subsystems is a comma‑separated list of subsystems, or
*to launch the process in the hierarchies associated with all available subsystems. Note that, as with
cgsetdescribed in Section 2.7, “Setting Parameters”, if cgroups of the same name exist in multiple hierarchies, the
-goption creates 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 cgroup relative to the hierarchy.
- command is the command to run.
- arguments are any arguments for the command.
--stickyoption before the command to keep any child processes in the same cgroup. If you do not set this option and the cgred service 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.
echo $$ > /cgroup/cpu_and_mem/group1/tasks~]#
group1cgroup. Therefore, an even better way would be:
sh -c "echo \$$ > /cgroup/cpu_and_mem/group1/tasks && firefox"
2.9.1. Starting a Service in a Control Group
- use a
- use the
/etc/init.d/functionsto start the service
/etc/sysconfigdirectory to include an entry in the form
CGROUP_DAEMON="subsystem:control_group"where subsystem is a subsystem associated with a particular hierarchy, and control_group is a cgroup in that hierarchy. For example:
cpusetis mounted to
/cgroup/cpu_and_mem/, the above configuration translates to
2.9.2. Process Behavior in the Root Control Group
cpuconfiguration options affect processes (tasks) running in the root cgroup in a different way than those in a subgroup. Consider the following example:
- Create two subgroups under one root group:
- In each subgroup and in the root group, define the
cpu.sharesconfiguration option and set it to
/rootgroup/blue/tasks) consumes 33.33% of the CPU:
redresult in the 33.33% percent of the CPU assigned to that specific subgroup to be split among the multiple processes in that subgroup.
/rootgroup/contains three processes,
/rootgroup/red/contains one process and
/rootgroup/blue/contains one process, and the
cpu.sharesoption is set to
1in all groups, the CPU resource is divided as follows:
/rootgroup/processes: 20% + 20% + 20%
cpuconfiguration options which divide an available resource based on a weight or a share (for example,
blkio.weight). To move all tasks from the root group into a specific subgroup, you can use the following commands:
cat tasks >> red/tasksrootgroup]#
echo > tasks