Alex Rivera | Logout

Command line command to auto-kill a command after a certain amount of time

Asked 2009-03-02T07:41:07.820
60

I'd like to automatically kill a command after a certain amount of time. I have in mind an interface like this:

% constrain 300 ./foo args

Which would run "./foo" with "args" but automatically kill it if it's still running after 5 minutes.

It might be useful to generalize the idea to other constraints, such as autokilling a process if it uses too much memory.

Are there any existing tools that do that, or has anyone written such a thing?

ADDED: Jonathan's solution is precisely what I had in mind and it works like a charm on linux, but I can't get it to work on Mac OSX. I got rid of the SIGRTMIN which lets it compile fine, but the signal just doesn't get sent to the child process. Anyone know how to make this work on Mac?

[Added: Note that an update is available from Jonathan that works on Mac and elsewhere.]

Edit
Report

1 Answer

2

I use "timelimit", which is a package available in the debian repository.

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

answered 2010-08-15T09:47:08.333

Your Answer