Gnu/coreutils/timeout-invocation
Previous: stdbuf invocation, Up: Modified command invocation [Contents][Index]
23.6 timeout
: Run a command with a time limit
timeout
runs the given command
and kills it if it is
still running after the specified time interval. Synopsis:
timeout [option] duration command [arg]…
command
must not be a special built-in utility (see Special built-in utilities).
The program accepts the following options. Also see Common options. Options must precede operands.
- ‘
--preserve-status
’ Return the exit status of the managed
command
on timeout, rather than a specific exit status indicating a timeout. This is useful if the managedcommand
supports running for an indeterminate amount of time.- ‘
--foreground
’ Don’t create a separate background program group, so that the managed
command
can use the foreground TTY normally. This is needed to support timing out commands not started directly from an interactive shell, in two situations.command
is interactive and needs to read from the terminal for example- the user wants to support sending signals directly to
command
from the terminal (like Ctrl-C for example)
Note in this mode of operation, any children of
command
will not be timed out. Also SIGCONT will not be sent tocommand
, as it’s generally not needed with foreground processes, and can cause intermittent signal delivery issues with programs that are monitors themselves (like GDB for example).- ‘
-k duration
’
‘--kill-after=duration
’ Ensure the monitored
command
is killed by also sending a ‘KILL
’ signal, after the specifiedduration
. Without this option, if the selected signal proves not to be fatal,timeout
does not kill thecommand
.- ‘
-s signal
’
‘--signal=signal
’ Send this
signal
tocommand
on timeout, rather than the default ‘TERM
’ signal.signal
may be a name like ‘HUP
’ or a number. See Signal specifications.- ‘
-v
’
‘--verbose
’ Diagnose to stderr, any signal sent upon timeout.
duration
is a floating point number in either the current or the
C locale (see Floating point) followed by an optional unit:
‘s’ for seconds (the default) ‘m’ for minutes ‘h’ for hours ‘d’ for days
A duration of 0 disables the associated timeout. Note that the actual timeout duration is dependent on system conditions, which should be especially considered when specifying sub-second timeouts.
Exit status:
124 if command times out 125 if timeout itself fails 126 if command is found but cannot be invoked 127 if command cannot be found 137 if command is sent the KILL(9) signal (128+9) the exit status of command otherwise
Previous: stdbuf invocation, Up: Modified command invocation [Contents][Index]