chiark / gitweb /
mtimeout.c: Restructure timeout handling to use explicit machine.
[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 [ \-s
8.IR signal ]
9.I time
10.I command
11.RI [ arguments ...]
12.
13.SH DESCRIPTION
14The
15.B mtimeout
16command runs a specified program for at most a given amount of
17.IR time .
18The
19.I time
20may be fractional (with a decimal point), and may be followed by a unit
21suffix:
22.RB ` s '
23for seconds,
24.RB ` m '
25for minutes,
26.RB ` h '
27for hours, and
28.RB ` d '
29for days.
30.PP
31It works by running the given command as a separate process group. It
32then waits either for the top-level process (only) to exit, or for the
33timeout to expire, whichever happens first. If the process exits, then
34.B mtimeout
35exits too, setting its exit status to match. Any other processes which
36may have been started are left unmolested.
37.PP
38On the other hand, if the timeout goes off, then
39.B mtimeout
40sends its child process group the specified signal, by default
41.BR SIGTERM ,
42though you can choose a different one with the
43.B \-s
44option. It then waits an additional five seconds. If the child still
45hasn't exited, it sends
46.B SIGKILL
47to the process group and waits a further five seconds. If the child
48still hasn't exited in this time, then
49.B mtimeout
50gives up and exits.
51.PP
52The following command-line options are recognized.
53.TP
54.B \-h, \-\-help
55Prints a reasonably full help message describing the arguments and
56options to standard output, and exits successfully.
57.TP
58.B \-v, \-\-version
59Prints the program's version number to standard output, and exits
60successfully.
61.TP
62.B \-u, \-\-usage
63Prints a brief usage summary to standard output, and exits successfully.
64.TP
65.BI "\-s, \-\-signal=" signal
66Send
67.I signal
68to the child process if it takes too long. The default is to send
69.BR SIGTERM .
70A signal may be given numerically (e.g., 9 for
71.BR SIGKILL )
72or by name (e.g.,
73.BR KILL ).
74.PP
75The
76.B mtimeout
77program sets its exit status as follows.
78.TP
790\(em127
80The child process ran to completion within the given time:
81.BR mtimeout 's
82exit status is the same as that of the child process.
83.TP
84128
85The child process exited in a way which
86.B mtimeout
87could not interpret.
88.TP
89129\(em250
90The child process was killed by a signal: the exit status is 128 higher
91than the signal number. If
92.B mtimeout
93had to kill the child because it took too long, then its exit status
94will be like this.
95.TP
96251
97The child took too long and couldn't be killed:
98.B mtimeout
99gave up waiting.
100.TP
101252
102The target program couldn't be started: an error message was written to
103standard error.
104.TP
105253
106The
107.B mtimeout
108program couldn't parse the arguments provided to it: an error message
109was written to standard error.
110.TP
111254
112A system call made by
113.B mtimeout
114failed unexpectedly: an error message was written to standard error.
115.TP
116255
117Not used.
118.
119.SH BUGS
120Because
121.B mtimeout
122works by running its child process in a separate process group, it
123interacts oddly with interactive shells. If the child process group
124attempts to do terminal I/O (particularly reading from a terminal) then
125it may be sent signals to suspend it. This may or may not make matters
126worse.
127.PP
128The
129.B mtimeout
130program makes an effort to propagate interesting signals to its child
131process group. Currently, it propagates
132.BR SIGTSTP ,
133.BR SIGCONT ,
134.BR SIGINT ,
135.BR SIGHUP ,
136and
137.BR SIGQUIT .
138This list is subject to change: I don't think I'm likely to remove any
139of the current signals from it, but I might add some; or I might add an
140option to control this list.
141.PP
142If you suspend
143.B mtimeout
144and its child process group, the timer continues running anyway. (I'm
145not quite sure whether this is the right behaviour.)
146.PP
147Nested timeouts don't work in a useful way if the outer timeout expires
148earlier than the inner one. Since
149.B SIGTERM
150isn't propagated (currently, at least), the inner
151.B mtimeout
152is killed by the outer one, and loses control of its child process
153group. You could possibly work around this by sending
154.B SIGQUIT
155instead.
156.PP
157Perhaps it would be useful to allow configuration of the `panic'
158timeouts after the initial timeout signal is sent.
159.
160.SH AUTHOR
161Mark Wooding, <mdw@distorted.org.uk>