/[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.5 - (show annotations)
Fri Jun 16 20:32:37 2006 UTC (18 years, 3 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +2 -3 lines
File MIME type: text/plain
minor fixes and cleanup

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

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