1 .\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 .\" Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .Nd run a command with a time limit
37 .Op Fl k Ar time | Fl -kill-after Ar time
38 .Op Fl s Ar sig | Fl -signal Ar sig
39 .Op Fl v | Fl -verbose
41 .Op Fl -preserve-status
53 is still running after
61 zero, signifies no limit.
62 Therefore a signal is never sent if
66 The options are as follows:
67 .Bl -tag -width indent
68 .It Fl k Ar time , Fl -kill-after Ar time
73 is still running after
75 after the first signal was sent.
76 .It Fl s Ar sig , Fl -signal Ar sig
77 Specify the signal to send on timeout.
81 .It Fl v , Fl -verbose
82 Show information to stderr about any signal sent on timeout.
84 Do not propagate timeout to the children of
86 .It Fl -preserve-status
87 Exit with the same status as
89 even if it times out and is killed.
96 are non-negative integer or real (decimal) numbers, with an optional
97 unit-specifying suffix.
98 Values without an explicit unit are interpreted as seconds.
100 Supported unit symbols are:
101 .Bl -tag -offset indent -width indent -compact
112 If the timeout was not reached, the exit status of
116 If the timeout was reached and
118 is set, the exit status of
123 is not set, an exit status of 124 is returned.
125 If an invalid parameter is passed to
129 the exit status returned is 125.
133 is an otherwise invalid program, the exit status returned is 126.
137 refers to a non-existing program, the exit status returned is 127.
141 exits after receiving a signal, the exit status returned is the signal number
146 with a time limit of 4 seconds.
147 Since the command completes in 2 seconds, the exit status is 0:
148 .Bd -literal -offset indent
156 for 4 seconds and terminate process after 2 seconds.
157 124 is returned since no
160 .Bd -literal -offset indent
166 Same as above but preserving status.
167 Exit status is 128 + signal number (15 for
169 .Bd -literal -offset indent
170 $ timeout --preserve-status 2 sleep 4
175 Same as above but sending
177 (signal number 14) instead of
179 .Bd -literal -offset indent
180 $ timeout --preserve-status -s SIGALRM 2 sleep 4
187 the single page version of the
192 signal after 1 minute and send a
194 signal 5 seconds later if the process refuses to stop:
195 .Bd -literal -offset indent
196 timeout -k 5s 1m fetch \\
197 https://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/book.html
205 command first appeared in
207 and was imported into
212 work is compatible with GNU
216 from GNU Coreutils 8.21.
219 utility first appeared in GNU Coreutils 7.0.
221 .An Baptiste Daroussin Aq Mt bapt@FreeBSD.org
223 .An Vsevolod Stakhov Aq Mt vsevolod@FreeBSD.org