runfinite

Consider the following problem: You want to run automatic software tests and you want to guarantee that a test is finished in a finite amount of time. In other words, you may want to limit the execution time of a process to a specific timespan. The first attempt would be to write a shell script which is polling for the existence of a specific process. Searching for a process by name is bad since there could be more of them and handling with the pid is somehow bulky.

I wrote a little C code which forks a child process to execute a given command and the parent process kills the child process when a given amount of time is over and the process has not finished yet. You may want to download the C source code, which is using automake and friends, via git or by downloading tar.gz snapshot from git.sthu.org.

The source contains a INSTALL.txt explaining the compilation procedure. Extremely usefull sample calls are: <p>

./runfinite -h
./runfinite -t 10 ./runfinite -t 4 /usr/bin/sleep 8
./runfinite -v -t 5 /usr/bin/find /

Update. With ulimit -t SEC you can limit the process time, too. But note that runfinite -t 2 would kill a sleep 10, while ulimit would not as sleep basically does not consume any cpu time.