aboutsummaryrefslogtreecommitdiffstats
path: root/doc/wait.html
blob: d38b06a79c6eb8a12e0eab452e7d759781798a35 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="color-scheme" content="dark light" />
  <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 [ -a | -o ] [ -u ] [ -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>-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 waited for. In particular, <tt>-t0</tt>
tells <tt>wait</tt> to perform a single reaping pass on current zombies
and immediately exec into <em>prog...</em>. </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.)
<li> <tt>-a</tt>&nbsp;: wait for <em>all</em> of the listed <em>pids</em>.
This is the default. </li>
 <li> <tt>-u</tt>&nbsp;: do not export the result in the environment,
even if <tt>wait</tt> succeeds. </li>
</ul>

<h2> Environment variables </h2>

<p>
 If the <tt>-u</tt> option has been given, <tt>wait</tt> execs into <em>prog...</em>
with the <tt>!</tt> and <tt>?</tt> environment variables unset. Same thing if an
error occurred before <tt>wait</tt> could successfully reap a zombie.
</p>

<p>
 Otherwise, the <tt>!</tt> environment variable is set to the pid of a reapt zombie,
and the <tt>?</tt> environment variable is set to its exit code. Here is how <tt>wait</tt>
decides what pid to report:
</p>

<ul>
 <li> If the <tt>-o</tt> option has been given, <tt>!</tt> is set to the pid of <em>the<em>
one zombie that has just been reapt. </li>
 <li> Otherwise, if <tt>wait</tt> has been given an empty list of pids (meaning it should
wait for all of its children), then <tt>!</tt> is set to the pid of the last child it has
waited for. If there were no children, <tt>!</tt> and <tt>?</tt> are unset. </li>
 <li> Otherwise, <tt>!</tt> is set to the <em>last</em> pid in the list provided to <tt>wait</tt>. </li>
</ul>

<h2> Notes </h2>

<ul>
 <li> For <a href="https://pubs.opengroup.org/onlinepubs/9799919799/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>