zoukankan      html  css  js  c++  java
  • Cpulimit---控制cpu百分比

    有一次,apche httpd进程cpu满100%了,后来发现下面的文章,然后转过来用了

    安装CPU Usage Limiter for Linux

    What is it?
    cpulimit is a simple program that attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. Also, it is able to adapt itself to the overall system load, dynamically and quickly.
    可以限制程序使用CPU的百分比,而不是时间.很好,很舒服.

    开始安装吧.

    官方地址:http://cpulimit.sourceforge.net/

    cd /root/install/ 
    svn checkout https://cpulimit.svn.sourceforge.net/svnroot/cpulimit/trunk cpulimit 

    cd cpulimit 
    make 

    cp ./cpulimit /usr/sbin

    限制方法:

    如果限制进程名,比如将httpd这个进程名的CPU限制在40%

    cpulimit --exe httpd --limit 40 
    cpulimit --exe /usr/local/bin/httpd --limit 40

    将pid为2960的进程的CPU限制在55%

    cpulimit --pid 2960 --limit 55

    慢慢对比top 命令那里的CPU变化.嘿嘿,有效果了吧?.

    再来个完美的

    自动限制当前进程使用CPU超过20%的进程,将他限制为10%

    cpulimit --pid `ps aux|awk '{if($3 > 20) print $2}'` --limit 10

    cpulimit命令:

    Error: You must specify a target process, by name or by PID
    Usage: cpulimit TARGET [OPTIONS...]
       TARGET must be exactly one of these:
          -p, --pid=N        pid of the process (implies -z)
          -e, --exe=FILE     name of the executable program file or absolute path name
       OPTIONS
          -l, --limit=N      percentage of cpu allowed from 0 to 100 (required)
          -v, --verbose      show control statistics
          -z, --lazy         exit if there is no suitable target process, or if it dies
          -h, --help         display this help and exit

  • 相关阅读:
    Alpha阶段项目展示
    Alpha阶段测试报告
    300种常用非处方中成药--06骨伤科用药/07皮肤科用药
    300种常用非处方中成药--05五官科用药
    300种常用非处方中成药--04儿科用药
    300种常用非处方中成药--02外科用药/03妇科用药
    300种常用非处方中成药-01内科用药
    文科思人,理科格物
    谁动我的奶酪--经典句子
    博士 水上飘
  • 原文地址:https://www.cnblogs.com/waterfox/p/3625187.html
Copyright © 2011-2022 走看看