2

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)

bortzmeyer
  • 34,164
  • 12
  • 67
  • 91

3 Answers3

4

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
  • 82,554
  • 44
  • 203
  • 280
  • 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 Dec 21 '08 at 21:03
  • Yes, you can do it with mod_suid. – Alex B Dec 22 '08 at 07:36
1

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

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

0

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
  • 14,535
  • 3
  • 29
  • 30