You can synchronize the execution of a process with the execution of one of its child processes by calling DosWaitChild. DosWaitChild does not return until the specified child process ends. This can be useful, for example, if the parent process needs to ensure that the child process has completed its task before the parent process continues with its own task.
In the following code fragment, the parent process starts a child process and then waits for the child process to finish:
#define INCL_DOSPROCESS /* Process and thread values */ #include <os2.h> RESULTCODES resc; PID pidEnded; CHAR szFailName[CCHMAXPATH]; CHAR szCommandLine[] = "APP\0test\0"; DosExecPgm(szFailName, /* Failed-name buffer */ sizeof(szFailName), /* Length of buffer */ EXEC_ASYNC, /* Sync flag */ szCommandLine, /* Argument string */ (PSZ) NULL, /* Environment string */ &resc, /* Address of result */ "APP.EXE"); /* Name of application */ DosWaitChild(DCWA_PROCESS, /* Only the process */ DCWW_WAIT, /* Waits until it is done */ &resc, /* Puts the result here */ &pidEnded, /* PID of ended process */ resc.codeTerminate); /* Child to wait for */
You can cause a process to wait for all its child processes to end by using the DCWA_PROCESSTREE constant in the call to DosWaitChild.