chiark / gitweb /
mtimeout.c: Fix ludicrous whitespace in help message.
[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.B "\-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
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.TP
128128
129The child process exited in a way which
130.B mtimeout
131could not interpret.
132.TP
133129\(em250
134The child process was killed by a signal: the exit status is 128 higher
135than the signal number. If
136.B mtimeout
137had to kill the child because it took too long, then its exit status
138will be like this.
139.TP
140251
141The child took too long and couldn't be killed:
142.B mtimeout
143gave up waiting.
144.TP
145252
146The target program couldn't be started: an error message was written to
147standard error.
148.TP
149253
150The
151.B mtimeout
152program couldn't parse the arguments provided to it: an error message
153was written to standard error.
154.TP
155254
156A system call made by
157.B mtimeout
158failed unexpectedly: an error message was written to standard error.
159.TP
160255
161Not used.
162.
163.SH BUGS
164Because
165.B mtimeout
166works by running its child process in a separate process group, it
167interacts oddly with interactive shells. If the child process group
168attempts to do terminal I/O (particularly reading from a terminal) then
169it may be sent signals to suspend it. This may or may not make matters
170worse.
171.PP
172The
173.B mtimeout
174program makes an effort to propagate interesting signals to its child
175process group. Currently, it propagates
176.BR SIGTSTP ,
177.BR SIGCONT ,
178.BR SIGINT ,
179.BR SIGHUP ,
180and
181.BR SIGQUIT .
182This list is subject to change: I don't think I'm likely to remove any
183of the current signals from it, but I might add some; or I might add an
184option to control this list.
185.PP
186If you suspend
187.B mtimeout
188and its child process group, the timer continues running anyway. (I'm
189not quite sure whether this is the right behaviour.)
190.PP
191Nested timeouts don't work in a useful way if the outer timeout expires
192earlier than the inner one. Since
193.B SIGTERM
194isn't propagated (currently, at least), the inner
195.B mtimeout
196is killed by the outer one, and loses control of its child process
197group. You could possibly work around this by sending
198.B SIGQUIT
199instead.
200.PP
201Perhaps it would be useful to allow configuration of the `panic'
202timeouts after the initial timeout signal is sent.
203.
204.SH AUTHOR
205Mark Wooding, <mdw@distorted.org.uk>