2 |
|
|
3 |
#include <windows.h> |
#include <windows.h> |
4 |
|
|
5 |
|
// background process bookkeeping |
6 |
|
HANDLE plist[MAXIMUM_WAIT_OBJECTS-1]; |
7 |
|
int plist_count = 0; |
8 |
|
|
9 |
BOOL os_start_process(char * filename, BOOL background) { |
BOOL os_start_process(char * filename, BOOL background) { |
10 |
|
|
11 |
STARTUPINFO si; |
STARTUPINFO si; |
36 |
|
|
37 |
// 1. background mode |
// 1. background mode |
38 |
if (background) { |
if (background) { |
39 |
// TODO: background process bookkeeping |
// background process bookkeeping |
40 |
|
plist[plist_count] = pi.hProcess; |
41 |
|
plist_count++; |
42 |
|
|
43 |
// 2. normal (blocking) mode |
// 2. normal (blocking) mode |
44 |
} else { |
} else { |
45 |
long status; |
long status; |
46 |
status = WaitForSingleObject(pi.hProcess, INFINITE); |
status = WaitForSingleObject(pi.hProcess, INFINITE); |
47 |
|
|
48 |
// close process and thread handles. |
// close process handle |
49 |
CloseHandle(pi.hProcess); |
CloseHandle(pi.hProcess); |
|
CloseHandle(pi.hThread); |
|
50 |
|
|
51 |
// check for and handle errors |
// check for and handle errors |
52 |
if (status == WAIT_FAILED) { |
if (status == WAIT_FAILED) { |
58 |
return TRUE; |
return TRUE; |
59 |
|
|
60 |
} |
} |
61 |
|
|
62 |
|
BOOL os_wait_for_processes() { |
63 |
|
|
64 |
|
long status; |
65 |
|
int i; |
66 |
|
HANDLE hProcess; |
67 |
|
|
68 |
|
if (plist_count == 0) |
69 |
|
return TRUE; |
70 |
|
|
71 |
|
status = WaitForMultipleObjects(plist_count, plist, TRUE, INFINITE); |
72 |
|
|
73 |
|
// close process handles |
74 |
|
for (i = 0; i < plist_count; i++) { |
75 |
|
hProcess = plist[i]; |
76 |
|
CloseHandle(hProcess); |
77 |
|
} |
78 |
|
|
79 |
|
// reset process counter |
80 |
|
plist_count = 0; |
81 |
|
|
82 |
|
// check for and handle errors |
83 |
|
if (status == WAIT_FAILED) { |
84 |
|
check_alert_error("WaitForMultipleObjects"); |
85 |
|
return FALSE; |
86 |
|
} |
87 |
|
|
88 |
|
return TRUE; |
89 |
|
} |