|
|
Microsoft OS/2 SDK 03-01-1988
/*
* Example of DosCWait usage.
*
* Although a process can only call DosCWait on its own child processes,
* it is possible to wait indirectly on subsequent generations of
* processes by use of the ProcessAndDescendents flag. To wait for a
* collection of subprocesses to end, a process must call DosCWait
* repeatedly, once for each of the subprocesses. The result codes
* field is only valid for the one call first call against the child.
* Subsequent calls indicate that another descendent process has ended,
* but do not return exit or termination codes.
*
* To wait for any child, rather that a specific one, the process
* should pass in a process id of 0. The pid of the process that ended
* will be placed in the ProcessIdWord field.
*
* Compile as: cl -AL -G2 -Lp cwait.c
*
* Created by Microsoft Corp. 1986
*/
#define INCL_DOSPROCESS
#include <os2def.h>
#include <bsedos.h>
#include <stdio.h>
#define ERRBUF_LEN 64
#define ARG_LEN 128
main()
{
RESULTCODES child_status, child_pid;
PID ending_pid;
unsigned res;
char errbuf[ERRBUF_LEN];
char child_arg[ARG_LEN];
char *child_env;
/*
* Execute a program and wait for it to finish.
*/
DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid,
"child.exe");
printf("exec'd child, pid = %u\n", child_pid);
DosCWait(0,0, &child_status, &ending_pid, child_pid.codeTerminate);
if (child_status.codeTerminate != 0)
printf("error: child's termination code was %u\n",
child_status.codeTerminate);
else
printf("child process returned %u\n", child_status.codeResult);
/*
* Execute a program and wait for it and all of its descendents
* to finish. In this case we specify the top pid to wait for.
*/
DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid,
"child.exe");
printf("exec'd child, pid = %u\n", child_pid);
do {
res = DosCWait(1,0, &child_status, &ending_pid,
child_pid.codeTerminate);
if(res == 0)
printf("cwait found pid = %u\n", ending_pid);
else
printf("cwait found no more process\n");
} while (res == 0);
/*
* Wait for any child to terminate. In this case we specify
* the pid as zero, which means wait for any child to finish.
*/
DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid,
"child.exe");
printf("exec'd child, pid = %u\n", child_pid);
do {
res = DosCWait(1,0, &child_status, &ending_pid, 0);
if (res == 0)
printf("child %u ended\n", ending_pid);
} while (res == 0);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.