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

Linux每隔1秒kill掉cpu大于50%的进程的更多相关文章

  1. 【每天一条Linux指令-Day1】kill掉多个mysql的进程

    我被问到过一个shell的问题,问的是如何kill掉多个mysql的进程? 怎么把这个的pid传递下去 ps -ef|grep mysql | xargs kill -9 ps -ef|grep my ...

  2. mysql中kill掉所有锁表的进程

    --mysql中kill掉所有锁表的进程 --------------------------------2014/05/20 在数据库的管理中,我们经常会碰到锁表的问题,看一下进程列表. mysql ...

  3. 找出 alter system kill session ‘sid,serial#’ kill 掉的数据库会话对应进程

    当我们使用alter system kill session ‘sid,serial#’ 在数据库中kill掉某个会话的时候,如果你观察仔细会发现v$session.paddr发生了改变,从而是的不能 ...

  4. 批量kill掉包含某个关键字的进程

    需要把 linux 下符合某一项条件的所有进程 kill 掉,又不能用 killall 直接杀掉某一进程名称包含的所有运行中进程(我们可能只需要杀掉其中的某一类或运行指定参数命令的进程),这个时候我们 ...

  5. linux 查看占用端口并kill掉

    主要可以使用ps  命令 或 netstat 命令 weihong@data1:~/jd_parser/jd_parser$ ps aux | head USER PID %CPU %MEM VSZ ...

  6. linux 因内存不足而 kill 掉 java 程序

    grep "Out of memory" /var/log/messages Sep 17 16:13:34 xxxaaa kernel: Out of memory: Kill ...

  7. linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现

    linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现?快速清理木马流程.假设木马的名字是xysbqaxjqy,如果top看不到,可以在/etc/init.d目 ...

  8. 编写shell脚本kill掉占用cpu超过90%以上的程序

    由于集群用户经常会不懂如何提交作业,将作业直接运行到登录节点上,这样导致登录节点的cpu及内存占用很大,导致其他用户甚至无法登录.所以就想到了一种解决方法,写一个shell脚本,常驻登录节点,监控cp ...

  9. 【shell脚本实例】一个恶作剧—— kill掉占用CPU较高的matlab进程

    我们实验室有台服务器,博士们在服务器上跑MATLAB,基本都是4核都是超过95%的CPU占用,想了个恶作剧的shell 定时kill掉MATLAB程序,是不是很邪恶啊,哈哈~~~  不过我只是干过一次 ...

随机推荐

  1. Flutter移动电商实战 --(45)详细页_说明区域UI编写

    pages/details_page/details_expain.dart 详情页面引用组件 效果展示: 最终代码: import 'package:flutter/material.dart'; ...

  2. Spring Boot项目跳转不到jsp页面是怎么回事

    SpringBoot访问不了JSP但却能进入后台 一直报错: 解决方法: 改成下面的

  3. python @abstractmethod

    1.写在前面 由于python 没有抽象类.接口的概念,所以要实现这种功能得abc.py 这个类库 2.@abstractmethod特点 @abstractmethod:抽象方法,含abstract ...

  4. phpstorm设置最多标签数

    在settings=>Editor=>General=>Editor Tabs的Tab limit下可以设置当前窗口能够打开的最多标签数目,默认是10,超过设定值时,会自动关闭前面的 ...

  5. 03--STL算法(常用算法)

    一:常用的查找算法 (一)adjacent_find():邻接查找 在iterator对标识元素范围内,查找一对相邻重复元素,找到则返回指向这对元素的第一个元素的迭代器.否则返回past-the-en ...

  6. ubuntu 17.04 Tomcat安装

    安装Tomcat分为两步: JDK和Tomcat 安装jdk 1.在oralce官网下载jdk

  7. MySQL 5.6 my.cnf优化后的标准配置(4核 16G Centos6.5 x64)

    [client] port = 3306 socket = /var/lib/mysql/mysql.sock [mysql] #这个配置段设置启动MySQL服务的条件:在这种情况下,no-auto- ...

  8. 基于OpenAM系列的SSO----基础

    基于OpenAM系列的SSO----基础   OpenAM简介:OpenAM是一个开源的访问管理.授权服务平台.由ForegeRock公司发起.OpenAM前身为OpenSSO,由SUN公司创建,现在 ...

  9. 实现下拉弹出视图和Block的简单实现

    实现效果如下: 实现代码如下: @interface ViewController ()<UIViewControllerTransitioningDelegate> { UILabel ...

  10. CentOS7.2配置LNMP环境并安装配置网站WordPress

    1,安装环境查看 2,安装MySQL5.7.22 下载MySQL wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-1.e ...