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
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
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.9. Starting a Process in a Control Group

Important — Mandatory parameters

Some controllers have mandatory parameters that you must set before you run a task in a hierarchy that includes those controllers. For example, before you use the cpuset controller, cpuset.cpus and cpuset.mems must be defined.
The examples in this section illustrate the correct syntax for the command, but only work on systems on which the relevant mandatory parameters have been set for any controllers used in the examples. If you have not already configured the relevant controllers, you cannot copy example commands directly from this section and expect them to work on your system.
Refer to Section 3.10, “Additional Resources” for a description of which parameters are mandatory for given subsystems.
Launch processes in a control group by running the cgexec command. For example, this command launches the lynx web browser within the group1 control group, subject to the limitations imposed on that group by the cpu subsystem:
cgexec -g cpu:group1 lynx https://www.redhat.com
The syntax for cgexec is: cgexec -g subsystems:path_to_cgroup command arguements , where:
  • 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 cgset described in Section 2.7, “Setting Parameters”, if control groups of the same name exist in multiple hierarchies, the -g option 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 control group relative to the hierarchy.
  • command is the command to run
  • arguements are any arguements for the command
You can also add the --sticky option before the command 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.

Alternative method

When you start a new process, it inherits the group of its parent process. Therefore, an alternative method for starting a process in a particular control group is to move your shell process to that group (refer to Section 2.8, “Moving a Process to a Control Group”), and then launch the process from that shell. For example:
echo $$ > /cgroup/lab1/group1/tasks
lynx
Note that after exiting lynx, your existing shell is still in the group1 control group. Therefore, an even better way would be:
sh -c "echo \$$ > /cgroup/lab1/group1/tasks && lynx"

2.9.1. Starting a Service in a Control Group

You can start some services in a control group. Services that can be started in control groups must:
  • use a /etc/sysconfig/servicename file
  • use the daemon() function from /etc/init.d/functions to start the service
To make an eligible service start in a control group, edit its file in the /etc/sysconfig directory 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 control group in that hierarchy. For example:
CGROUP_DAEMON="cpuset:daemons/sql"

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