Processes
timeout
Run a command with a time limit.
timelimitprocessscript
Additional Notes
timeout runs another command with a time limit. If the command is still running when the limit is reached, timeout sends it a signal.
Use it in scripts, tests, network checks, downloads, and automation jobs where a command should not hang forever.
Syntax
timeout [options] duration command [arguments...]
Parameters
options: Flags that change howtimeoutbehaves.duration: Time limit such as10s,2m,1h, or1d. Seconds are the default.command: Command to run.arguments: Arguments passed to the command.
Common Options
-s SIGNAL: Send a specific signal when time expires.-k DURATION: Force kill after an additional delay.--preserve-status: Return the command's status when possible.--foreground: Let an interactive command use the foreground terminal.-v: Print a message whentimeoutsends a signal.
Examples
timeout 10s curl https://example.com
Stop curl if it runs longer than 10 seconds.
timeout -k 5s 1m ./job.sh
Send the default timeout signal after 1 minute, then force kill 5 seconds later if needed.
timeout -s INT 30s ./server-test.sh
Send INT instead of the default TERM when time expires.
Practical Notes
- Without
--preserve-status, a timed-out command usually returns status124. - Status
125meanstimeoutitself failed. - Status
126means the command was found but could not run. - Status
127means the command was not found. - Status
137usually meansKILLwas used. - Put
timeoutoptions before the duration and command.