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