| 2 |
|
|
| 3 |
#include <windows.h> |
#include <windows.h> |
| 4 |
|
|
|
#define MAX_PROCESSES 64 |
|
|
|
|
| 5 |
// background process bookkeeping |
// background process bookkeeping |
| 6 |
HANDLE plist[MAX_PROCESSES]; |
HANDLE plist[MAXIMUM_WAIT_OBJECTS-1]; |
| 7 |
int plist_max = 0; |
int plist_count = 0; |
| 8 |
|
|
| 9 |
BOOL os_start_process(char * filename, BOOL background) { |
BOOL os_start_process(char * filename, BOOL background) { |
| 10 |
|
|
| 36 |
|
|
| 37 |
// 1. background mode |
// 1. background mode |
| 38 |
if (background) { |
if (background) { |
| 39 |
// TODO: background process bookkeeping |
// background process bookkeeping |
| 40 |
plist[plist_max] = pi.hProcess; |
plist[plist_count] = pi.hProcess; |
| 41 |
plist_max++; |
plist_count++; |
| 42 |
|
|
| 43 |
// 2. normal (blocking) mode |
// 2. normal (blocking) mode |
| 44 |
} else { |
} else { |
| 65 |
int i; |
int i; |
| 66 |
HANDLE hProcess; |
HANDLE hProcess; |
| 67 |
|
|
| 68 |
status = WaitForMultipleObjects(plist_max, plist, TRUE, INFINITE); |
if (plist_count == 0) |
| 69 |
|
return TRUE; |
| 70 |
|
|
| 71 |
|
status = WaitForMultipleObjects(plist_count, plist, TRUE, INFINITE); |
| 72 |
|
|
| 73 |
// close process handles |
// close process handles |
| 74 |
for (i = 0; i < plist_max; i++) { |
for (i = 0; i < plist_count; i++) { |
| 75 |
hProcess = plist[i]; |
hProcess = plist[i]; |
| 76 |
CloseHandle(hProcess); |
CloseHandle(hProcess); |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
// reset process counter |
// reset process counter |
| 80 |
plist_max = 0; |
plist_count = 0; |
| 81 |
|
|
| 82 |
// check for and handle errors |
// check for and handle errors |
| 83 |
if (status == WAIT_FAILED) { |
if (status == WAIT_FAILED) { |