Killing a dependant process

  • Thread starter Thread starter Sraj
  • Start date Start date
S

Sraj

There is a process A that launches process B as a COM object.
If the User tries to end process A, process B should also end. But vice
versa is not true. Process A can run independant of process. It is not
possible for a user to know process B is launched by process A.
In the destructor of Process A, there is a code to close process B. During
normal closing of process A, process B also gets closed. In certain
situations this is not happening-

1. When I clsoe process A from task manager, process B is still running. How
to close process B in this situation from code?
2. If process A has launched Process B, and process A has crashed, it still
leaves process B running.

This is a situation I would like to avoid. How is it possible to handle
these scenarios?
 
It's possible to kill a process in such a way
that it's "desctructor" code won't be executed.
When a process crashes, it's "desctructor code" often is not run as well.
Think of another solution, not depending on "desctructor" code in process A.

Regards,
--PA
 
Thanks Pavel for your suggestion. The whole idea of my question is - where
else should I write the code? Any idea what happens internally during crash?
Which part of the code is being called to shut down process A? If that
information is known then code can e written accordingly.
 
Sraj said:
Thanks Pavel for your suggestion. The whole idea of my question is - where
else should I write the code? Any idea what happens internally during crash?
Which part of the code is being called to shut down process A? If that
information is known then code can e written accordingly.

The code that shuts down a crashed or killed process
is the OS... Would you hack the kernel to accomplish your goal?
Maybe, instead, make the process B cooperate ?

--PA
 
Sraj said:
There is a process A that launches process B as a COM object.
If the User tries to end process A, process B should also end. But vice
versa is not true. Process A can run independant of process. It is not
possible for a user to know process B is launched by process A.
In the destructor of Process A, there is a code to close process B. During
normal closing of process A, process B also gets closed. In certain
situations this is not happening-

1. When I clsoe process A from task manager, process B is still running.
How
to close process B in this situation from code?
2. If process A has launched Process B, and process A has crashed, it
still
leaves process B running.

This is a situation I would like to avoid. How is it possible to handle
these scenarios?

Is the code for both process A and process B under your control?

If yes, then set an environment variable when starting process B. Process B
will look for that and then watch (using WaitForSingleObject or one of its
kin) for process A to quit and then end itself.
 
Back
Top