作用:增加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