I am running a program.Inside this program i run a specific command and i use ulimit command to terminate the running of that command if it exceeds an amount of time.To be more clear i run this:

ulimit -t 1800 ./bsolo3.0.17 test.opb

which means that i want to terminate the run of bsolo solver if the time needed exceeds 1800 seconds.

What i want is a way to know, after let's say 10 runs of that command,how many times the runtime was below that limit and how many times the runtime of that command was above that limit.I don't have any clue yet.Any tips?

1 Answer 1


At least on my system (Debian), that's not how ulimit works. It won't run the command after the limit, you just set the limit, then run the command:

$ ulimit -t 1800 
$ ./bsolo3.0.17 test.opb

Anyway, to get the times, you can use time:

$ time ls > /dev/null
real    0m0.004s
user    0m0.000s
sys     0m0.000s

So, if your command is running in some kind of loop, you can capture the times in a file like this:

ulimit -t 1800
for i in {1..10}; do
  (time ./bsolo3.0.17 test.opb) 2>> times.log 

The subshell (the parentheses) is needed in order to be able to capture the output of time which prints to STDERR. Using time foo 2> log will not work because that will only redirect the STDERR of the command foo and not of time.

If all you want is the number of times the command finished within the allotted time, do this:

 ulimit -t 1800
for i in {1..10}; do
  ./bsolo3.0.17 test.opb && let count++
echo "Job finished in time $count times."
  • what i want is not to capture the times but find out how many times the running of that command reaches that limit
    – Dchris
    Jul 13, 2013 at 13:31
  • @Dchris OK, updated accordingly. All you need to do is have a counter that increases each time the job finishes successfully.
    – terdon
    Jul 13, 2013 at 13:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .