2

It's crucial to measure not user time for some program/script, but the cpu time and kill it when this time limit will be breached.

What's the best way to do it?

One of the most obvious solutions is to check with some time step process tree to see if the requested program/script hasn't breached it's limits. It's implemented in a perl script (pshved/timeout). I'm looking for other aproaches

Ribtoks
  • 6,634
  • 1
  • 25
  • 37

1 Answers1

2

You can use ulimit(1) or setrlimit(2) to limit the cpu time. The process will be automatically killed if it uses more cpu time. It is also possible to specify a soft limit that can be ignored.

Simple example:

#! /bin/bash
(
    ulimit -t 5
    python -c '
a, b = 0, 1
while True:
    a += b
    b += a
'
    echo $?
)
echo "..."
nosid
  • 48,932
  • 13
  • 112
  • 139