xref: /dflybsd-src/usr.bin/timeout/timeout.1 (revision 3a777ae4923e1b2f3c2d9866e016da31faeac163)
1ef2b2b9dSAaron LI.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
2ef2b2b9dSAaron LI.\"
3ef2b2b9dSAaron LI.\" Copyright (c) 2014 Baptiste Daroussin <bapt@FreeBSD.org>
4ef2b2b9dSAaron LI.\" All rights reserved.
5ef2b2b9dSAaron LI.\"
6ef2b2b9dSAaron LI.\" Redistribution and use in source and binary forms, with or without
7ef2b2b9dSAaron LI.\" modification, are permitted provided that the following conditions
8ef2b2b9dSAaron LI.\" are met:
9ef2b2b9dSAaron LI.\" 1. Redistributions of source code must retain the above copyright
10ef2b2b9dSAaron LI.\"    notice, this list of conditions and the following disclaimer.
11ef2b2b9dSAaron LI.\" 2. Redistributions in binary form must reproduce the above copyright
12ef2b2b9dSAaron LI.\"    notice, this list of conditions and the following disclaimer in the
13ef2b2b9dSAaron LI.\"    documentation and/or other materials provided with the distribution.
14ef2b2b9dSAaron LI.\"
15ef2b2b9dSAaron LI.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16ef2b2b9dSAaron LI.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17ef2b2b9dSAaron LI.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18ef2b2b9dSAaron LI.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19ef2b2b9dSAaron LI.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20ef2b2b9dSAaron LI.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21ef2b2b9dSAaron LI.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ef2b2b9dSAaron LI.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23ef2b2b9dSAaron LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24ef2b2b9dSAaron LI.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25ef2b2b9dSAaron LI.\" SUCH DAMAGE.
26ef2b2b9dSAaron LI.\"
27ef2b2b9dSAaron LI.\" $FreeBSD$
28ef2b2b9dSAaron LI.\"
294d524481SAaron LI.Dd January 2, 2021
30ef2b2b9dSAaron LI.Dt TIMEOUT 1
31ef2b2b9dSAaron LI.Os
32ef2b2b9dSAaron LI.Sh NAME
33ef2b2b9dSAaron LI.Nm timeout
34ef2b2b9dSAaron LI.Nd run a command with a time limit
35ef2b2b9dSAaron LI.Sh SYNOPSIS
36ef2b2b9dSAaron LI.Nm
37d631f4f3SAaron LI.Op Fl k Ar time | Fl -kill-after Ar time
38d631f4f3SAaron LI.Op Fl s Ar sig | Fl -signal Ar sig
39966d0055SAaron LI.Op Fl v | Fl -verbose
40ef2b2b9dSAaron LI.Op Fl -foreground
41d631f4f3SAaron LI.Op Fl -preserve-status
42ef2b2b9dSAaron LI.Ar duration
43ef2b2b9dSAaron LI.Ar command
44ef2b2b9dSAaron LI.Op Ar args ...
45ef2b2b9dSAaron LI.Sh DESCRIPTION
46ef2b2b9dSAaron LI.Nm
47ef2b2b9dSAaron LIstarts the
48ef2b2b9dSAaron LI.Ar command
49ef2b2b9dSAaron LIwith its
50ef2b2b9dSAaron LI.Ar args .
51ef2b2b9dSAaron LIIf the
52ef2b2b9dSAaron LI.Ar command
53ef2b2b9dSAaron LIis still running after
54ef2b2b9dSAaron LI.Ar duration ,
55ef2b2b9dSAaron LIit is killed.
56ef2b2b9dSAaron LIBy default,
57ef2b2b9dSAaron LI.Dv SIGTERM
58ef2b2b9dSAaron LIis sent.
59ef2b2b9dSAaron LIThe special
60ef2b2b9dSAaron LI.Ar duration ,
61ef2b2b9dSAaron LIzero, signifies no limit.
62ef2b2b9dSAaron LITherefore a signal is never sent if
63ef2b2b9dSAaron LI.Ar duration
64ef2b2b9dSAaron LIis 0.
65ef2b2b9dSAaron LI.Pp
66ef2b2b9dSAaron LIThe options are as follows:
67ef2b2b9dSAaron LI.Bl -tag -width indent
68ef2b2b9dSAaron LI.It Fl k Ar time , Fl -kill-after Ar time
69ef2b2b9dSAaron LISend a
70ef2b2b9dSAaron LI.Dv SIGKILL
71ef2b2b9dSAaron LIsignal if
72ef2b2b9dSAaron LI.Ar command
73ef2b2b9dSAaron LIis still running after
74ef2b2b9dSAaron LI.Ar time
75ef2b2b9dSAaron LIafter the first signal was sent.
76d631f4f3SAaron LI.It Fl s Ar sig , Fl -signal Ar sig
77d631f4f3SAaron LISpecify the signal to send on timeout.
78d631f4f3SAaron LIBy default,
79d631f4f3SAaron LI.Dv SIGTERM
80d631f4f3SAaron LIis sent.
81966d0055SAaron LI.It Fl v , Fl -verbose
82966d0055SAaron LIShow information to stderr about any signal sent on timeout.
83d631f4f3SAaron LI.It Fl -foreground
84d631f4f3SAaron LIDo not propagate timeout to the children of
85d631f4f3SAaron LI.Ar command .
86d631f4f3SAaron LI.It Fl -preserve-status
87d631f4f3SAaron LIExit with the same status as
88d631f4f3SAaron LI.Ar command ,
89d631f4f3SAaron LIeven if it times out and is killed.
90ef2b2b9dSAaron LI.El
91ef2b2b9dSAaron LI.Sh DURATION FORMAT
92d631f4f3SAaron LIThe
93ef2b2b9dSAaron LI.Ar duration
94ef2b2b9dSAaron LIand
95ef2b2b9dSAaron LI.Ar time
96ef2b2b9dSAaron LIare non-negative integer or real (decimal) numbers, with an optional
97ef2b2b9dSAaron LIunit-specifying suffix.
98ef2b2b9dSAaron LIValues without an explicit unit are interpreted as seconds.
99ef2b2b9dSAaron LI.Pp
100ef2b2b9dSAaron LISupported unit symbols are:
101d631f4f3SAaron LI.Bl -tag -offset indent -width indent -compact
102ef2b2b9dSAaron LI.It Cm s
103ef2b2b9dSAaron LIseconds
104ef2b2b9dSAaron LI.It Cm m
105ef2b2b9dSAaron LIminutes
106ef2b2b9dSAaron LI.It Cm h
107ef2b2b9dSAaron LIhours
108ef2b2b9dSAaron LI.It Cm d
109ef2b2b9dSAaron LIdays
110ef2b2b9dSAaron LI.El
111ef2b2b9dSAaron LI.Sh EXIT STATUS
112ef2b2b9dSAaron LIIf the timeout was not reached, the exit status of
113ef2b2b9dSAaron LI.Ar command
114ef2b2b9dSAaron LIis returned.
115ef2b2b9dSAaron LI.Pp
116ef2b2b9dSAaron LIIf the timeout was reached and
117ef2b2b9dSAaron LI.Fl -preserve-status
118ef2b2b9dSAaron LIis set, the exit status of
119ef2b2b9dSAaron LI.Ar command
120ef2b2b9dSAaron LIis returned.
121ef2b2b9dSAaron LIIf
122ef2b2b9dSAaron LI.Fl -preserve-status
123ef2b2b9dSAaron LIis not set, an exit status of 124 is returned.
124ef2b2b9dSAaron LI.Pp
125d631f4f3SAaron LIIf an invalid parameter is passed to
126d631f4f3SAaron LI.Fl s
127d631f4f3SAaron LIor
128d631f4f3SAaron LI.Fl k ,
129d631f4f3SAaron LIthe exit status returned is 125.
130d631f4f3SAaron LI.Pp
131ef2b2b9dSAaron LIIf
132ef2b2b9dSAaron LI.Ar command
133d631f4f3SAaron LIis an otherwise invalid program, the exit status returned is 126.
134ef2b2b9dSAaron LI.Pp
135ef2b2b9dSAaron LIIf
136ef2b2b9dSAaron LI.Ar command
137ef2b2b9dSAaron LIrefers to a non-existing program, the exit status returned is 127.
138ef2b2b9dSAaron LI.Pp
139ef2b2b9dSAaron LIIf
140ef2b2b9dSAaron LI.Ar command
141d631f4f3SAaron LIexits after receiving a signal, the exit status returned is the signal number
142d631f4f3SAaron LIplus 128.
143ef2b2b9dSAaron LI.Sh EXAMPLES
144ef2b2b9dSAaron LIRun
145ef2b2b9dSAaron LI.Xr sleep 1
146ef2b2b9dSAaron LIwith a time limit of 4 seconds.
147ef2b2b9dSAaron LISince the command completes in 2 seconds, the exit status is 0:
148ef2b2b9dSAaron LI.Bd -literal -offset indent
149ef2b2b9dSAaron LI$ timeout 4 sleep 2
150ef2b2b9dSAaron LI$ echo $?
151ef2b2b9dSAaron LI0
152ef2b2b9dSAaron LI.Ed
153ef2b2b9dSAaron LI.Pp
154ef2b2b9dSAaron LIRun
155ef2b2b9dSAaron LI.Xr sleep 1
156ef2b2b9dSAaron LIfor 4 seconds and terminate process after 2 seconds.
157ef2b2b9dSAaron LI124 is returned since no
158ef2b2b9dSAaron LI.Fl -preserve-status
159ef2b2b9dSAaron LIis used:
160ef2b2b9dSAaron LI.Bd -literal -offset indent
161ef2b2b9dSAaron LI$ timeout 2 sleep 4
162ef2b2b9dSAaron LI$ echo $?
163ef2b2b9dSAaron LI124
164ef2b2b9dSAaron LI.Ed
165ef2b2b9dSAaron LI.Pp
166ef2b2b9dSAaron LISame as above but preserving status.
167ef2b2b9dSAaron LIExit status is 128 + signal number (15 for
168ef2b2b9dSAaron LI.Va SIGTERM )
169ef2b2b9dSAaron LI.Bd -literal -offset indent
170ef2b2b9dSAaron LI$ timeout --preserve-status 2 sleep 4
171ef2b2b9dSAaron LI$ echo $?
172ef2b2b9dSAaron LI143
173ef2b2b9dSAaron LI.Ed
174ef2b2b9dSAaron LI.Pp
175ef2b2b9dSAaron LISame as above but sending
176ef2b2b9dSAaron LI.Va SIGALRM
177ef2b2b9dSAaron LI(signal number 14) instead of
178ef2b2b9dSAaron LI.Va SIGTERM
179ef2b2b9dSAaron LI.Bd -literal -offset indent
180ef2b2b9dSAaron LI$ timeout --preserve-status -s SIGALRM 2 sleep 4
181ef2b2b9dSAaron LI$ echo $?
182ef2b2b9dSAaron LI142
183ef2b2b9dSAaron LI.Ed
184ef2b2b9dSAaron LI.Pp
185ef2b2b9dSAaron LITry to
186ef2b2b9dSAaron LI.Xr fetch 1
187ef2b2b9dSAaron LIthe single page version of the
188ef2b2b9dSAaron LI.Fx
189ef2b2b9dSAaron LIHandbook.
190ef2b2b9dSAaron LISend a
191ef2b2b9dSAaron LI.Va SIGTERM
192ef2b2b9dSAaron LIsignal after 1 minute and send a
193ef2b2b9dSAaron LI.Va SIGKILL
194ef2b2b9dSAaron LIsignal 5 seconds later if the process refuses to stop:
195ef2b2b9dSAaron LI.Bd -literal -offset indent
196ef2b2b9dSAaron LItimeout -k 5s 1m fetch \\
197ef2b2b9dSAaron LIhttps://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/book.html
198ef2b2b9dSAaron LI.Ed
199ef2b2b9dSAaron LI.Sh SEE ALSO
200ef2b2b9dSAaron LI.Xr kill 1 ,
201ef2b2b9dSAaron LI.Xr signal 3
202ef2b2b9dSAaron LI.Sh HISTORY
203ef2b2b9dSAaron LIThe
204ef2b2b9dSAaron LI.Nm
205ef2b2b9dSAaron LIcommand first appeared in
2064d524481SAaron LI.Fx 10.3 ,
2074d524481SAaron LIand was imported into
2084d524481SAaron LI.Dx 5.9 .
209d631f4f3SAaron LI.Pp
210*3a777ae4SSascha WildnerThe
211*3a777ae4SSascha Wildner.Fx
212*3a777ae4SSascha Wildnerwork is compatible with GNU
213d631f4f3SAaron LI.Nm
214d631f4f3SAaron LIby
215d631f4f3SAaron LI.An Padraig Brady ,
216d631f4f3SAaron LIfrom GNU Coreutils 8.21.
217d631f4f3SAaron LIThe
218d631f4f3SAaron LI.Nm
219d631f4f3SAaron LIutility first appeared in GNU Coreutils 7.0.
220ef2b2b9dSAaron LI.Sh AUTHORS
221ef2b2b9dSAaron LI.An Baptiste Daroussin Aq Mt bapt@FreeBSD.org
222ef2b2b9dSAaron LIand
223ef2b2b9dSAaron LI.An Vsevolod Stakhov Aq Mt vsevolod@FreeBSD.org
224