cgroup限制进程cpu

编写一个死循环脚本

[root@workstation ~]# cat circle.sh 
#!/bin/bash
a=1
while true
do
	let a++
done

查看top

使用cgroup进行资源控制

[root@workstation cpu]# mkdir supermao_t
[root@workstation cpu]# pwd
/sys/fs/cgroup/cpu
[root@workstation cpu]# cd supermao_t/
[root@workstation supermao_t]# ls
cgroup.clone_children  cpuacct.usage_percpu       cpu.cfs_period_us  cpu.stat
cgroup.procs           cpuacct.usage_percpu_sys   cpu.cfs_quota_us   notify_on_release
cpuacct.stat           cpuacct.usage_percpu_user  cpu.rt_period_us   tasks
cpuacct.usage          cpuacct.usage_sys          cpu.rt_runtime_us
cpuacct.usage_all      cpuacct.usage_user         cpu.shares        
[root@workstation supermao_t]# echo 20000 > /sys/fs/cgroup/cpu/supermao_t/cpu.cfs_quota_us 
[root@workstation supermao_t]# 

3539为进程pid
[root@workstation supermao_t]# echo 3539 > /sys/fs/cgroup/cpu/supermao_t/tasks

rmdir 可以删除内存文件夹

posted @ 2022-12-17 12:03  supermao12  阅读(117)  评论(0编辑  收藏  举报