Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <process.h>
    int wait( int *status );

Description:
    The wait function suspends the calling process until any of the caller's
    immediate child processes terminate.

    Under Windows NT, there is no parent-child relationship amongst
    processes so the wait function cannot and does not wait for child
    processes to terminate.  To wait for any process, you must specify its
    process id.  For this reason, the  cwait function should be used (one of
    its arguments is a process id).

    If status is not NULL, it points to a word that will be filled in with
    the termination status word and return code of the terminated child
    process.

    If the child process terminated normally, then the low order byte of the
    status word will be set to 0, and the high order byte will contain the
    low order byte of the return code that the child process passed to the
     DOSEXIT function.  The  DOSEXIT function is called whenever  main
    returns, or  exit or  _exit are explicity called.

    If the child process did not terminate normally, then the high order
    byte of the status word will be set to 0, and the low order byte will
    contain one of the following values:

    Value     Meaning

1
    Hard-error abort

2
    Trap operation

3
    SIGTERM signal not intercepted

    Note:
        This implementation of the status value follows the OS/2 model and
        differs from the Microsoft implementation.  Under Microsoft, the
        return code is returned in the low order byte and it is not possible
        to determine whether a return code of 1, 2, or 3 imply that the
        process terminated normally.  For portability to Microsoft
        compilers, you should ensure that the application that is waited on
        does not return one of these values.  The following shows how to
        handle the status value in a portable manner.


             cwait( &status, process_id, WAIT_CHILD );

             #if defined(__WATCOMC__)
             switch( status & 0xff ) {
             case 0:
                 printf( "Normal termination exit code = %d\n", status >> 8
        );
                 break;
             case 1:
                 printf( "Hard-error abort\n" );
                 break;
             case 2:
                 printf( "Trap operation\n" );
                 break;
             case 3:
                 printf( "SIGTERM signal not intercepted\n" );
                 break;
             default:
                 printf( "Bogus return status\n" );
             }

             #else if defined(_MSC_VER)
             switch( status & 0xff ) {
             case 1:
                 printf( "Possible Hard-error abort\n" );
                 break;
             case 2:
                 printf( "Possible Trap operation\n" );
                 break;
             case 3:
                 printf( "Possible SIGTERM signal not intercepted\n" );
                 break;
             default:
                 printf( "Normal termination exit code = %d\n", status );
             }

             #endif



Returns:
    The wait function returns the child's process id if the child process
    terminated normally.  Otherwise, wait returns -1 and sets  errno to one
    of the following values:

    Constant     Meaning

ECHILD
    No child processes exist for the calling process.

EINTR
    The child process terminated abnormally.


Example:
    #include <stdlib.h>
    #include <process.h>

    void main()
      {
         int   process_id, status;

         process_id = spawnl( P_NOWAIT, "child.exe",
                    "child", "parm", NULL );
         wait( &status );
      }

Classification:
    WATCOM

Systems:
    Win32, QNX, OS/2 1.x(all), OS/2-32

See Also:
    cwait, exit, _exit, spawn Functions

See Also: cwait exit

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson