سؤال

I have a C#-Application, which starts some child-Processes and redirect their Standart-Input and Output.

If i close the application on the normal way all child processes will be destroyed, but if the application is killed by the Task Manager or another way i can't close the child-processes.

They exist and need much CPU-Power (Nearly 99%). I think they need so much Power because their "redirected" Standart-Output is not readed?

Is there a way to close the child-processes always? Or to decrease their CPU-Time after killing the parent-process?

thanks & best regards

Kevin Meier

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

المحلول

The short answer is No!

When user terminates your application process, It's just terminated. You can't do anything about it, unless you have the child processes source code and modify them to end after parent termination or use an individual observer process to terminate child processes of your application when it's terminated.

نصائح أخرى

Redirecting the streams shouldnt cause high cpu usage by it self, something else is probably happening.

If i had this problem, i would check running parent proccess sometimes in all child processes if parent process dont exist, child process would do exit.

If you want to guarantee that child processes end when the parent is terminated, you can use job objects. Unfortunately, there is no simple way to do this from managed code; it would require a lot of P/Invoke interop calls to Win32 APIs like CreateJobObject, AssignProcessToJobObject, etc. But in general it should be possible.

You can use named pipe etc to communicate between parent and child processes, keep checking if the parent is there or not.

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