Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux cpulimit 限制程序 CPU 使用率教學:安裝、依程式名/ PID/ 絕對路徑限制、單核與多核使用率換算、nice/renice 相關工具

編輯:Linux 教學

Linux 系統後台程式佔用過多 CPU 導致卡頓時,可用 cpulimit 依百分比限制特定程序 CPU 使用率。本文涵蓋原始碼編譯安裝、apt-get 安裝、三種鎖定方式 (程式名、PID、絕對路徑)、多核心使用率換算、nice/renice 優先序調整工具。

安裝 cpulimit

原始碼編譯

cd /tmp
wget https://downloads.sourceforge.net/cpulimit/cpulimit-1.1.tar.gz
tar zxvf cpulimit-1.1.tar.gz
cd cpulimit-1.1
make
cp cpulimit /usr/local/sbin/
rm -rf cpulimit*

Debian/Ubuntu

sudo apt-get update
sudo apt-get install cpulimit

使用範例

  • 限制 firefox 30%:cpulimit -e firefox -l 30
  • 限制 PID 1313 30%:cpulimit -p 1313 -l 30
  • 依絕對路徑:cpulimit -P /opt/firefox/firefox -l 30

查詢 PID 方法

ps aux | grep firefox
pgrep -u vivek php-cgi
pgrep lighttpd

單核 vs 多核使用率換算

  • 單核:0%~100%
  • 四核:0%~400% (cpulimit 參數仍以單核百分比為基準,-l 30 表示限制單核 30%,四核總和上限 120%)

相關工具

  • nice:指定優先序啟動程式
  • renice:調整執行中程式優先序

cpulimit 適合限制失控程式;nice/renice 適合調度優先序,兩者可搭配使用。

Copyright © Windows教程網 All Rights Reserved