|
|
1.1 ! root 1: /* ! 2: * Example of DOSCWAIT usage. ! 3: * ! 4: * Although a process can only call DOSCWAIT on its own child processes, ! 5: * it is possible to wait indirectly on subsequent generations of ! 6: * processes by use of the ProcessAndDescendents flag. To wait for a ! 7: * collection of subprocesses to end, a process must call DOSCWAIT ! 8: * repeatedly, once for each of the subprocesses. The result codes ! 9: * field is only valid for the one call first call against the child. ! 10: * Subsequent calls indicate that another descendent process has ended, ! 11: * but do not return exit or termination codes. ! 12: * ! 13: * To wait for any child, rather that a specific one, the process ! 14: * should pass in a process id of 0. The pid of the process that ended ! 15: * will be placed in the ProcessIdWord field. ! 16: * ! 17: * Compile as: cl -AL -G2 -Lp cwait.c ! 18: * ! 19: * Copyright (C) Microsoft Corp. 1986 ! 20: */ ! 21: ! 22: #include <doscalls.h> ! 23: #include <stdio.h> ! 24: ! 25: #define ERRBUF_LEN 64 ! 26: #define ARG_LEN 128 ! 27: ! 28: main() ! 29: { ! 30: struct ResultCodes child_status, child_pid; ! 31: unsigned ending_pid, res; ! 32: char errbuf[ERRBUF_LEN]; ! 33: char child_arg[ARG_LEN]; ! 34: char *child_env; ! 35: ! 36: /* ! 37: * Execute a program and wait for it to finish. ! 38: */ ! 39: DOSEXECPGM((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, ! 40: "child.exe"); ! 41: printf("exec'd child, pid = %u\n", child_pid); ! 42: DOSCWAIT(0,0, &child_status, &ending_pid, child_pid.TermCode_PID); ! 43: if (child_status.TermCode_PID != 0) ! 44: printf("error: child's termination code was %u\n", ! 45: child_status.TermCode_PID); ! 46: else ! 47: printf("child process returned %u\n", child_status.ExitCode); ! 48: ! 49: /* ! 50: * Execute a program and wait for it and all of its descendents ! 51: * to finish. In this case we specify the top pid to wait for. ! 52: */ ! 53: DOSEXECPGM((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, ! 54: "child.exe"); ! 55: printf("exec'd child, pid = %u\n", child_pid); ! 56: do { ! 57: res = DOSCWAIT(1,0, &child_status, &ending_pid, ! 58: child_pid.TermCode_PID); ! 59: if(res == 0) ! 60: printf("cwait found pid = %u\n", ending_pid); ! 61: else ! 62: printf("cwait found no more process\n"); ! 63: } while (res == 0); ! 64: ! 65: /* ! 66: * Wait for any child to terminate. In this case we specify ! 67: * the pid as zero, which means wait for any child to finish. ! 68: */ ! 69: DOSEXECPGM((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, ! 70: "child.exe"); ! 71: printf("exec'd child, pid = %u\n", child_pid); ! 72: do { ! 73: res = DOSCWAIT(1,0, &child_status, &ending_pid, 0); ! 74: if (res == 0) ! 75: printf("child %u ended\n", ending_pid); ! 76: } while (res == 0); ! 77: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.