Aaa Bbb Aaa Bbb - 3 years ago 45
Bash Question

Loooking for a command similar to time, but exiting if the time exceeds a limit

I want to benchmark a tool. I am using the usual time command. But if it takes more than 1 hour to run, the tool is clearly too bad, and I want to exit immediately and be notified on the stdout.

Answer Source

You can combine time (does the timing) with the timeout utility from coreutils (does the killing).


$ time timeout 1 sleep 4
  Command exited with non-zero status 124
  0.00user 0.00system 0:01.00elapsed 0%CPU (0avgtext+0avgdata 2012maxresident)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download