summary refs log tree commit diff
path: root/doc/wait.html
blob: a66cefcdf162e4564e6e1b8194b78456bf90d8a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="Content-Language" content="en" />
  <title>execline: the wait command</title>
  <meta name="Description" content="execline: the wait command" />
  <meta name="Keywords" content="execline command wait" />
  <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
 </head>
<body>

<p>
<a href="index.html">execline</a><br />
<a href="//skarnet.org/software/">Software</a><br />
<a href="//skarnet.org/">skarnet.org</a>
</p>

<h1> The <tt>wait</tt> program </h1>

<p>
<tt>wait</tt> waits for a set of children, then executes a program.
</p>

<h2> Interface </h2>

<p>
 In an <a href="execlineb.html">execlineb</a> script:
</p>

<pre>
     wait [ -I | -i ] [ -a | -o ] [ -r | -t <em>timeout</em> ] { [ <em>pids...</em> ] } <em>prog...</em>
</pre>

<ul>
 <li> <tt>wait</tt> reads a list of <em>pids</em> in a
(possibly empty) <a href="el_semicolon.html">block</a>,
and unquotes it. </li>
 <li> <tt>wait</tt> waits for every child whose pid is
listed in <em>pids...</em>. If <em>pids...</em> is an
empty list, it waits for every child process it has. </li>
 <li><tt>wait</tt> then execs into <em>prog...</em>. </li>
</ul>

<h2> Options </h2>

<ul>
 <li> <tt>-r</tt>&nbsp;: equivalent to <tt>-t&nbsp;0</tt>. Do not
pause: only reap processes that are already dead when <tt>wait</tt>
is invoked. </li>
 <li> <tt>-t</tt>&nbsp;<em>timeout</em>&nbsp;: wait for a maximum
of <em>timeout</em> milliseconds. If there still are living processes
among <em>pids...</em> (or among <tt>wait</tt>'s children if
<em>pids...</em> is an empty list), after <em>timeout</em>
milliseconds, they will not be reaped. </li>
 <li> <tt>-I</tt>&nbsp;: loose. If <tt>wait</tt> times out while
waiting for children to die, it will still
exec into <em>prog...</em>. This is the default. </li>
 <li> <tt>-i</tt>&nbsp;: strict. If <tt>wait</tt> times out, it
will print an error message and exit 99. </li>
 <li> <tt>-o</tt>&nbsp;: wait for <em>one</em> of the listed
<em>pids</em> &mdash; exec into <em>prog</em> as soon as one of the
listed children dies. (If no pid is listed, wait for one child to die.)
The <tt>!</tt> environment variable will be set to the
pid that died, and the <tt>?</tt> environment variable will contain an
<a href="exitcodes.html">approximation</a> of its exit code. If no
listed child has died before <tt>wait</tt> has to exec (either because
it timed out or it has no suitable children left), the <tt>?</tt> and
<tt>!</tt> environment variables are unset. </li>
<li> <tt>-a</tt>&nbsp;: wait for <em>all</em> of the listed <em>pids</em>.
Do not touch the <tt>!</tt> or <tt>?</tt> variables. This is the default. </li>
</ul>

<h2> Notes </h2>

<ul>
 <li> For <a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/wait.html">POSIX
compatibility</a>, <tt>wait</tt> also works when it cannot find a block.
In that case, all the options are still supported and have the same
effect, but the rest of the command line is interpreted as <em>pids...</em>
arguments and <tt>wait</tt> does not execute into a program; instead, it exits
with a conforming exit code. </li>
</ul>

</body>
</html>