Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any generic way to monitor a process and restart it automatically if it's pegged at 100% CPU for over x seconds?

I'm battling some bugs in Mono's fastcgi server and while I search for a fix (analyzing stack traces) I'm looking for a workaround that will automatically detect it being stuck and restart it with the same command line parameters.

Thanks.

share|improve this question
up vote 1 down vote accepted

Try MONIT.

Sample configuration:

check process example-server with pidfile /var/run/example-server.pid
  start program = "/etc/init.d/example-server start" with timeout 60 seconds
  stop program  = "/etc/init.d/example-server stop"
  if cpu > 90% for 3 cycles then restart

See Also:

  1. http://serverfault.com/questions/97541/kill-process-with-high-cpu-usage-after-x-time
  2. http://stackoverflow.com/questions/2784468/monitor-and-kill-runaway-processes-using-100-io
  3. http://mmonit.com/monit/documentation/monit.html
share|improve this answer
    
Thanks, that looks promising. Worst case scenario was to write a light wrapper around pidstat, but this looks good. – Mahmoud Al-Qudsi May 11 '12 at 3:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .