1.\" 2.\" Copyright (c) 2004-2009, Jilles Tjoelker 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with 6.\" or without modification, are permitted provided that the 7.\" following conditions are met: 8.\" 9.\" 1. Redistributions of source code must retain the above 10.\" copyright notice, this list of conditions and the 11.\" following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the 13.\" above copyright notice, this list of conditions and 14.\" the following disclaimer in the documentation and/or 15.\" other materials provided with the distribution. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 18.\" CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED 19.\" WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 21.\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22.\" COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY 23.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 26.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31.\" OF SUCH DAMAGE. 32.\" 33.Dd July 27, 2026 34.Dt PWAIT 1 35.Os 36.Sh NAME 37.Nm pwait 38.Nd wait for processes to terminate 39.Sh SYNOPSIS 40.Nm 41.Op Fl t Ar duration 42.Op Fl oprv 43.Ar pid 44\&... 45.Sh DESCRIPTION 46The 47.Nm 48utility will wait until each of the given processes has terminated. 49.Pp 50The following option is available: 51.Bl -tag -width indent 52.It Fl o 53Exit when any of the given processes has terminated. 54.It Fl p 55On exit, print a list of processes that have not terminated. 56.It Fl r 57Do not exit until target processes have not only terminated, but been 58reaped by a call to the 59.Xr wait 2 60family of functions. 61Without this flag, target processes may still exist as zombies when 62.Nm 63exits. 64Beware of deadlocks if a target process's reaper (usually its parent) 65is directly or indirectly blocked by 66.Nm . 67.It Fl t Ar duration 68If any process is still running after 69.Ar duration , 70.Nm 71will exit. 72The 73.Ar duration 74value can be integer or decimal numbers. 75Values without unit symbols are interpreted as seconds. 76.Pp 77Supported unit symbols are: 78.Bl -tag -width indent -compact 79.It s 80seconds 81.It m 82minutes 83.It h 84hours 85.El 86.It Fl v 87Print the exit status when each process terminates or 88.Ql timeout 89if the timer goes off earlier. 90.El 91.Pp 92If 93.Nm 94receives 95.Dv SIGINFO 96(see the 97.Sy status 98argument for 99.Xr stty 1 ) 100signal, 101a space-separated list of processes still being waited on is printed 102to the standard error output. 103.Sh EXIT STATUS 104The 105.Nm 106utility exits 0 on success, and >0 if an error occurs. 107.Pp 108If the 109.Fl t 110flag is specified and a timeout occurs, the exit status will be 124. 111.Pp 112Invalid pids elicit a warning message but are otherwise ignored. 113.Sh EXAMPLES 114Start two 115.Xr sleep 1 116processes in the background. 117The first one will sleep for 30 seconds and the second one for one hour. 118Wait for any of them to finish but no more than 5 seconds. 119Since a timeout occurs the exit status is 124: 120.Bd -literal -offset indent 121$ sleep 30 & sleep 3600 & 122[1] 1646 123[2] 1647 124$ pwait -o -t5 1646 1647 125$ echo $? 126124 127.Ed 128.Pp 129Same as above but try to obtain the exit status of the processes. 130In this case 131.Ql timeout 132is shown and the exit status is 124: 133.Bd -literal -offset indent 134$ sleep 30 & sleep 3600 & 135[1] 1652 136[2] 1653 137$ pwait -v -t 5 1652 1653 138timeout 139$ echo $? 140124 141.Ed 142.Pp 143Start two 144.Xr sleep 1 145processes in the background sleeping for 30 and 40 seconds respectively. 146Wait 60 seconds for any of them to finish and get their exit codes: 147.Bd -literal -offset indent 148$ sleep 30 & sleep 40 & 149[1] 1674 150[2] 1675 151$ pwait -v -t 60 1674 1675 1521674: exited with status 0. 153[1]- Done sleep 30 1541675: exited with status 0. 155[2]+ Done sleep 40 156$ echo $? 1570 158.Ed 159.Sh SEE ALSO 160.Xr kill 1 , 161.Xr pkill 1 , 162.Xr ps 1 , 163.Xr stty 1 , 164.Xr wait 1 , 165.Xr kqueue 2 166.Sh NOTES 167.Nm 168is not a substitute for the 169.Xr wait 1 170builtin 171as it will not clean up any zombies or state in the parent process. 172.Pp 173To avoid deadlock, 174.Nm 175will ignore its own pid, if it is provided as a process id to wait for. 176.Sh HISTORY 177A 178.Nm 179command first appeared in SunOS 5.8. 180