Stories

Detail Return Return

Linux使用cpulimit對CPU使用率進行限制 - Stories Detail

介紹

cpulimit是一款可以對CPU使用率進行限制的軟件,既可限制單個特定程序,也可以對整個CPU使用率進行限制,安裝使用都很方便,需要的朋友可以試試。

源安裝(推薦)

Centos:

yum install cpulimit

Debian / Ubuntu:

apt-get install -y cpulimit

編譯安裝

cd /tmp
wget 'https://www.02405.com/wp-content/uploads/2022/12/cpulimit-1.1.tar.gz'
tar cpulimit-1.1.tar.gz
cd cpulimit-1.1
make
cp cpulimit  /usr/local/sbin/
rm -rf cpulimit*

使用實例

限制程序名為xmrig的程序僅使用60%的CPU使用率,並在後台一直運行;
cpulimit -e xmrig -l 60 -b
限制進程號為10086的程序僅使用60%的CPU利用率,並在後台一直運行;
cpulimit -p 10086 -l 60 -b
限制絕對路徑下的軟件僅使用60%的CPU利用率,並在後台一直運行;
cpulimit -e /usr/local/nginx/sbin/nginx -l 60 -b
關閉cpulimit後台進程(取消所有限制)
kill $(pidof cpulimit)

使用説明

-P –pid=N pid of the process 進程的PID
-e –exe=FILE name of the executable program file 可執行程序文件名
-P –path=PATH absolute path name of the 進程的絕對路徑名
-b –background run in background 後台運行
-l –limit=N percentage of cpu allowed from 1 up 允許的CPU百分比,最低為1%
-z –lazy exit if there is no suitable target process 如果目標進程退出或無目標進程則終止
-h –help display this help and exit 顯示幫助並退出

注意事項

  • 限制CPU的百分比按照實際的CPU數量而定,比如單核最高為100%,雙核最高為200%,三核最高為300%,以此類推即可;
  • ROOT用户可以限制所有的進程,普通用户只能限制用户有權限管理的進程。
user avatar zhanwang Avatar veronicaaa Avatar shiluodexiaomaju Avatar abelethan Avatar yuezhang_5e5e7da0beeea Avatar
Favorites 5 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.