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
Linux每隔1秒kill掉cpu大于50%的进程的更多相关文章
- 【每天一条Linux指令-Day1】kill掉多个mysql的进程
我被问到过一个shell的问题,问的是如何kill掉多个mysql的进程? 怎么把这个的pid传递下去 ps -ef|grep mysql | xargs kill -9 ps -ef|grep my ...
- mysql中kill掉所有锁表的进程
--mysql中kill掉所有锁表的进程 --------------------------------2014/05/20 在数据库的管理中,我们经常会碰到锁表的问题,看一下进程列表. mysql ...
- 找出 alter system kill session ‘sid,serial#’ kill 掉的数据库会话对应进程
当我们使用alter system kill session ‘sid,serial#’ 在数据库中kill掉某个会话的时候,如果你观察仔细会发现v$session.paddr发生了改变,从而是的不能 ...
- 批量kill掉包含某个关键字的进程
需要把 linux 下符合某一项条件的所有进程 kill 掉,又不能用 killall 直接杀掉某一进程名称包含的所有运行中进程(我们可能只需要杀掉其中的某一类或运行指定参数命令的进程),这个时候我们 ...
- linux 查看占用端口并kill掉
主要可以使用ps 命令 或 netstat 命令 weihong@data1:~/jd_parser/jd_parser$ ps aux | head USER PID %CPU %MEM VSZ ...
- linux 因内存不足而 kill 掉 java 程序
grep "Out of memory" /var/log/messages Sep 17 16:13:34 xxxaaa kernel: Out of memory: Kill ...
- linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现
linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现?快速清理木马流程.假设木马的名字是xysbqaxjqy,如果top看不到,可以在/etc/init.d目 ...
- 编写shell脚本kill掉占用cpu超过90%以上的程序
由于集群用户经常会不懂如何提交作业,将作业直接运行到登录节点上,这样导致登录节点的cpu及内存占用很大,导致其他用户甚至无法登录.所以就想到了一种解决方法,写一个shell脚本,常驻登录节点,监控cp ...
- 【shell脚本实例】一个恶作剧—— kill掉占用CPU较高的matlab进程
我们实验室有台服务器,博士们在服务器上跑MATLAB,基本都是4核都是超过95%的CPU占用,想了个恶作剧的shell 定时kill掉MATLAB程序,是不是很邪恶啊,哈哈~~~ 不过我只是干过一次 ...
随机推荐
- 【Oracle】创建用户及设定权限
; grant create session to ufo; grant create tablespace to ufo; grant create table to ufo; grant drop ...
- 使用Flask构建机器学习模型API
1. Python环境设置和Flask基础 使用"Anaconda"创建一个虚拟环境.如果你需要在Python中创建你的工作流程,并将依赖项分离出来,或者共享环境设置," ...
- opencv 检测人脸、人眼
This tutorial code’s is shown lines below. You can also download it from here . The second version ( ...
- android: requestLayout(), invalidate(), postInvalidate() 方法区别
一.invalidate和postInvalidate 这两个方法都是在重绘当前控件的时候调用的.invalidate在UI线程中调用,postInvalidate在非UI线程中调用.因为androi ...
- Oracle数据库的坑
Oracle数据库爬过的坑 ORA-00918 未定义明确列 ORA-01861: 文字与格式字符串不匹配 DPI-1005 : unable to acquire Oracle environmen ...
- Flutter布局基本情况总结:
1.一行内容,发布两边: 效果: Flex( direction: Axis.horizontal, children: <Widget>[ Expanded( flex: , child ...
- 123457123457#0#-----com.cym.shuXueWangGuo1--前拼后广--儿童数学
123456123456#1#-----com.cym.shuXueWangGuo1--前拼后广--儿童数学
- 导出 VuePress构建的网站为 PDF
前言 学 Rust 也有一段时间了,网上也有不少官方文档的中文翻译版,但是似乎只有 Rust中文网站 文档一直是最新的,奈何并没有 PDF 供直接下载,是在是不太方便,为了方便阅读以及方便后续文档更新 ...
- 【C#设计模式2】简单工厂模式
我们在编程的时候,每当"new"一个对象之后,这个对象就依赖于这个类了.如果在后期的维护过程中由于某些原因需要修改一下这个类,则唯一的做法就是打开源代码,进行修改,修改所有与这个对 ...
- 粒子系统与雨的效果 (DirectX11 with Windows SDK)
前言 最近在学粒子系统,看这之前的<<3D图形编程基础 基于DirectX 11 >>是基于Direct SDK的,而DXSDK微软已经很久没有更新过了并且我学的DX11是用W ...