|
|
1.1 root 1: /* 1.1.1.2 ! root 2: * Example of DosCWait usage. 1.1 root 3: * 1.1.1.2 ! root 4: * Although a process can only call DosCWait on its own child processes, 1.1 root 5: * it is possible to wait indirectly on subsequent generations of 6: * processes by use of the ProcessAndDescendents flag. To wait for a 1.1.1.2 ! root 7: * collection of subprocesses to end, a process must call DosCWait 1.1 root 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: * 1.1.1.2 ! root 19: * Created by Microsoft Corp. 1986 1.1 root 20: */ 21: 1.1.1.2 ! root 22: #define INCL_DOSPROCESS ! 23: ! 24: #include <os2def.h> ! 25: #include <bsedos.h> 1.1 root 26: #include <stdio.h> 27: 28: #define ERRBUF_LEN 64 29: #define ARG_LEN 128 30: 31: main() 32: { 1.1.1.2 ! root 33: RESULTCODES child_status, child_pid; ! 34: PID ending_pid; ! 35: unsigned res; 1.1 root 36: char errbuf[ERRBUF_LEN]; 37: char child_arg[ARG_LEN]; 38: char *child_env; 39: 40: /* 41: * Execute a program and wait for it to finish. 42: */ 1.1.1.2 ! root 43: DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, 1.1 root 44: "child.exe"); 45: printf("exec'd child, pid = %u\n", child_pid); 1.1.1.2 ! root 46: DosCWait(0,0, &child_status, &ending_pid, child_pid.codeTerminate); ! 47: if (child_status.codeTerminate != 0) 1.1 root 48: printf("error: child's termination code was %u\n", 1.1.1.2 ! root 49: child_status.codeTerminate); 1.1 root 50: else 1.1.1.2 ! root 51: printf("child process returned %u\n", child_status.codeResult); 1.1 root 52: 53: /* 54: * Execute a program and wait for it and all of its descendents 55: * to finish. In this case we specify the top pid to wait for. 56: */ 1.1.1.2 ! root 57: DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, 1.1 root 58: "child.exe"); 59: printf("exec'd child, pid = %u\n", child_pid); 60: do { 1.1.1.2 ! root 61: res = DosCWait(1,0, &child_status, &ending_pid, ! 62: child_pid.codeTerminate); 1.1 root 63: if(res == 0) 64: printf("cwait found pid = %u\n", ending_pid); 65: else 66: printf("cwait found no more process\n"); 67: } while (res == 0); 68: 69: /* 70: * Wait for any child to terminate. In this case we specify 71: * the pid as zero, which means wait for any child to finish. 72: */ 1.1.1.2 ! root 73: DosExecPgm((char *)0, 0, 2, (char *)0, (char *)0, &child_pid, 1.1 root 74: "child.exe"); 75: printf("exec'd child, pid = %u\n", child_pid); 76: do { 1.1.1.2 ! root 77: res = DosCWait(1,0, &child_status, &ending_pid, 0); 1.1 root 78: if (res == 0) 79: printf("child %u ended\n", ending_pid); 80: } while (res == 0); 81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.