Hello,

I'm using a C# application to create a process "A" to execute an .exe file.
The problem is that when the application is killed (for example from task
manager) the child process keeps on running.
The question is how can i run the "A" process so that when my application is
killed or crashes the child process "A" will be terminated?
I'm using this code:

Process A = new Process();
A.StartInfo.FileName = some_exe_path;
A.Start();

Thanks in advance

Re: Terminate a child process when parent process is killed by Sheng

Sheng
Mon Jul 09 12:17:29 CDT 2007

If you have source code access to the exe file, check the parent process
periodically in the exe and exit if the parent process is killed. If you
don't, write a loader process to do the same. Again, this only works if you
loader is not crashed or killed.
--
Sheng Jiang
Microsoft MVP in VC++
"barbutz" <barbutz@discussions.microsoft.com> wrote in message
news:1802FB31-55F9-4F4B-996C-A7D545E880FC@microsoft.com...
> Hello,
>
> I'm using a C# application to create a process "A" to execute an .exe
file.
> The problem is that when the application is killed (for example from task
> manager) the child process keeps on running.
> The question is how can i run the "A" process so that when my application
is
> killed or crashes the child process "A" will be terminated?
> I'm using this code:
>
> Process A = new Process();
> A.StartInfo.FileName = some_exe_path;
> A.Start();
>
> Thanks in advance



Re: Terminate a child process when parent process is killed by barbutz

barbutz
Mon Jul 09 15:50:01 CDT 2007

Hi Sheng,
Thanks for the response.
Unfortunately i don't have an access to the exe source code. However i think
i'll implement a loader class as you suggested. Just one request please. Can
you please supply a code snippet that describes how to check the parent
process responsiveness? - do you refer to .net remoting or do you suggest
another way?

Thanks again!

"Sheng Jiang[MVP]" wrote:

> If you have source code access to the exe file, check the parent process
> periodically in the exe and exit if the parent process is killed. If you
> don't, write a loader process to do the same. Again, this only works if you
> loader is not crashed or killed.
> --
> Sheng Jiang
> Microsoft MVP in VC++
> "barbutz" <barbutz@discussions.microsoft.com> wrote in message
> news:1802FB31-55F9-4F4B-996C-A7D545E880FC@microsoft.com...
> > Hello,
> >
> > I'm using a C# application to create a process "A" to execute an .exe
> file.
> > The problem is that when the application is killed (for example from task
> > manager) the child process keeps on running.
> > The question is how can i run the "A" process so that when my application
> is
> > killed or crashes the child process "A" will be terminated?
> > I'm using this code:
> >
> > Process A = new Process();
> > A.StartInfo.FileName = some_exe_path;
> > A.Start();
> >
> > Thanks in advance
>
>
>

Re: Terminate a child process when parent process is killed by Sheng

Sheng
Mon Jul 09 16:29:54 CDT 2007

It is hard to define responsiveness for some applications. For example, you
can expect an IE window to stop responding for a while when a FTP address is
entered. Since there is no apparent main window for IE, the IE process can
be described as partially hang if another window is open and responding to
user input.

If your process has only one main window, use SendMessageTimeout to send a
WM_NULL message or check the Responding property of the Process object
returned by the Process.GetProcessById method.

You can pass your process id in the command line and parse the command line
in your loader process.

Reference

How to detect if an application has stopped responding by using Visual C#
http://support.microsoft.com/kb/304991


--
Sheng Jiang
Microsoft MVP in VC++
"barbutz" <barbutz@discussions.microsoft.com> wrote in message
news:59292F31-3E14-43DB-923B-5D41DF5E620D@microsoft.com...
> Hi Sheng,
> Thanks for the response.
> Unfortunately i don't have an access to the exe source code. However i
think
> i'll implement a loader class as you suggested. Just one request please.
Can
> you please supply a code snippet that describes how to check the parent
> process responsiveness? - do you refer to .net remoting or do you suggest
> another way?
>
> Thanks again!
>
> "Sheng Jiang[MVP]" wrote:
>
> > If you have source code access to the exe file, check the parent process
> > periodically in the exe and exit if the parent process is killed. If you
> > don't, write a loader process to do the same. Again, this only works if
you
> > loader is not crashed or killed.
> > --
> > Sheng Jiang
> > Microsoft MVP in VC++
> > "barbutz" <barbutz@discussions.microsoft.com> wrote in message
> > news:1802FB31-55F9-4F4B-996C-A7D545E880FC@microsoft.com...
> > > Hello,
> > >
> > > I'm using a C# application to create a process "A" to execute an .exe
> > file.
> > > The problem is that when the application is killed (for example from
task
> > > manager) the child process keeps on running.
> > > The question is how can i run the "A" process so that when my
application
> > is
> > > killed or crashes the child process "A" will be terminated?
> > > I'm using this code:
> > >
> > > Process A = new Process();
> > > A.StartInfo.FileName = some_exe_path;
> > > A.Start();
> > >
> > > Thanks in advance
> >
> >
> >