Executing commands for a specific amount of time


Posted by Diego Assencio on 2014.03.31 under Linux (Management)

On Linux, you can run a command for a specific amount of time using the timeout utility:

timeout <time> <command>

For example, to recursively list all files in the current working directory for no longer than 2 seconds, open a terminal and run:

timeout 2s ls -R

The command which is passed as an argument to timeout will be automatically killed if it is still running after the specified amount of time. If this is the case, the exit status code of timeout will be 124 (not zero!).

For more on this topic, see the man page of timeout:

man timeout

Comments

No comments posted yet.

Leave a reply

NOTE: A name and a comment (max. 1024 characters) must be provided; all other fields are optional. Equations will be processed if surrounded with dollar signs (as in LaTeX). You can post up to 5 comments per day.