cht電腦資訊Linux
adm Find login register

限制 CPU 使用率的工具 - cpulimit

coolcd
joined: 2008-01-21
posted: 2596
promoted: 348
bookmarked: 95
1subject: 限制 CPU 使用率的工具 - cpulimitPromote 3 Bookmark 12010-01-11quote  

CPULIMIT

cpulimit 可限制指定程式的 CPU 使用率

在 Debian 中的安裝方式

# aptitude install cpulimit

語法簡介

$ sudo cpulimit [-e EXECUTABLE|-p PID|-P ABSOLUTE_PATH_TO_EXECUTABLE] [-l LIMIT]
  • 目標程式可用三種方式指定,用 -e 指定執行檔的名稱,用 -p 指定 PID,或 -P 指定絕對路徑
  • CPU 使用率的限制,用 -l 指定,-l 後面直接輸入整數即可,代表百分率

例子

限制 PID 為 10796 的 process CPU 使用率為 50%

$ sudo cpulimit -p 10796 -l 50
Process 10796 detected

限制 firefox 的 CPU 使用率為 50%

$ sudo cpulimit -e firefox-bin -l 50
Warning: no target process found. Waiting for it..

奇怪,抓不到?

$ ls -l /usr/lib/iceweasel/firefox-bin
lrwxrwxrwx 1 root root 31 2009-12-01 03:00 /usr/lib/iceweasel/firefox-bin -> ../xulrunner-1.9/xulrunner-stub
$ sudo cpulimit -e xulrunner-stub -l 50
Process 10796 detected

這次抓到了。所以,cpulimit 對 softlink 無效,必需找出 softlink 的 target。

參考資訊:

How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu)

cht電腦資訊Linux
adm Find login register
views:5350