0

Run Linux Commands Using the timeout Tool

Question:

how to execute a command with a time limit in linux.

Command-prompt Windows Add a comment
isaac
asked Apr 07 2021

Answer

0

Answer:

  • Its syntax is as follows.
       timeout [OPTION] DURATION COMMAND [ARG]...
    
  • to timeout a ping command after 5 seconds, you can run the following command.
      # timeout 5s ping google.com
    

Sometimes commands may continue to run even after timeout sends the initial signal. In such instances, you can use the --kill-after option.

         -k, --kill-after=DURATION

For example, the command shown is going to be terminated after 8 seconds.

# timeout 8s tail -f /var/log/syslog
Add a comment
linuxhelp
asked Apr 07 2021
edited Apr 07 2021
Post your Answer