NAME
timeout
—
signal command after delays
SYNOPSIS
timeout |
[-fpv ] [-s
signal] [-k
kill-after] signal-after
program
[argument]… |
DESCRIPTION
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
0 disable the
corresponding timer.
OPTIONS
-f
,--foreground
- Signal the child directly, do not become the process group leader.
-p
,--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.
-v
,--verbose
- Log all signals being sent to the standard error stream.
-s
,--signal
=signal- Send signal instead of
SIGTERM
after signal-after expires. -k
,--kill-after
=duration- Send
SIGKILL
duration after signal-after.
Time Intervals
signal-after and kill-after are floating-point amounts of seconds, optionally suffixed with one of the following cumulative multipliers:
This is the same format as in sleep(1).Signal Name
If signal starts with a digit, it's presumed to be a numerical signal value. Otherwise, if it starts with "SIG", 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
"RTinteger",
where integer is a decimal number
(NetBSD-style), or
"RTMIN+integer"
and
"RTMAX-integer"
(procps-style). Real-time signals must fall in
[SIGRTMIN
, SIGRTMAX
] to be
accepted.
ENVIRONMENT
PATH
- In which program is searched; confer execvp(3).
SIGNALS
SIGTERM
,SIGINT
,SIGHUP
,SIGQUIT
, all other deadly signals, signal- Caught and forwarded to the child (or process group).
SIGTTIN
,SIGTTOU
- Ignored: this means that "
timeout
1cat
&
" will not stop, while "cat
&
" would; confer termios(4).
The child's signal dispositions and mask are unaffected.
EXIT STATUS
- 125
- Couldn't fork.
- 124
- If
-p
wasn't specified: program exited after signal was sent - None, deadly signal re-raised
- program died to a signal.
- 127
- program wasn't found.
- 126
- 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.
EXAMPLES
Limit a command to a second of run-time:
$
timeout
1sleep
20$
echo
$?
124$
timeout
-p
1sleep
20 Terminated$
echo
$?
143
Emulate pipe shutter after a half-minute:
$
timeout
-vfs
PIPE
0.5myes
|
wc
timeout: yes (3558706): sending SIGPIPE 11462975 11462975 22925950
-f
, as otherwise
timeout
would also kill the
wc
.
Resort to killing:
$
timeout
-vk
1s-s
HUP
1nohup
sleep
20 nohup: <&- >> nohup.out 2>&1 timeout: nohup (group): sending SIGHUP timeout: nohup (group): sending SIGKILL Killed$
echo
$?
137
-p
, the exit status
appears to be
137 —
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.
SEE ALSO
signal(7), kill
-l
for a list of available signals.
credentials(7) for the implications of
timeout
becoming a process group leader.
STANDARDS
IEEE Std 1003.1-2024
(“POSIX.1”); -v
is an extension,
originating from the GNU system. The standard specifies
smhd
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.
HISTORY
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.