chiark / gitweb /
debian/control: Include `prlimit' and `x86-model' in the metapackage.
[misc] / mtimeout.1
CommitLineData
58b43082 1.TH "mtimeout" 1 "5 June 2011" "Mark Wooding" "Toys"
e825e5a9 2.SH NAME
58b43082 3mtimeout \- run a program for at most a given amount of time
e825e5a9
MW
4.
5.SH SYNOPSIS
58b43082 6.B mtimeout
0db9a123
MW
7.RB [ \-K ]
8.RB [ \-k
9.IR time ]
10.RB [ \-b
11.IR time ]
e825e5a9
MW
12.RB [ \-s
13.IR signal ]
0db9a123
MW
14.br
15 \c
753f86de 16.I time
e825e5a9
MW
17.I command
18.RI [ arguments ...]
19.
20.SH DESCRIPTION
21The
58b43082 22.B mtimeout
753f86de
MW
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.
e825e5a9
MW
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
58b43082 41.B mtimeout
e825e5a9
MW
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
58b43082 46.B mtimeout
e825e5a9
MW
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
0db9a123
MW
51option. It then waits an additional five seconds (configurable with
52the
53.B \-k
54option). If the child still hasn't exited, it sends
e825e5a9 55.B SIGKILL
0db9a123
MW
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
58b43082 60.B mtimeout
e825e5a9
MW
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
0db9a123
MW
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
8b3d57aa 97.BI "\-k, \-\-kill-after=" time
0db9a123
MW
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
e825e5a9
MW
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 ).
25ae65a8
MW
118.PP
119The
58b43082 120.B mtimeout
25ae65a8
MW
121program sets its exit status as follows.
122.TP
f54e279c 1230\(em127, 255
25ae65a8 124The child process ran to completion within the given time:
58b43082 125.BR mtimeout 's
25ae65a8 126exit status is the same as that of the child process.
f54e279c
MW
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.)
25ae65a8 133.TP
f658787d
MW
134128
135The child process exited in a way which
136.B mtimeout
137could not interpret.
138.TP
25ae65a8
MW
139129\(em250
140The child process was killed by a signal: the exit status is 128 higher
141than the signal number. If
58b43082 142.B mtimeout
25ae65a8
MW
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:
58b43082 148.B mtimeout
25ae65a8
MW
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
58b43082 157.B mtimeout
25ae65a8
MW
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
58b43082 163.B mtimeout
25ae65a8 164failed unexpectedly: an error message was written to standard error.
e825e5a9
MW
165.
166.SH BUGS
167Because
58b43082 168.B mtimeout
e825e5a9
MW
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
58b43082 176.B mtimeout
e825e5a9
MW
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
58b43082 190.B mtimeout
e825e5a9
MW
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
58b43082 198.B mtimeout
e825e5a9
MW
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>