zoukankan      html  css  js  c++  java
  • Linux每隔1秒kill掉cpu大于50%的进程

    1.新建/test/killcpu.sh shell脚本 并授予权限0755
    #!/bin/bash
    ps axf -o "pid %cpu" | awk '{if($2>=50.0) print $1}' | while read procid
    do
    kill -9 $procid
    done

    2.安装crontab
    yum -y install vixie-cron
    3.查看定时任务 crontab -l
    4.添加定时任务 crontab -e

    分  时  日  月  周  命令
    第1列表示分钟1~59 每分钟用*或者 */1表示
    第2列表示小时1~23(0表示0点)
    第3列表示日期1~31
    第4列表示月份1~12
    第5列标识号星期0~6(0表示星期天)
    第6列要运行的命令
    ## For excuting killcpu.sh every 3 seconds##on 2017-03-09 每3秒执行脚本
    */1 * * * * /test/killcpu.sh
    */1 * * * * sleep 3 && /test/killcpu.sh
    */1 * * * * sleep 6 && /test/killcpu.sh
    */1 * * * * sleep 9 && /test/killcpu.sh
    */1 * * * * sleep 12 && /test/killcpu.sh
    */1 * * * * sleep 15 && /test/killcpu.sh
    */1 * * * * sleep 18 && /test/killcpu.sh
    */1 * * * * sleep 21 && /test/killcpu.sh
    */1 * * * * sleep 24 && /test/killcpu.sh
    */1 * * * * sleep 27 && /test/killcpu.sh
    */1 * * * * sleep 30 && /test/killcpu.sh
    */1 * * * * sleep 33 && /test/killcpu.sh
    */1 * * * * sleep 36 && /test/killcpu.sh
    */1 * * * * sleep 39 && /test/killcpu.sh
    */1 * * * * sleep 42 && /test/killcpu.sh
    */1 * * * * sleep 45 && /test/killcpu.sh
    */1 * * * * sleep 48 && /test/killcpu.sh
    */1 * * * * sleep 51 && /test/killcpu.sh
    */1 * * * * sleep 54 && /test/killcpu.sh
    */1 * * * * sleep 57 && /test/killcpu.sh
    #-----------------------------------------------------------------

    ## For excuting killcpu.sh every 1 seconds##on 2017-03-09 每1秒执行脚本
    */1 * * * * /test/killcpu.sh
    */1 * * * * sleep 1 && /test/killcpu.sh
    */1 * * * * sleep 2 && /test/killcpu.sh
    */1 * * * * sleep 3 && /test/killcpu.sh
    */1 * * * * sleep 4 && /test/killcpu.sh
    */1 * * * * sleep 5 && /test/killcpu.sh
    */1 * * * * sleep 6 && /test/killcpu.sh
    */1 * * * * sleep 7 && /test/killcpu.sh
    */1 * * * * sleep 8 && /test/killcpu.sh
    */1 * * * * sleep 9 && /test/killcpu.sh
    */1 * * * * sleep 10 && /test/killcpu.sh
    */1 * * * * sleep 11 && /test/killcpu.sh
    */1 * * * * sleep 12 && /test/killcpu.sh
    */1 * * * * sleep 13 && /test/killcpu.sh
    */1 * * * * sleep 14 && /test/killcpu.sh
    */1 * * * * sleep 15 && /test/killcpu.sh
    */1 * * * * sleep 16 && /test/killcpu.sh
    */1 * * * * sleep 17 && /test/killcpu.sh
    */1 * * * * sleep 18 && /test/killcpu.sh
    */1 * * * * sleep 19 && /test/killcpu.sh
    */1 * * * * sleep 20 && /test/killcpu.sh
    */1 * * * * sleep 21 && /test/killcpu.sh
    */1 * * * * sleep 22 && /test/killcpu.sh
    */1 * * * * sleep 23 && /test/killcpu.sh
    */1 * * * * sleep 24 && /test/killcpu.sh
    */1 * * * * sleep 25 && /test/killcpu.sh
    */1 * * * * sleep 26 && /test/killcpu.sh
    */1 * * * * sleep 27 && /test/killcpu.sh
    */1 * * * * sleep 28 && /test/killcpu.sh
    */1 * * * * sleep 29 && /test/killcpu.sh
    */1 * * * * sleep 30 && /test/killcpu.sh
    */1 * * * * sleep 31 && /test/killcpu.sh
    */1 * * * * sleep 32 && /test/killcpu.sh
    */1 * * * * sleep 33 && /test/killcpu.sh
    */1 * * * * sleep 34 && /test/killcpu.sh
    */1 * * * * sleep 35 && /test/killcpu.sh
    */1 * * * * sleep 36 && /test/killcpu.sh
    */1 * * * * sleep 37 && /test/killcpu.sh
    */1 * * * * sleep 38 && /test/killcpu.sh
    */1 * * * * sleep 39 && /test/killcpu.sh
    */1 * * * * sleep 40 && /test/killcpu.sh
    */1 * * * * sleep 41 && /test/killcpu.sh
    */1 * * * * sleep 42 && /test/killcpu.sh
    */1 * * * * sleep 43 && /test/killcpu.sh
    */1 * * * * sleep 44 && /test/killcpu.sh
    */1 * * * * sleep 45 && /test/killcpu.sh
    */1 * * * * sleep 46 && /test/killcpu.sh
    */1 * * * * sleep 47 && /test/killcpu.sh
    */1 * * * * sleep 48 && /test/killcpu.sh
    */1 * * * * sleep 49 && /test/killcpu.sh
    */1 * * * * sleep 50 && /test/killcpu.sh
    */1 * * * * sleep 51 && /test/killcpu.sh
    */1 * * * * sleep 52 && /test/killcpu.sh
    */1 * * * * sleep 53 && /test/killcpu.sh
    */1 * * * * sleep 54 && /test/killcpu.sh
    */1 * * * * sleep 55 && /test/killcpu.sh
    */1 * * * * sleep 56 && /test/killcpu.sh
    */1 * * * * sleep 57 && /test/killcpu.sh
    */1 * * * * sleep 58 && /test/killcpu.sh
    */1 * * * * sleep 59 && /test/killcpu.sh
    #-----------------------------------------------------------------
    5.重启服务 service crond restart
    6.添加开机启动 chkconfig --list crond
    7.查看开机启动服务 chkconfig

  • 相关阅读:
    u-boot器件驱动模型(Device&Drivers)之uclass (转)
    u-boot下的DM驱动模型 阶梯状 (转)
    u-boot-2018.09 DTS上 I2C节点的解析 (转)
    [uboot] (番外篇)uboot串口&console&stdio设备工作流程 (转)
    [uboot] (番外篇)uboot 驱动模型(转)重要
    u-boot DM初始化流程
    【u-boot】u-boot中initf_dm()函数执行流程(转)
    【u-boot】u-boot对设备树的节点解析(转)
    BeanPostProcessor
    一些压力测试结果(Mysql,Zookeeper,Redis,Mongodb)
  • 原文地址:https://www.cnblogs.com/liruning/p/6526433.html
Copyright © 2011-2022 走看看