Syntax
#include <process.h> int wait (int *stat_loc);Description
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 OS/2 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 OS/2 DosWaitChild function, and the next higher-order byte is 0. See the Control Program Guide and Reference for details about DosWaitChild return status codes.
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: compact break=fit.
Value
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 ****************************************************************************/ }Related Information