Take the 2-minute tour ×

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

share|improve this question
You should be able to kill them by using "End Process Tree" in the task manager –  BrokenGlass Sep 4 '11 at 20:49
can you post some portion of your code, maybe there is something you didn't handle it well. –  Jerry Liang Sep 5 '11 at 2:09
add comment

5 Answers

up vote 1 down vote accepted

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.

share|improve this answer
It is possible to do this if you use job objects (see my answer below). –  bobbymcr Sep 5 '11 at 2:34
Ok, thanks. So there's no "good" solution. –  Kevin Meier Sep 5 '11 at 21:16
add comment

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

share|improve this answer
The child-processes have 0% cpu-usage on the normal runtime. And if i kill the parent-process the usage increases fastly from one to the other second. But it can be of course another problem, don't know. –  Kevin Meier Sep 5 '11 at 21:11
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
The application should run on linux too, so this is no option. But thanks for this info. –  Kevin Meier Sep 5 '11 at 21:13
There is no "POSIX compliant" way that I know of. On Windows NT platforms, job objects would be the way to go. For Linux, you could do this: stackoverflow.com/questions/284325/… –  bobbymcr Sep 7 '11 at 0:27
add comment

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

share|improve this answer
add comment

Your Answer


