tags:

views:

244

answers:

1

I want to limit the execution time of a program I am running under Linux. I put in my scons script a line like:

Command("com​","",​"ulimit -t 1; myprogram")

and tested it with an infinite loop program: it did not work and the program ran forever.

Am I missing something?

-- tsf

+1  A: 

ulimit -t 1 means that the limit is set to 1 second of CPU time. If your infinite loop program uses any sort of sleep in its inner loop then it will use practically no CPU time. This means it will not get killed in 1 second of real, on the clock time. In fact it may take minutes or hours to use up its 1 second allocation.

What happens if you run the command outside of SCons? Perhaps you don't have permission to change the limit at all...

ulimit -t 1; ./myprogram

For example, it may say the following if the limit is already set to 0:

bash: ulimit: cpu time: cannot modify limit: Operation not permitted

Edit: it seems that the -t option is broken on Ubuntu 9.04. A fix has been committed 05 June 2009, but it may take a while to trickle into the updates - it may not be fixed until 9.10.

As an historical note, this problem no longer exists in Ubuntu 10.04.

rq
My program endless loop was something like (in C): while (1) x = 1;so that that there was no sleep in it.-- tsf
Tsf
It seems that this is not a problem of Scons! I tried ulimit -t 1; ./myprogramIt worked (was interrupted) under a Linux Fedora installation but did not work under Ubuntu. I have to check whether it depends on some configuration value.Thanks!
Tsf
Ah! I was trying it on openSuse and it worked. On Ubuntu... nothing. No error but no kill after 1 second either.
rq