CPULimit是一个简单的程序,用于限制Linux中某些应用程序的CPU使用率。 默认情况下,它位于Ubuntu存储库中。 我们可以通过在Ubuntu中发出以下命令来安装它
sudo apt-get install cpulimit
输出量
mkyong@mkyong:~$ sudo apt-get install cpulimit
[sudo] password for mkyong:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-2.6.28-11 linux-headers-2.6.28-11-generic
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
cpulimit
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 9730B of archives.
After this operation, 65.5kB of additional disk space will be used.
Get:1 http://my.archive.ubuntu.com jaunty/universe cpulimit 1.1-11 [9730B]
Fetched 9730B in 1s (8940B/s)
Selecting previously deselected package cpulimit.
(Reading database ... 131942 files and directories currently installed.)
Unpacking cpulimit (from .../cpulimit_1.1-11_i386.deb) ...
Processing triggers for man-db ...
Setting up cpulimit (1.1-11) ...
mkyong@mkyong:~$
我们可以通过可执行文件名称或进程ID(pid)限制应用程序CPU使用率。 例如,我们有一个用python编写的cron作业(名称= mycronjob.py,pid = 1234)
通过可执行文件名将进程“ mycronjob.py”限制为50%CPU使用率
cpulimit -e mycronjob.py -l 50
通过PID(1234)将进程限制为50%CPU:
cpulimit -p 1234 -l 50
这个程序非常有用,可以防止某些应用程序占用我们所有的CPU使用率。
翻译自: https://mkyong.com/linux/how-to-limit-the-application-cpu-usage-in-linux-cpulimit/