Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Terminate a child process when parent process is killed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
barbutz - 09 Jul 2007 16:46 GMT
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
Sheng Jiang[MVP] - 09 Jul 2007 18:17 GMT
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.
Signature

Sheng Jiang
Microsoft MVP in VC++

> Hello,
>
[quoted text clipped - 10 lines]
>
> Thanks in advance
barbutz - 09 Jul 2007 21:50 GMT
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!

> 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
[quoted text clipped - 16 lines]
> >
> > Thanks in advance
Sheng Jiang[MVP] - 09 Jul 2007 22:29 GMT
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

Signature

Sheng Jiang
Microsoft MVP in VC++

> Hi Sheng,
> Thanks for the response.
[quoted text clipped - 26 lines]
> > >
> > > Thanks in advance

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.