Killing a dependant process

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?
 
P

Pavel A.

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
 
S

Sraj

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.
 
P

Pavel A.

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
 
B

Ben Voigt [C++ MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top