chiark / gitweb /
mtimeout.c: Accept time unit specification on timeout options.
[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
e825e5a9
MW
7.RB [ \-s
8.IR signal ]
753f86de 9.I time
e825e5a9
MW
10.I command
11.RI [ arguments ...]
12.
13.SH DESCRIPTION
14The
58b43082 15.B mtimeout
753f86de
MW
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.
e825e5a9
MW
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
58b43082 34.B mtimeout
e825e5a9
MW
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
58b43082 39.B mtimeout
e825e5a9
MW
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
58b43082 49.B mtimeout
e825e5a9
MW
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 ).
25ae65a8
MW
74.PP
75The
58b43082 76.B mtimeout
25ae65a8
MW
77program sets its exit status as follows.
78.TP
790\(em127
80The child process ran to completion within the given time:
58b43082 81.BR mtimeout 's
25ae65a8
MW
82exit status is the same as that of the child process.
83.TP
84128
85The child process exited in a way which
58b43082 86.B mtimeout
25ae65a8
MW
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
58b43082 92.B mtimeout
25ae65a8
MW
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:
58b43082 98.B mtimeout
25ae65a8
MW
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
58b43082 107.B mtimeout
25ae65a8
MW
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
58b43082 113.B mtimeout
25ae65a8
MW
114failed unexpectedly: an error message was written to standard error.
115.TP
116255
117Not used.
e825e5a9
MW
118.
119.SH BUGS
120Because
58b43082 121.B mtimeout
e825e5a9
MW
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
58b43082 129.B mtimeout
e825e5a9
MW
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
58b43082 143.B mtimeout
e825e5a9
MW
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
58b43082 151.B mtimeout
e825e5a9
MW
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>