TIMEOUT(1) General Commands Manual Fully-rendered PDF

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 is 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 every signal that terminates the receiver by default (SIGTERM, SIGINT, SIGHUP, SIGQUIT, &c.) and the specified signal it receives to the child (or process group).

All times are monotonic. All sent signals are followed by a SIGCONT. Delays of disable the corresponding timer.

, --foreground
Signal the child directly, do not become the process group leader.
, --preserve-status
Return the child's exit status or re-raise the deadly signal instead of exiting 124 when the child dies after timing out.
, --verbose
Log 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 in 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, all other deadly signals, signal
Caught and forwarded to the child (or process group).
, SIGTTOU
Ignored: this means that "timeout 1 cat &" will not stop, while "cat &" would; confer termios(4).

The child's signal dispositions and mask are unaffected.

Couldn't fork.
If -p wasn't specified: program exited after signal was sent
None, deadly signal re-raised
program died to a signal.
program wasn't found.
program exists, but couldn't be executed for a different reason.
All others
forwarded from program if -p or if it exited normally before signal-after.

Limit a command to a second of run-time:

$ timeout 1 sleep 20
$ echo $?
124
$ timeout -p 1 sleep 20
Terminated
$ echo $?
143

Emulate pipe shutter after a half-minute:

$ timeout -vfsPIPE 0.5m yes | wc
timeout: yes (3558706): sending SIGPIPE
11462975 11462975 22925950
Note the -f, as otherwise timeout would also kill the wc.

Resort to killing:

$ timeout -vk1s -sHUP 1 nohup sleep 20
nohup: <&- >> nohup.out 2>&1
timeout: nohup (group): sending SIGHUP
timeout: nohup (group): sending SIGKILL
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 interactive shell, each pipeline is a process group.

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

IEEE Std 1003.1-2024 (“POSIX.1”); -v is an extension, originating from the GNU system. The standard specifies Time Intervals' suffixes and matches signals case-insensitively by the part after SIG, and without real-time signals.

SIGALRM may cause timeout to behave as-if the signal-after or --kill-after timers elapsed, rather than forwarding it. The standard doesn't specify the clock: this implementation uses CLOCK_MONOTONIC, some implementations use CLOCK_REALTIME, which makes them subject to NTP and date adjustments. The standard allows timeout to reset the disposition of signal to no longer be ignored.

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.

IEEE Std 1003.1-2024 (“POSIX.1”) invents timeout, as present-day.

July 10, 2024 voreutils 5a9f9f29