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
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
0 disable the
corresponding timer.
OPTIONS
-f
,--foreground
- Do not become a process group leader and signal the child directly.
-p
,--preserve-status
- Return the child's shell-style exit status instead of 124 when the child dies after timing out.
-v
,--verbose
- Note 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 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
, signal- Caught and forwarded to the child (or process group).
SIGALRM
- 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. SIGTTIN
,SIGTTOU
- Ignored: this means that "
timeout
1cat
&
" will not stop, while "cat
&
" would, confer termios(4).
EXIT STATUS
- 124
- program exited after signal
was sent and
-p
wasn't specified. - 128+signal
(128+
SIGKILL
) - program exited due to a signal. This matches shells' synthesised exit statuses for signal terminations.
- 125
- An error occurred.
- 126
- program exists, but couldn't be executed for a different reason.
- 127
- program wasn't found.
- All others
- returned by program either before
signal-after or with
-p
.
EXAMPLES
Limit a command to a second of run-time:
$
timeout
1sleep
20$
echo
$?
124
Emulate pipe shutter after a half-minute:
$
timeout
-vfs
PIPE
0.5myes
|
wc
timeout: yes (14539): sending SIGPIPE 568057856 568057856 1136115712
-f
, as otherwise
timeout
also kills wc
.
Resort to killing:
$
timeout
-k
1s-s
HUP
1nohup
sleep
20 nohup: input shut, output and error in nohup.out timeout: nohup (group): sending Hangup timeout: nohup (group): sending Killed 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 interactove shell, each pipeline is a process group.
SEE ALSO
credentials(7) for the implications of
timeout
becoming a process group leader.
kill
-l
and
signal(7) for a list of available signals.
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
.
The
hd delay suffixes and
short versions of -fp
are extensions.