1 WAIT(1)                          User Commands                         WAIT(1)
   2 
   3 
   4 
   5 NAME
   6        wait - await process completion
   7 
   8 SYNOPSIS
   9 
  10 
  11 
  12    /bin/sh
  13        wait [pid]...
  14 
  15 
  16    /bin/jsh /bin/ksh /usr/xpg4/bin/sh
  17        wait [pid]...
  18 
  19 
  20        wait [% jobid...]
  21 
  22 
  23    /bin/csh
  24        wait
  25 
  26 
  27    ksh93
  28        wait [job...]
  29 
  30 
  31 DESCRIPTION
  32        The shell itself executes wait, without creating a new process. If you
  33        get the error message cannot fork,too many processes, try using the
  34        wait command to clean up your background processes. If this doesn't
  35        help, the system process table is probably full or you have too many
  36        active foreground processes. There is a limit to the number of process
  37        IDs associated with your login, and to the number the system can keep
  38        track of.
  39 
  40 
  41        Not all the processes of a pipeline with three or more stages are
  42        children of the shell, and thus cannot be waited for.
  43 
  44    /bin/sh, /bin/jsh
  45        Wait for your background process whose process ID is pid and report its
  46        termination status. If pid is omitted, all your shell's currently
  47        active background processes are waited for and the return code is 0.
  48        The wait utility accepts a job identifier, when Job Control is enabled
  49        (jsh), and the argument, jobid, is preceded by a percent sign (%).
  50 
  51 
  52        If pid is not an active process ID, the wait utility returns
  53        immediately and the return code is 0.
  54 
  55    csh
  56        Wait for your background processes.
  57 
  58    ksh
  59        When an asynchronous list is started by the shell, the process ID of
  60        the last command in each element of the asynchronous list becomes known
  61        in the current shell execution environment.
  62 
  63 
  64        If the wait utility is invoked with no operands, it waits until all
  65        process IDs known to the invoking shell have terminated and exit with
  66        an exit status of 0.
  67 
  68 
  69        If one or more pid or jobid operands are specified that represent known
  70        process IDs (or jobids), the wait utility waits until all of them have
  71        terminated. If one or more pid or jobid operands are specified that
  72        represent unknown process IDs (or jobids), wait treats them as if they
  73        were known process IDs (or jobids) that exited with exit status 127.
  74        The exit status returned by the wait utility is the exit status of the
  75        process requested by the last pid or jobid operand.
  76 
  77 
  78        The known process IDs are applicable only for invocations of wait in
  79        the current shell execution environment.
  80 
  81    ksh93
  82        wait with no operands, waits until all jobs known to the invoking shell
  83        have terminated. If one or more job operands are specified, wait waits
  84        until all of them have completed. Each job can be specified as one of
  85        the following:
  86 
  87        number
  88                    number refers to a process ID.
  89 
  90 
  91        -number
  92                    number refers to a process group ID.
  93 
  94 
  95        %number
  96                    number refers to a job number
  97 
  98 
  99        %string
 100                    Refers to a job whose name begins with string
 101 
 102 
 103        %?string
 104                    Refers to a job whose name contains string
 105 
 106 
 107        %+
 108        %%
 109                    Refers to the current job
 110 
 111 
 112        %-
 113                    Refers to the previous job
 114 
 115 
 116 
 117        If one or more job operands is a process id or process group id not
 118        known by the current shell environment, wait treats each of them as if
 119        it were a process that exited with status 127.
 120 
 121 OPERANDS
 122        The following operands are supported:
 123 
 124        pid
 125                 The unsigned decimal integer process ID of a command, for
 126                 which the utility is to wait for the termination.
 127 
 128 
 129        jobid
 130                 A job control job ID that identifies a background process
 131                 group to be waited for. The job control job ID notation is
 132                 applicable only for invocations of wait in the current shell
 133                 execution environment, and only on systems supporting the job
 134                 control option.
 135 
 136 
 137 USAGE
 138        On most implementations, wait is a shell built-in. If it is called in a
 139        subshell or separate utility execution environment, such as one of the
 140        following,
 141 
 142          (wait)
 143          nohup wait ...
 144          find . -exec wait ... \;
 145 
 146 
 147 
 148 
 149        it returns immediately because there is no known process IDs to wait
 150        for in those environments.
 151 
 152 EXAMPLES
 153        Example 1 Using A Script To Identify The Termination Signal
 154 
 155 
 156        Although the exact value used when a process is terminated by a signal
 157        is unspecified, if it is known that a signal terminated a process, a
 158        script can still reliably figure out which signal is using kill, as
 159        shown by the following (/bin/ksh and /usr/xpg4/bin/sh):
 160 
 161 
 162          sleep 1000&
 163          pid=$!
 164          kill -kill $pid
 165          wait $pid
 166          echo $pid was terminated by a SIG$(kill -l $(($?-128))) signal.
 167 
 168 
 169 
 170        Example 2 Returning The Exit Status Of A Process
 171 
 172 
 173        If the following sequence of commands is run in less than 31 seconds
 174        (/bin/ksh and /usr/xpg4/bin/sh):
 175 
 176 
 177          sleep 257 | sleep 31 &
 178 
 179          jobs -l %%
 180 
 181 
 182 
 183 
 184        then either of the following commands returns the exit status of the
 185        second sleep in the pipeline:
 186 
 187 
 188          wait <pid of sleep 31>
 189          wait %%
 190 
 191 
 192 
 193 ENVIRONMENT VARIABLES
 194        See environ(5) for descriptions of the following environment variables
 195        that affect the execution of wait: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
 196        and NLSPATH.
 197 
 198 EXIT STATUS
 199    ksh93
 200        The following exit values are returned by the wait built-in in ksh93:
 201 
 202        0
 203               wait was invoked with no operands. All processes known by the
 204               invoking process have terminated.
 205 
 206 
 207        127
 208               job is a process id or process group id that is unknown to the
 209               current shell environment.
 210 
 211 
 212 ATTRIBUTES
 213        See attributes(5) for descriptions of the following attributes:
 214 
 215 
 216 
 217 
 218        +--------------------+-------------------+
 219        |  ATTRIBUTE TYPE    |  ATTRIBUTE VALUE  |
 220        +--------------------+-------------------+
 221        |Interface Stability | Committed         |
 222        +--------------------+-------------------+
 223        |Standard            | See standards(5). |
 224        +--------------------+-------------------+
 225 
 226 SEE ALSO
 227        csh(1), jobs(1), ksh(1), ksh93(1), sh(1), attributes(5), environ(5),
 228        standards(5)
 229 
 230 
 231 
 232                                  May 17, 2020                          WAIT(1)