/[cvs]/joko/Uni/BSArch/03/win32/utils_proc.c
ViewVC logotype

Contents of /joko/Uni/BSArch/03/win32/utils_proc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Jun 16 00:31:50 2006 UTC (18 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.2: +36 -3 lines
File MIME type: text/plain
+ WaitForMultipleObjects

1 /* $Id: utils_proc.c,v 1.2 2006/06/15 23:09:44 joko Exp $ */
2
3 #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) {
12
13 STARTUPINFO si;
14 PROCESS_INFORMATION pi;
15 BOOL proc_ok;
16
17 //printf("start_process: '%s'\n", filename);
18
19 // initialize structures
20 ZeroMemory(&si,sizeof(si));
21 si.cb = sizeof(STARTUPINFO);
22 ZeroMemory(&pi,sizeof(pi));
23
24 // actually do something now...
25 proc_ok = CreateProcess(
26 NULL, filename,
27 NULL, NULL, FALSE, 0,
28 NULL, NULL,
29 &si,
30 &pi
31 );
32
33 // did something fail?
34 if (!proc_ok) {
35 check_alert_error("CreateProcess");
36 return FALSE;
37 }
38
39 // 1. background mode
40 if (background) {
41 // TODO: background process bookkeeping
42 plist[plist_max] = pi.hProcess;
43 plist_max++;
44
45 // 2. normal (blocking) mode
46 } else {
47 long status;
48 status = WaitForSingleObject(pi.hProcess, INFINITE);
49
50 // close process handle
51 CloseHandle(pi.hProcess);
52
53 // check for and handle errors
54 if (status == WAIT_FAILED) {
55 check_alert_error("WaitForSingleObject");
56 return FALSE;
57 }
58 }
59
60 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 }

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed