我正在寻找一个程序或脚本来检查一个进程列表的cpu使用情况,如果它们是100%超过X时间,比如30秒,就杀死它们.我尝试过ps-watcher,但无法确定如何完成此 *** 作.
只是在100%使用情况下终止进程将无法正常工作,因为它会在正常 *** 作期间短暂停留.
我也发现这个脚本看起来像我想要的那样,但它仅限于一个过程:link
任何帮助是极大的赞赏!
解决方法 试试 monit.你可以使用这样的配置来完成你的任务:
check process gameserver with pIDfile /var/run/gameserver.pID start program = "/etc/init.d/gameserver start" with timeout 60 seconds stop program = "/etc/init.d/gameserver stop" if cpu > 80% for 2 cycles then alert if cpu > 95% for 5 cycles then restart if totalmem > 200.0 MB for 5 cycles then restart if loadavg(5min) greater than 10 for 8 cycles then stop if Failed port 12345 type tcp with timeout 15 seconds then restart if 3 restarts within 5 cycles then timeout
有关此配置的详细信息,请参见monit的documentation.
总结以上是内存溢出为你收集整理的linux – 在X时间后杀死CPU占用率高的进程?全部内容,希望文章能够帮你解决linux – 在X时间后杀死CPU占用率高的进程?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)