How to limit the running time of a program

limit

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?

Best Answer

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.

Related Question