### wait -- Wait for Child Process (OS/2)

Format

>     #include <process.h>
>     int wait (int *stat_loc);

Language Level: XPG4, Extension
wait delays a parent process until one of the immediate child processes stops. If all the child processes stop before wait is called, control returns immediately to the parent function.

If stat_loc is NULL, wait does not use it. If it is not NULL, wait places information about the return status and the return code ot the child process that ended in the location to which stat_loc points.

If the child process ended normally, with a call to the Windows DosExit function, the lowest-order byte of stat_loc is 0, and the next higher-order byte contains the lowest-order byte of the argument passed to DosExit by the child process. The value of this byte depends on how the child process caused the system to call DosExit.

If the child process called exit, _exit, or return from main, the byte contains the lowest-order byte of the argument the child process passed to exit, _exit, or return. The value of the byte is undefined if the child process caused a DosExit call simply by reaching the end of main.

If the child process ended abnormally, the lowest-order byte of stat_loc contains the return status code from the Windows DosWaitChild function, and the next higher-order byte is 0.

Note: In earlier releases of the C/C++ run-time library, wait began with an underscore (_wait). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, IBM C and C++ Compilers will map _wait to wait for you.

Return Value
If wait returns after a normal end of a child process, it returns the process identifier of the child process to the parent process. A return value of -1 indicates an error, and errno is set to one of the following values:

Value | Meaning
ECHILD | There were no child processes or they all ended before the call to wait. This value indicates that no child processes exist for the particular process.
EINTR | A child process ended unexpectedly.

Example
This example creates a new process called CHILD.EXE, specifying P_NOWAIT when the child process is called. The parent process calls wait and waits for the child process to stop running. The parent process then displays the return information of the child process in hexadecimal.

    #include <stdio.h>
    #include <process.h>

    int stat_child;

    int main(void)
    {
       int pid;

       _spawnl(P_NOWAIT, "child2.exe", "child2.exe", NULL);
       if (-1 == (pid = wait(&stat_child)))
          perror("error in _spawnl");    /* display error status message */
       else
          printf("child process %d just ran.\n", pid);

       printf("return information was 0x%X\n", stat_child);
       return 0;

       /*******************************************************************
          If the source for child2.exe is:

          #include <stdio.h>
          int main(void)
          {
              puts("child2.exe is an executable file");
              return 0;
          }

          Then the output should be similar to:

          child2.exe is an executable file
          child process 2423 just ran.
          return information was 0x0
       *******************************************************************/
    }

_cwait -- Wait for Child Process
execl - _execvpe -- Load and Run Child Process
exit -- End Program
_exit -- End Process
_spawnl - _spawnvpe -- Start and Run Child Processes
<process.h>