c++windowswaitforsingleobject

How to make process B running only while Process A is alive


I have a process A that starts another process B.
Currently process B waits for a signal(WaitForSingleObject) that is signaled by the process'A ' before exiting and once the signal is set the process B exits. However when Process A terminates or crashes unexpectedly I end up with process B still running. How can I make B wait for the signal indefinitely except when the Process A has crashed? In other words .. Process B should stay alive only till Process A is running. thanks


Solution

  • WaitForSingleObject on process A's process handle; it will signal when A dies.

    One other way of doing it is to attach B to A as a debugger. Then you will get an event when the process has exited, and can exit in perfect synchronization.