如何在Linux中限制应用程序CPU使用率(CPUlimit)

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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值