Release 1.4.3.
[misc] / mtimeout.1
... / ...
CommitLineData
1.TH "mtimeout" 1 "5 June 2011" "Mark Wooding" "Toys"
2.SH NAME
3mtimeout \- run a program for at most a given amount of time
4.
5.SH SYNOPSIS
6.B mtimeout
7.RB [ \-K ]
8.RB [ \-k
9.IR time ]
10.RB [ \-b
11.IR time ]
12.RB [ \-s
13.IR signal ]
14.br
15 \c
16.I time
17.I command
18.RI [ arguments ...]
19.
20.SH DESCRIPTION
21The
22.B mtimeout
23command runs a specified program for at most a given amount of
24.IR time .
25The
26.I time
27may be fractional (with a decimal point), and may be followed by a unit
28suffix:
29.RB ` s '
30for seconds,
31.RB ` m '
32for minutes,
33.RB ` h '
34for hours, and
35.RB ` d '
36for days.
37.PP
38It works by running the given command as a separate process group. It
39then waits either for the top-level process (only) to exit, or for the
40timeout to expire, whichever happens first. If the process exits, then
41.B mtimeout
42exits too, setting its exit status to match. Any other processes which
43may have been started are left unmolested.
44.PP
45On the other hand, if the timeout goes off, then
46.B mtimeout
47sends its child process group the specified signal, by default
48.BR SIGTERM ,
49though you can choose a different one with the
50.B \-s
51option. It then waits an additional five seconds (configurable with
52the
53.B \-k
54option). If the child still hasn't exited, it sends
55.B SIGKILL
56to the process group and waits a further five seconds (configurable
57with the
58.B \-b
59option). If the child still hasn't exited in this time, then
60.B mtimeout
61gives up and exits.
62.PP
63The following command-line options are recognized.
64.TP
65.B \-h, \-\-help
66Prints a reasonably full help message describing the arguments and
67options to standard output, and exits successfully.
68.TP
69.B \-v, \-\-version
70Prints the program's version number to standard output, and exits
71successfully.
72.TP
73.B \-u, \-\-usage
74Prints a brief usage summary to standard output, and exits successfully.
75.TP
76.BI "\-b, \-\-bored-after=" time
77After sending
78.B SIGKILL
79(or, with
80.BR \-K ,
81the original signal)
82wait for
83.I time
84before giving up and declaring the child process undead. The default
85wait is five seconds. The
86.I time
87may have a unit suffix.
88.TP
89.B "\-K, \-\-no-kill"
90Don't send a
91.B SIGKILL
92to the process: just wait for a while (see the
93.B \-b
94option) after sending the original signal to see whether it actually
95dies.
96.TP
97.BI "\-k, \-\-kill-after=" time
98After sending a signal, wait for
99.I time
100before sending
101.BR SIGKILL .
102The default wait is five seconds. The
103.I time
104may have a unit suffix.
105This option has no effect if
106.BR \-K
107is set.
108.TP
109.BI "\-s, \-\-signal=" signal
110Send
111.I signal
112to the child process if it takes too long. The default is to send
113.BR SIGTERM .
114A signal may be given numerically (e.g., 9 for
115.BR SIGKILL )
116or by name (e.g.,
117.BR KILL ).
118.PP
119The
120.B mtimeout
121program sets its exit status as follows.
122.TP
1230\(em127, 255
124The child process ran to completion within the given time:
125.BR mtimeout 's
126exit status is the same as that of the child process.
127(Whatever status the child exits with will be propagated;
128but if it exits with some status other than these then
129there is a risk that it will be conflict
130with a status used by
131.B mtimeout
132and be misinterpreted.)
133.TP
134128
135The child process exited in a way which
136.B mtimeout
137could not interpret.
138.TP
139129\(em250
140The child process was killed by a signal: the exit status is 128 higher
141than the signal number. If
142.B mtimeout
143had to kill the child because it took too long, then its exit status
144will be like this.
145.TP
146251
147The child took too long and couldn't be killed:
148.B mtimeout
149gave up waiting.
150.TP
151252
152The target program couldn't be started: an error message was written to
153standard error.
154.TP
155253
156The
157.B mtimeout
158program couldn't parse the arguments provided to it: an error message
159was written to standard error.
160.TP
161254
162A system call made by
163.B mtimeout
164failed unexpectedly: an error message was written to standard error.
165.
166.SH BUGS
167Because
168.B mtimeout
169works by running its child process in a separate process group, it
170interacts oddly with interactive shells. If the child process group
171attempts to do terminal I/O (particularly reading from a terminal) then
172it may be sent signals to suspend it. This may or may not make matters
173worse.
174.PP
175The
176.B mtimeout
177program makes an effort to propagate interesting signals to its child
178process group. Currently, it propagates
179.BR SIGTSTP ,
180.BR SIGCONT ,
181.BR SIGINT ,
182.BR SIGHUP ,
183and
184.BR SIGQUIT .
185This list is subject to change: I don't think I'm likely to remove any
186of the current signals from it, but I might add some; or I might add an
187option to control this list.
188.PP
189If you suspend
190.B mtimeout
191and its child process group, the timer continues running anyway. (I'm
192not quite sure whether this is the right behaviour.)
193.PP
194Nested timeouts don't work in a useful way if the outer timeout expires
195earlier than the inner one. Since
196.B SIGTERM
197isn't propagated (currently, at least), the inner
198.B mtimeout
199is killed by the outer one, and loses control of its child process
200group. You could possibly work around this by sending
201.B SIGQUIT
202instead.
203.PP
204Perhaps it would be useful to allow configuration of the `panic'
205timeouts after the initial timeout signal is sent.
206.
207.SH AUTHOR
208Mark Wooding, <mdw@distorted.org.uk>