xref: /freebsd/bin/pwait/pwait.1 (revision 1a7c9e1585dd3ae14b03226e359d434c10066bfb)
10e5e4167SJilles Tjoelker.\"
20e5e4167SJilles Tjoelker.\" Copyright (c) 2004-2009, Jilles Tjoelker
30e5e4167SJilles Tjoelker.\" All rights reserved.
40e5e4167SJilles Tjoelker.\"
50e5e4167SJilles Tjoelker.\" Redistribution and use in source and binary forms, with
60e5e4167SJilles Tjoelker.\" or without modification, are permitted provided that the
70e5e4167SJilles Tjoelker.\" following conditions are met:
80e5e4167SJilles Tjoelker.\"
90e5e4167SJilles Tjoelker.\" 1. Redistributions of source code must retain the above
100e5e4167SJilles Tjoelker.\"    copyright notice, this list of conditions and the
110e5e4167SJilles Tjoelker.\"    following disclaimer.
120e5e4167SJilles Tjoelker.\" 2. Redistributions in binary form must reproduce the
130e5e4167SJilles Tjoelker.\"    above copyright notice, this list of conditions and
140e5e4167SJilles Tjoelker.\"    the following disclaimer in the documentation and/or
150e5e4167SJilles Tjoelker.\"    other materials provided with the distribution.
160e5e4167SJilles Tjoelker.\"
170e5e4167SJilles Tjoelker.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
180e5e4167SJilles Tjoelker.\" CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
190e5e4167SJilles Tjoelker.\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
200e5e4167SJilles Tjoelker.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
210e5e4167SJilles Tjoelker.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
220e5e4167SJilles Tjoelker.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
230e5e4167SJilles Tjoelker.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240e5e4167SJilles Tjoelker.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
250e5e4167SJilles Tjoelker.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
260e5e4167SJilles Tjoelker.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
270e5e4167SJilles Tjoelker.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
280e5e4167SJilles Tjoelker.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
290e5e4167SJilles Tjoelker.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
300e5e4167SJilles Tjoelker.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
310e5e4167SJilles Tjoelker.\" OF SUCH DAMAGE.
320e5e4167SJilles Tjoelker.\"
335bdce6ffSAlexander V. Chernikov.Dd January 21, 2021
340e5e4167SJilles Tjoelker.Dt PWAIT 1
35aa12cea2SUlrich Spörlein.Os
360e5e4167SJilles Tjoelker.Sh NAME
370e5e4167SJilles Tjoelker.Nm pwait
380e5e4167SJilles Tjoelker.Nd wait for processes to terminate
390e5e4167SJilles Tjoelker.Sh SYNOPSIS
400e5e4167SJilles Tjoelker.Nm
41b06b52baSBryan Drewery.Op Fl t Ar duration
422362bc2cSPawel Jakub Dawidek.Op Fl ov
430e5e4167SJilles Tjoelker.Ar pid
440e5e4167SJilles Tjoelker\&...
450e5e4167SJilles Tjoelker.Sh DESCRIPTION
460e5e4167SJilles TjoelkerThe
470e5e4167SJilles Tjoelker.Nm
480e5e4167SJilles Tjoelkerutility will wait until each of the given processes has terminated.
490e5e4167SJilles Tjoelker.Pp
500e5e4167SJilles TjoelkerThe following option is available:
510e5e4167SJilles Tjoelker.Bl -tag -width indent
522362bc2cSPawel Jakub Dawidek.It Fl o
532362bc2cSPawel Jakub DawidekExit when any of the given processes has terminated.
54b06b52baSBryan Drewery.It Fl t Ar duration
55b06b52baSBryan DreweryIf any process is still running after
56b06b52baSBryan Drewery.Ar duration ,
57b06b52baSBryan Drewery.Nm
58b06b52baSBryan Drewerywill exit.
59b06b52baSBryan DreweryThe
60b06b52baSBryan Drewery.Ar duration
61b06b52baSBryan Dreweryvalue can be integer or decimal numbers.
62b06b52baSBryan DreweryValues without unit symbols are interpreted as seconds.
63b06b52baSBryan Drewery.Pp
64b06b52baSBryan DrewerySupported unit symbols are:
65b06b52baSBryan Drewery.Bl -tag -width indent -compact
66b06b52baSBryan Drewery.It s
67b06b52baSBryan Dreweryseconds
68b06b52baSBryan Drewery.It m
69b06b52baSBryan Dreweryminutes
70b06b52baSBryan Drewery.It h
71b06b52baSBryan Dreweryhours
72b06b52baSBryan Drewery.El
730e5e4167SJilles Tjoelker.It Fl v
74270a4869SFernando ApesteguíaPrint the exit status when each process terminates or
75270a4869SFernando Apesteguía.Ql timeout
76270a4869SFernando Apesteguíaif the timer goes off earlier.
770e5e4167SJilles Tjoelker.El
78b06b52baSBryan Drewery.Sh EXIT STATUS
790e5e4167SJilles TjoelkerThe
800e5e4167SJilles Tjoelker.Nm
81b06b52baSBryan Dreweryutility exits 0 on success, and >0 if an error occurs.
82b06b52baSBryan Drewery.Pp
83b06b52baSBryan DreweryIf the
84b06b52baSBryan Drewery.Fl t
85b06b52baSBryan Dreweryflag is specified and a timeout occurs, the exit status will be 124.
860e5e4167SJilles Tjoelker.Pp
870e5e4167SJilles TjoelkerInvalid pids elicit a warning message but are otherwise ignored.
88270a4869SFernando Apesteguía.Sh EXAMPLES
89270a4869SFernando ApesteguíaStart two
90270a4869SFernando Apesteguía.Xr sleep 1
91270a4869SFernando Apesteguíaprocesses in the background.
92270a4869SFernando ApesteguíaThe first one will sleep for 30 seconds and the second one for one hour.
93270a4869SFernando ApesteguíaWait for any of them to finish but no more than 5 seconds.
94270a4869SFernando ApesteguíaSince a timeout occurs the exit status is 124:
95270a4869SFernando Apesteguía.Bd -literal -offset indent
96270a4869SFernando Apesteguía$ sleep 30 & sleep 3600 &
97270a4869SFernando Apesteguía[1] 1646
98270a4869SFernando Apesteguía[2] 1647
99270a4869SFernando Apesteguía$ pwait -o -t5 1646 1647
100*1a7c9e15SMike Karels$ echo $?
101270a4869SFernando Apesteguía124
102270a4869SFernando Apesteguía.Ed
103270a4869SFernando Apesteguía.Pp
104270a4869SFernando ApesteguíaSame as above but try to obtain the exit status of the processes.
105270a4869SFernando ApesteguíaIn this case
106270a4869SFernando Apesteguía.Ql timeout
107270a4869SFernando Apesteguíais shown and the exit status is 124:
108270a4869SFernando Apesteguía.Bd -literal -offset indent
109270a4869SFernando Apesteguía$ sleep 30 & sleep 3600 &
110270a4869SFernando Apesteguía[1] 1652
111270a4869SFernando Apesteguía[2] 1653
112270a4869SFernando Apesteguía$ pwait -v -t 5 1652 1653
113270a4869SFernando Apesteguíatimeout
114*1a7c9e15SMike Karels$ echo $?
115270a4869SFernando Apesteguía124
116270a4869SFernando Apesteguía.Ed
117270a4869SFernando Apesteguía.Pp
118270a4869SFernando ApesteguíaStart two
119270a4869SFernando Apesteguía.Xr sleep 1
120270a4869SFernando Apesteguíaprocesses in the background sleeping for 30 and 40 seconds respectively.
121270a4869SFernando ApesteguíaWait 60 seconds for any of them to finish and get their exit codes:
122270a4869SFernando Apesteguía.Bd -literal -offset indent
123270a4869SFernando Apesteguía$ sleep 30 & sleep 40 &
124270a4869SFernando Apesteguía[1] 1674
125270a4869SFernando Apesteguía[2] 1675
126270a4869SFernando Apesteguía$ pwait -v -t 60 1674 1675
127270a4869SFernando Apesteguía1674: exited with status 0.
128270a4869SFernando Apesteguía1675: exited with status 0.
129270a4869SFernando Apesteguía[1]-  Done                    sleep 30
130270a4869SFernando Apesteguía[2]+  Done                    sleep 40
131270a4869SFernando Apesteguía$ echo $?
132270a4869SFernando Apesteguía0
133270a4869SFernando Apesteguía.Ed
1340e5e4167SJilles Tjoelker.Sh SEE ALSO
1350e5e4167SJilles Tjoelker.Xr kill 1 ,
1360e5e4167SJilles Tjoelker.Xr pkill 1 ,
1370e5e4167SJilles Tjoelker.Xr ps 1 ,
1380e5e4167SJilles Tjoelker.Xr wait 1 ,
1390e5e4167SJilles Tjoelker.Xr kqueue 2
1400e5e4167SJilles Tjoelker.Sh NOTES
1410e5e4167SJilles Tjoelker.Nm
1420e5e4167SJilles Tjoelkeris not a substitute for the
1430e5e4167SJilles Tjoelker.Xr wait 1
1440e5e4167SJilles Tjoelkerbuiltin
1450e5e4167SJilles Tjoelkeras it will not clean up any zombies or state in the parent process.
1465bdce6ffSAlexander V. Chernikov.Pp
1475bdce6ffSAlexander V. ChernikovTo avoid deadlock,
1485bdce6ffSAlexander V. Chernikov.Nm
1495bdce6ffSAlexander V. Chernikovwill ignore its own pid, if it is provided as a process id to wait for.
1500e5e4167SJilles Tjoelker.Sh HISTORY
1510e5e4167SJilles TjoelkerA
1520e5e4167SJilles Tjoelker.Nm
1530e5e4167SJilles Tjoelkercommand first appeared in SunOS 5.8.
154