作用:增加CPU使用率到指定范围
1、书写shell脚本增加CPU压力
#! /bin/bash # filename cputest.sh endless_loop() { echo -ne "i=0; while true do i=i+100; i=100 done" | /bin/bash & } if [ $# != 1 ] ; then echo "USAGE: $0 <CPUs>" exit 1; fi for i in `seq $1` do endless_loop pid_array[$i]=$! ; done for i in "${pid_array[@]}"; do echo 'kill ' $i ';'; done
2、安装cpulimit-master工具,限制CPU使用情况
1、下载:
wget https://github.com/opsengine/cpulimit/archive/master.zip
2、解压
unzip cpulimit.zip
3、编译
cd cpulimit-master make
4、创建快捷方式
cp src/cpulimit /usr/bin
5、使用
1)限制进程号的程序使用40% cpu利用率
cpulimit -p 1313 -l 40
2)限制程序google使用40% cpu利用率
cpulimit -e google -l 40