title: Restarting a process from another process
body: <p>I have two processes: ProcessA and ProcessB.</p>
  
  <p>When i launch my application, i call ProcessA which uses <code>CreateProcess()</code> to launch ProcessB. ProcessA is killed by ProcessB when my application receives command A. Likewise, ProcessB <strong>should relaunch ProcessA</strong> when it receives command B.</p>
  
  <p>Where i am stuck on is on the process of relaunching ProcessA. Since ProcessA has the code to relaunch ProcessB, i cannot stop it from relaunching another instance of ProcessB. Ideally, i want to have only 1 instance of ProcessB.</p>
  
  <p>For creating ProcessB from ProcessA, i have the following code:</p>
  
  <pre><code>for(int i32Index = 0; i32Index &lt; NUM_PROCESS; i32Index++)
          {
              wcscpy(wcPath,Directorypath.c_str());
              wcscat(wcPath,wcProcess[i32Index]);
              RETAILMSG(1,(_T("Path:%s\r\n"),wcPath));
              bCreateProcessSuccess = CreateProcess(wcPath,   // No module name (use command line)
                                      NULL,                   // Command line
                                      NULL,                   // Process handle not inheritable
                                      NULL,                   // Thread handle not inheritable
                                      FALSE,                  // Set handle inheritance to FALSE
                                      0,                      // No creation flags
                                      NULL,                   // Use parent's environment block
                                      NULL,                   // Use parent's starting directory 
                                      &amp;si,                    // Pointer to STARTUPINFO structure
                                      &amp;pi ) ;                 // Pointer to PROCESS_INFORMATION structure
               if(bCreateProcessSuccess == FALSE)
               {
                   RETAILMSG(1,(_T("Create process failed:%d\r\n"),GetLastError()));
               }
               else
               {
                  RETAILMSG(1,(_T("Loading Exes\r\n")));
               }
  </code></pre>
  
  <p>Pretty straightforward, basic code. I basically repeat this in ProcessB, but so that it creates ProcessA. </p>
  
  <p>Now, im stuck on how i would be able to implement the condition to launch ProcessA without it launching ProcessB again. I initially thought of using a flag, but that flag would be reset since launching ProcessA would reset the flag as it is local to the function.</p>
  
  <p>Also, to clarify: this is in windows embedded compact environment so both processes exist as different subprojects so to access ProcessA from ProcessB would require IPC. </p>
  
  <p>My next idea was to use <code>CreateEvent()</code> with <code>WaitForSingleObject()</code> to check if the event is signaled, but i realized that the wait duration would have to be infinite, which would cause an issue the first time i launch my application.</p>
  
  <p>So, is there any type of windows(wince) api that would solve this? (Or some kind of fancy coding i cannot think of?)</p>