In the absence of requested details ...
Here is how I use cgroups on ubuntu.
Throughout this post, you will need to change the variable "$USER" to the user running the process
I added information for memory as well as that is going to be a FAQ, if you do not need it do not use it.
1) Install cgroup-bin
sudo apt-get install cgroup-bin
2) Reboot. cgroups is now located at /sys/fs/cgroup
3) Make a cgroup for your user (the owner of the process)
# Change $USER to the system user running your process.
sudo cgcreate -a $USER -g memory,cpu:$USER
4) Your user can them manage resources. By default users get 1024 cpu units (shares), so to limit to about 10 % cpu , memory is in bytes ...
# About 10 % cpu
echo 100 > /cgroup/cpu/$USER/cpu.shares
# 10 Mb
echo 10000000 > /cgroup/memory/$USER/memory.limit_in_bytes
5) Start your process (change exec to cgexec)
# -g specifies the control group to run the process in
# Limit cpu
cgexec -g cpu:$USER command <options> &
# Limit cpu and memory
cgexec -g memory,cpu:$USER command <options> &
Configuration
Assuming cgroups are working for you ;)
Edit /etc/cgconfig.conf
, add in your custom cgroup
# Graphical
gksudo gedit /etc/cgconfig.conf
# Command line
sudo -e /etc/cgconfig.conf
Add in your cgroup. Again change $USER to the user name owning the process.
group $USER {
# Specify which users can admin (set limits) the group
perm {
admin {
uid = $USER;
}
# Specify which users can add tasks to this group
task {
uid = $USER;
}
}
# Set the cpu and memory limits for this group
cpu {
cpu.shares = 100;
}
memory {
memory.limit_in_bytes = 10000000;
}
}
You can also specify groups gid=$GROUP
, /etc/cgconfig.conf is well commented.
Now again run your process with cgexec -g cpu:$USER command <options>
You can see your process (by PID) in /sys/fs/cgroup/cpu/$USER/tasks
Example
bodhi@ufbt:~$ cgexec -g cpu:bodhi sleep 100 &
[1] 1499
bodhi@ufbt:~$ cat /sys/fs/cgroup/cpu/bodhi/tasks
1499
For additional information see:
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/
cgsnapshot -s
to retrieve the information without writing the configuration file manually, the latter of which is not recommended.