Killing a debugged process RRS feed

  • Question

  • Hi,

    I've been working on a "crash monitoring" application (WM 6.0) which works something like this:

    1. Main application thread launches Thread B, and waits for an event object (to be signalled from Thread B upon completion of task)
    2. Thread B creates a new process (the monitored app), with parameters DEBUG_ONLY_THIS_PROCESS
    3. Thread B launches Thread C, which sends some input parameters to the monitored app
    4. Thread B calls WaitForDebugEvent
    5. If an EXCEPTION_DEBUG_EVENT is caught, Thread B should terminate the monitored app and go back to step 2 (until we have exhausted all of the input parameters to be tested)

    Is there a good way to ensure that the monitored app is killed, regardless of the circumstances? TerminateProcess always seems to fail if the monitored app hangs as a result of the exception.

    Thanks in advance
    Tuesday, June 16, 2009 10:15 AM

All replies

  • You can communicate with the other process by creating a "Named Event" for example to signal the process to exit. 
    In thread B do a: CreateEvent(.., .., .., L"MyEvent");

    This will return a newly created handle which you can use to signal the event with SetEvent() or PulseEvent(). 
    If you do the exactly same in the other processes created by thread B (thus CreateEvent(.., .., .., L"MyEvent");), then it will open and return the existing one. 

    Then you can wait for to be signalled (WaitForSingleObject), and if so exit the app. 

    Good luck,

    Erwin Zwart, 
    Check out my blog: http://GuruCE.com/blog

     Microsoft Embedded Partner
     Consultancy, training and development services.
    • Proposed as answer by Erwin Zwart Monday, June 22, 2009 7:45 PM
    Monday, June 22, 2009 10:07 AM