سؤال

I'm working with CreateProcess to run a process/application of mine. The purpose is to run it, do something, wait for some indication, and close it (Using TerminateProcess).

What I noticed is that this application/process creates sub-processes. Additionally, when terminating the created process, the sub-processes do not terminate, and still remain for a period of time.

I wanted to ask if there's an option to somehow kill all the sub-processes with the main process. It causes issues, since when I do CreateProcess again, there are leftovers from previous processes, and I think they're causing some issues.

I really appreciate your help!

هل كانت مفيدة؟

المحلول

Use Windows Job Objects. Jobs are like process groups; the operating system will take care of terminating all processes in the job once the job leader (your initial process) is terminated. This even works if the proess leader crashes.

نصائح أخرى

When you create a process using CreateProcess you'll get a LPPROCESS_INFORMATION-pointer. It contains the process handle. You'll need to close the processes manually, as there is no such thing as a process hierarchy as in Linux/Unix.

See here for CreateProcess and here for the PROCESS_INFORMATION-structure.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top