Killing child processes when debugging ends

2019-07-25 13:29发布

I have a C++ project in Visual Studio 2008 that, when executed, spawns another process (due to a GUI library that is being used). However when I exit the main process (either using Ctrl-C or by stopping the debugger), the spawned process (and hence the GUI) remains. This is a side-effect of the library being used, and the nature of the project - it is designed to be embedded, and hence never really "exit", but debugging and testing is Windows-based. The orphan process then stops me being able to run the software again, without first killing it.

Using Process Explorer I can see that the spawned process is a child of the process being debugged. I would like a way to, when I end debugging of a project, kill all child processes.

The Chromium project has a macro which will grab child processes in order to attach to them. This is designed to be associated with a button in the VS GUI, and seems to be chrome-specific (that is, you would need a different button for a different project/parent-process).

I have looked into using the DebuggerProcessEvents::OnProcessStateChanged macro, the idea being that when the debugger stops I could walk through the child processes using a similar idea to the Chromium macro and <evil voice>kill them</evil voice>... but this event never seems to be triggered.

Any thoughts? The project is Makefile-based, due to the code being generated outside of Visual Studio, so I will be limited in the options I can set project-wise.

0条回答
登录 后发表回答