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程序,是不是很邪恶啊,哈哈~~~ 不过我只是干过一次 ...
随机推荐
- 一个读取C#特性Description方法(zhuan)
class Program { static void Main(string[] args) { string str= DB.write.ToDescription(); Console.Writ ...
- Qt编写控件属性设计器5-属性中文
一.前言 在上一篇文章中就提到过,使用qtpropertybrowser来加载属性,对应加载到的属性是英文的,也就是控件类中Q_PROPERTY描述的变量名称,如何变成中文或者其他语言显示呢?这个就需 ...
- html设置多个div并排显示
我这里以4个div为例,html代码如下: <body> <div id="column1" style="background-color: blue ...
- python的注释规范
pydoc是python自带的一个文档生成工具,使用pydoc可以很方便的查看类和方法结构 本文主要介绍:1.查看文档的方法.2.html文档说明.3.注释方法. 一.查看文档的方法 方法1: ...
- Navicat安装及使用
一.安装Navicat 1.下载安装文件:navicat11.0.17_premium_cs_x86.exe(32位) 2.Oracle 的 Instance Client:instantclient ...
- (CVE-2017-8464)LNK文件远程代码执行
漏洞详细 北京时间2017年6月13日凌晨,微软官方发布6月安全补丁程序,“震网三代” LNK文件远程代码执行漏洞(CVE-2017-8464)和Windows搜索远程命令执行漏洞(CVE-2017- ...
- go gRPC介绍, demo
参考文章: 1. https://www.cnblogs.com/kaixinyufeng/p/9651513.html 2. http://jia-shun.cn/2018/08/12/gRPC/ ...
- Python 面向对象总结
面向对象 类 class 类型 类变量 实例方法 init attack bite 类指针 - 指向父类 对象 对象指针 实例变量 self.name slef.age 组合 一个对象作为一个属性 s ...
- jenkins相关war包下载
1.jenkins的war包下载地址 地址:http://mirrors.jenkins-ci.org/,打开链接后,表格有war列,Releases行是短期更新包.LTS是长期更新包.一般选择Rel ...
- React native 放大点击区域 hitSlop属性的使用
在日常的需求中,如上图的加减按钮,可能写ui布局的时候没考虑实际的这个点击范围太小,不利于真机上用户点击到,如果加包裹层加padding的话又会影响原先定好的布局,或者不利于对齐. 那么可以用 hi ...