Sep 14, 2018

Timeout a Linux command

Run a command with a time limit, runs the given command and kills it if it is still running after the specified time interval.
       timeout [option] duration command [arg]...
duration is a floating point number followed by an optional unit:

       ‘s’ for seconds (the default)
       ‘m’ for minutes
       ‘h’ for hours
       ‘d’ for days

Run a command (LongRunningCommand) and timeout after 1 minute if the process has not completed already:

$ timeout 1m LongRunningCommand

Apply a 48 second time out to a crontab task

$ * * * * * cronuser timeout 48 demo-script