timeout
Run command with time limit
TLDR
Run a command with a time limit (30 seconds)
SYNOPSIS
timeout [options] duration command [args...]
DESCRIPTION
timeout runs a command with a specified time limit. If the command doesn't complete within the duration, timeout sends a signal (SIGTERM by default) to terminate it.
The default signal (SIGTERM) allows processes to clean up before exiting. For processes that ignore SIGTERM, use --kill-after to send SIGKILL after an additional grace period.
Exit status is 124 if the command times out, 137 if killed by SIGKILL, or the command's own exit status if it completes within the limit. Use --preserve-status to return the signal number + 128 on timeout.
PARAMETERS
-k duration, --kill-after=duration
Send SIGKILL after additional duration if command still running-s signal, --signal=signal
Signal to send on timeout (default: SIGTERM)--preserve-status
Return command's exit status even on timeout--foreground
Don't create new process group (for terminal interaction)-v, --verbose
Diagnose signal sent to stderr
DURATION FORMAT
s: Seconds (default)
m: Minutes
h: Hours
d: Days
Numbers can be floating-point: 1.5m = 90 seconds
CAVEATS
Timeout creates a new process group by default, which can interfere with interactive commands or terminal I/O. Use --foreground for such cases.
Commands that spawn child processes may leave orphaned children. Timeout only signals the direct child, not grandchildren.
Very short timeouts (sub-second) may not be reliable due to scheduling overhead.
