Member-only story

How to auto restart command/ process in Linux after specific run time or duration (quick-note)

(quick-note) How to auto restart command/ process in Linux after specific run time, duration or time period

You want to auto-restart a command or process in Linux after specific run time, duration or time period.

For this you can use the timeout command in a while loop.

while true; do
timeout 10 htop --tree
true # you have to have true so that the while lop doesn't break. You might also do en echo.
done

where:

  • timeout 10 means 10 seconds
  • htop --tree is the command you want to run

You may also use echo instead of true after the command

while true; do
timeout 10 htop --tree
echo "restarting process..."
done

References

--

--

Diego Carrasco G.
Diego Carrasco G.

Written by Diego Carrasco G.

Hi, I'm an entrepreneur-turned-developer living in Germany. I enjoy learning, write, coffee and solving problems. I write mainly about technology.

No responses yet