timeoutcommand


How to limit process running time in Linux

Linux command timeout can be used to run a command with a time limit .

Usage:

timeout [OPTION] DURATION COMMAND

For example, below command will limit ssh command running time as 10 seconds.

j@ubuntu2004:~$ timeout 10 ssh linuxtutorials.org
j@linuxtutorials.org's password: 
timeout: sending signal TERM to command ‘ssh’

This command is useful when we send a remote command , like we invoke ssh in script but sometimes it will be hung due to something, by using timeout we can kill it automatically.

For DURATION:

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