We have a C++ task that will fork a new process. That process in turn may have several child processes. If the task runs past an allotted time, we will want to kill that forked process.
However, we don't want to orphan the processes it has spawned. We want them all to die. I have used Process Explorer and it has a "Kill Process Tree" option, similar to Windows Task Manager's "End Process Tree", so I'm guessing/assuming there is a public API to do this. Has anyone done this, or know of a reference to a public API that does?
Best Answer
You might want to consider the "Jobs API".
CreateJobObject
and friends. You can enforce children processes to stay within the Job, by setting appropriate attribute. Then you can callTerminateJobObject
whenever you want.Clarification: this is NOT what Task Manager does.