在没有要求的详细信息的情况下...
这是我在ubuntu上使用cgroups的方法。
在整个本文中,您需要将变量“ $ USER”更改为运行流程的用户
我添加了内存信息,这将是一个常见问题解答,如果您不需要它,请不要使用它。
1)安装 cgroup-bin
sudo apt-get install cgroup-bin
2)重新启动。cgroups现在位于/sys/fs/cgroup
3)为您的用户(进程的所有者)创建一个cgroup
# Change $USER to the system user running your process.
sudo cgcreate -a $USER -g memory,cpu:$USER
4)您的用户可以让他们管理资源。默认情况下,用户获得1024个cpu单位(份额),因此限制为大约10%cpu,内存以字节为单位...
# About 10 % cpu
echo 100 > /cgroup/cpu/$USER/cpu.shares
# 10 Mb
echo 10000000 > /cgroup/memory/$USER/memory.limit_in_bytes
5)开始您的进程(将exec更改为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> &
组态
假设cgroup正在为您工作;)
编辑/etc/cgconfig.conf
,添加自定义cgroup
# Graphical
gksudo gedit /etc/cgconfig.conf
# Command line
sudo -e /etc/cgconfig.conf
添加您的cgroup。再次将$ USER更改为拥有该进程的用户名。
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;
}
}
您也可以指定组gid=$GROUP
,/etc/cgconfig.conf的注释很好。
现在再次使用 cgexec -g cpu:$USER command <options>
您可以在以下位置看到您的过程(通过PID) /sys/fs/cgroup/cpu/$USER/tasks
例
bodhi @ ufbt:〜$ cgexec -g cpu:bodhi sleep 100&
[1] 1499
bodhi @ ufbt:〜$ cat / sys / fs / cgroup / cpu / bodhi / tasks
1499
有关更多信息,请参见:http :
//docs.redhat.com/docs/zh-CN/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/