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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Thu Jun 15 22:58:58 2006 UTC revision 1.3 by joko, Fri Jun 16 00:31:50 2006 UTC
# Line 2  Line 2 
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;
14    PROCESS_INFORMATION pi;    PROCESS_INFORMATION pi;
15      BOOL proc_ok;
16    
17    //printf("start_process: '%s'\n", filename);    //printf("start_process: '%s'\n", filename);
18        
# Line 15  BOOL os_start_process(char * filename, B Line 22  BOOL os_start_process(char * filename, B
22    ZeroMemory(&pi,sizeof(pi));    ZeroMemory(&pi,sizeof(pi));
23        
24    // actually do something now...    // actually do something now...
25    CreateProcess(    proc_ok = CreateProcess(
26      NULL, filename,      NULL, filename,
27      NULL, NULL, FALSE, 0,      NULL, NULL, FALSE, 0,
28      NULL, NULL,      NULL, NULL,
29      &si,      &si,
30      &pi      &pi
31    );    );
32    check_alert_error("CreateProcess");  
33      // did something fail?
34      if (!proc_ok) {
35        check_alert_error("CreateProcess");
36        return FALSE;
37      }
38        
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) {
# Line 47  BOOL os_start_process(char * filename, B Line 60  BOOL os_start_process(char * filename, B
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    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.3

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