TIMEOUT(1) User Commands TIMEOUT(1)

timeout - execute a command with a time limit

timeout [-k time] [-s signal] [-fp] time command [argument ...]

Timeout executes a specified command and attempts to terminate it after an also specified time. Per default, it sends signal 15 (terminate, alias SIGTERM), but the signal can be redefined (see option If the duration is a zero value, the timer is disabled (see timer_settime(2)), ergo there will not be any signal sent to the specified command's process.

It accepts the following options:

Sets a complementary time for tolerance before sending a final signal 9 (SIGKILL) to command if it's still executing.
-s signal
Sets a signal to be sent instead of signal 15 (terminate). It's defined per a decimal number or its symbolic name (see kill(1) '-l' option).
If it's defined as 9 (SIGKILL), it has an immediate effect and annuls the '-k' option.
Permits that command runs as foreground and recieves signals from the terminal; per using this option, the children processes that command may create will not be terminated with it even in case of the timer timing out.
Keep command's exit status instead of using this program's default.

time can be specified as a fractional number by using a full stop or a comma as the decimal separator. The default value are seconds unless a time unit is specified per its single-letter identifier; in ascend order, the supported units are:

seconds
minutes
hours
days

Exit status is 124 if the timer expired and the -p option was not set, 126 if the command could be found, but could not be executed and 127 if the command could not be found.

This program has different possible applications in one's routine, here are some:
Lets suppose you need to check if your system is connected to the Internet and that it can successfully connect to a server in less than 5 seconds, you can use timeout along with nc(1):

% timeout -p 5 nc -vz pindorama.dob.jp 80
% echo $?
0

In another example, you have a project and start experiencing hangings at some part after a contributor sent a patch, but you do not know the part nor the file that was broken; since you know that it should not take more than half a minute to pass that part, you can use timeout and visualize precisely where it hangs per enabling debug at the shell interpreter:
% timeout 0,5m /bin/ksh -x ./build.ksh

Although this implementation being sœur with BSDs' implementations since it shares some parts of code with it, it does not support long options as GNU (and BSDs') does, so some shell scripts may not work unchanged with this implementation.
An abideable approach for solving this problem could be an small check/wrapper for the timeout command in case of utilizing the -f or the -p options in its long format.

if test `getconf HEIRLOOM_TOOLCHEST_VERSION` -ge 20240220
then

timeout -p -ktime time command else
timeout --preserve-duration --kill-after time time command fi

This implementation supports intervals using both European or Anglo decimal separators, GNU doesn't.

In contrast to OpenBSD's — and any other implementation thoroughly based and/or ported from FreeBSD 10.3R —, this implementation supports nanoseconds as the interval instead of microseconds. This can change in the future depending on your platform, though.

exec(3), fork(2), kill(1), signal(2), timer_settime(2), itimerspec(3type), wait(2)

The timeout utility first appeared as a proposal in BusyBox mailing lists in February 3, 2006, but this version have payloads closer to the timeout found at GNU Coreutils 7.0, released in 05 October, 2008.

2/20/24 Heirloom Toolchest