TIMEOUT(1) General Commands Manual TIMEOUT(1)

timeoutsignal command after delays

timeout [-fpv] [-s signal] [-k kill-after] signal-after program [argument]…

Executes program arguments, but sends it signal (default SIGTERM) after signal-after, and SIGKILL after an additional delay of kill-after, if specified.

If -f was not specified, timeout becomes the process group leader and sends signals to the process group: this has the added benefit of signaling all of the program's children.

Additionally, it will also forward all instances of SIGTERM, SIGINT, SIGHUP, SIGQUIT, and the specified signal it receives to the child (or process group). Be wary about attempting to forward SIGALRM.

All times are in non-monotonic wall-clock time. All sent signals are followed by a SIGCONT. Delays of disable the corresponding timer.

, --foreground
Do not become a process group leader and signal the child directly.
, --preserve-status
Return the child's shell-style exit status instead of 124 when the child dies after timing out.
, --verbose
Note all signals being sent to the standard error stream.
, --signal=signal
Send signal instead of SIGTERM after signal-after expires.
, --kill-after=duration
Send SIGKILL duration after signal-after.

signal-after and kill-after are floating-point amounts of seconds, optionally suffixed with one of the following cumulative multipliers:

(econds)
(inutes)
(hours)
(ays)
(eeks)
(ears)
/ 7
This is the same format as sleep(1).

If signal starts with a digit, it's presumed to be a numerical signal value. Otherwise, if it starts with "", that prefix is stripped for the purposes of further matching. All string comparisons are case-insensitive.

On platforms with sys_signame(3) (the BSD), signal is matched directly to the array.

Elsewhere, it's matched to the signal names known at compile time; the null signal is known as "Signal 0". Real-time signals, if any, can be specified in the format "integer", where integer is a decimal number (NetBSD-style), or "integer" and "integer" (procps-style). Real-time signals must fall in [SIGRTMIN, SIGRTMAX] to be accepted.

In which program is searched, confer execvp(3).

, SIGINT, SIGHUP, SIGQUIT, signal
Caught and forwarded to the child (or process group).
Used for timing signal-after and kill-after. May be specified as signal, but sending it to timeout will only advance it to sending the next signal.
, SIGTTOU
Ignored: this means that "timeout 1 cat &" will not stop, while "cat &" would, confer termios(4).

program exited after signal was sent and -p wasn't specified.
+signal (128+SIGKILL)
program exited due to a signal. This matches shells' synthesised exit statuses for signal terminations.
An error occurred.
program exists, but couldn't be executed for a different reason.
program wasn't found.
All others
returned by program either before signal-after or with -p.

Limit a command to a second of run-time:

$ timeout 1 sleep 20
$ echo $?
124

Emulate pipe shutter after a half-minute:

$ timeout -vfsPIPE 0.5m yes | wc
timeout: yes (14539): sending SIGPIPE
568057856 568057856 1136115712
Note the -f, as otherwise timeout also kills wc.

Resort to killing:

$ timeout -k1s -sHUP 1 nohup sleep 20
nohup: input shut, output and error in nohup.out
timeout: nohup (group): sending Hangup
timeout: nohup (group): sending Killed
Killed
$ echo $?
137
Note, how, despite the absence of -p, the exit status appears to be — this is because SIGKILL is unblockable, and, when sent to the process group, arrived to timeout itself, since under an interactove shell, each pipeline is a process group.

credentials(7) for the implications of timeout becoming a process group leader. kill -l and signal(7) for a list of available signals.

Originates from the GNU system in coreutils 7.0; also present in NetBSD 7.0 and FreeBSD 11.0, although those versions miss -v and un-SIG-prefixed -s.

The delay suffixes and short versions of -fp are extensions.

November 23, 2022 voreutils pre-v0.0.0-latest