timeout
Linux · Processes · reference only
What it does
Runs a command and terminates it if it takes longer than the given time. It is useful to stop a process from hanging.
Syntax
timeout [opciones] duración comando [argumentos...]
Options and parameters
duraciónMaximum time; accepts the suffixes s, m, h and d (for example 30s or 2m).
-s señalSignal sent when time runs out; TERM by default.
-k duraciónIf the command is still alive after that time, it kills it with KILL.
--preserve-statusReturns the command's exit status even if time ran out.
--foregroundAllows running it from a script without blocking on the terminal.
-vReports the signals it sends.
Usage examples
timeout 5 ping -c 10 localhostCuts the ping at 5 seconds even if packets were left.
timeout -s KILL 10 ./lento.shKills the script with KILL if it goes past 10 seconds.
timeout -k 5 30 ./procesoAsks it to close at 30 seconds and forces it 5 seconds later.
timeout 2m ./copia.sh; echo $?If time runs out, the exit status is 124.
Notes and common mistakes
- An exit status of 124 means the command was cut by the time limit.