Back to the command reference

timeout

ProcessesFundamentals In real Linux

Run a command with a time limit

Name: timeout

This command needs a real Linux system; you can practise it in real Linux mode.

Description

timeout runs a command and signals it (SIGTERM by default) if it is still running after the time limit; the exit status is then 124. It keeps a hung command from stalling a script.

Syntax

timeout [OPTION] DURATION COMMAND

Common options

-s / --signal SIGNALSignal to send (default TERM)
-k / --kill-after DURATIONForce kill after this extra time
--preserve-statusExit with the command’s own status rather than 124

Examples

  • $ timeout 10 ping example.com

    Run for at most 10 seconds

    Explain
  • $ timeout 5m ./long-task.sh

    At most 5 minutes

    Explain

Related