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?
How to limit the running time of a program
limit
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.It will kill
command
after 10 seconds. Instead ofs
for seconds, you can also usem
for minutes,h
for hours ord
for days.