How to run a command with a time limit

The timeout command can be used to run a command with a timelimit. This can be useful when an application needs to be stopped after a specific time or if the application does not stop within a time then forcibly kill it.

$timeout 15 top

The above example will run the top command for 15 seconds and then kill it.

$timeout    --preserve-status 15 top

The above example on exit will return the status of the command. For more information refer to man page.

Leave a Reply

Your email address will not be published. Required fields are marked *