Click to See Complete Forum and Search --> : How to kill child processes when the parent terminates


chafey
May 6th, 1999, 12:47 PM
Hi
Is there anyway to have NT automatically terminate all child processes created by a process when that process is terminated itself? I have a process monitor program which launches several processes, but the child processes are not being cleaned up if I terminate the parent monitor process from task manager or by stopping the debug session from within Developer Studio. Although I don't plan on having users stop the process monitor by killing it, I would like to handle this situation properly. I would also like this cleanup to occur when I am debugging the parent process(killing the spawned children from task manager is time consuming). I have this kind of working by adding the DEBUG_ONLY_THIS_PROCESS flag to the creation flags when creating the process. Unfortunately the child processes don't use the parent process's console window with this flag. The process monitor is a console application and all spawned children are console applications. The process monitor itself will eventually be a NT Service. Any ideas?

Chris Hafey
PS - Does anyone know the header file that declares IsDebuggerPresent()? The doc's don't specify one and I couldn't find it in the VC header files when I did a search! I ended up declaring it myself.

Ashley Antony
May 7th, 1999, 01:57 AM
In Win32 world, as far as my knowledge, there is no child-process relationship like in other OS like VMS, etc. Its operating in a separate address and is in a diff world. Once you spawn a process from yours you need that process's id to do something with that. You can also spawn a process in the debug mode, but if debugee or debugger crashes result will be the termination of both the applications. Thats how your parent process is getting killed while you terminate the debugger of it. While you kill a process from TaskManager it calls TerminateProcess with that process's id. It doesn't do any clean up, thats why MS says it should be the last resort to terminate an application. So I don't think what you are trying to do will be possible. If you could please let me know, I'm interested in it.
There id no .h file defined for IsDebuggerPresent(). You can find an excel sheet called Win32api.csv in the lib directory of VC++ installation. It tells about lot of API's and its header files, ...... There is no entry in the .h column for IsDebuggerPresent().

Ashley.Antony@in.bosch.com
Bangalore
India.