linux – 在X时间后杀死CPU占用率高的进程?

前端之家收集整理的这篇文章主要介绍了linux – 在X时间后杀死CPU占用率高的进程?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
运行 Linux我有一些流程偶尔会崩溃(游戏服务器),最终使用100%的cpu.

我正在寻找一个程序或脚本来检查一个进程列表的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.

原文链接:https://www.f2er.com/linux/402341.html

猜你在找的Linux相关文章