5

Sometimes when I write code I found that I made a stupid mistake and some loop takes almost all CPU time forever. Is there a way the running time of a program for example to 10 seconds in bash?

7

The timeout command will do this for you, i.e.

timeout 10s command

It will kill command after 10 seconds. Instead of s for seconds, you can also use m for minutes, h for hours or d for days.

| improve this answer | |
  • 5
    One just has to love the BUGS section of man timeout: "Some platforms don't curently support timeouts beyond 2038" – Hagen von Eitzen Apr 4 '15 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.