tags:

views:

275

answers:

3

I manage Unix systems where, sometimes, programs like CGI scripts run forever, sometimes eating a lot of CPU time and wasting resources.

I want a program (typically invoked from cron) which can kill these runaways, based on the following criteria (combined with AND and OR):

  • Name (given by a regexp)
  • CPU time used
  • elapsed time (for programs which are blocked on an I/O)

I do not really know what to type in a search engine for this sort of program. I certainly could write it myself in Python but I'm lazy and there is may be a good program already existing?

(I did not tag my question with a language name since a program in Perl or Ruby or whatever would work as well)

A: 

Most of the watchdig-like programs or libraries are just trying to see whether a given process is running, so I'd say you'd better off writing your own, using the existing libraries that give out process information.

Keltia
+4  A: 

Try using system-level quota enforcement instead. Most systems will allow to set per-process CPU time limit for different users.

Examples:

  1. Linux: /etc/security/limits.conf
  2. FreeBSD: /etc/login.conf

CGI scripts can usually be run under their own user ID, for example using mod_suid for Apache.

Alex B
In this case, it is CGI run by Apache and I hesitate to punish the httpd user because of some scripts. May be changing my Apache setup to run CGI with a different user depending on the program? Never tried that.
bortzmeyer
Yes, you can do it with mod_suid.
Alex B
+1  A: 

This might be something more like what you were looking for:

http://devel.ringlet.net/sysutils/timelimit/

Yes, it seems very interesting and simple to use. Currently testing it in a real Web server.
bortzmeyer