I was wondering if I have a program that creates another process, do开发者_StackOverflowes that created process run inside the creator? If so, does it always have to (is there a way to attach it to another process)?
The reason that I ask is actually because I'm trying to determine whether to make a particular thread, a background thread. Here is the scenario:
A process A is launching a program B that makes calls to wcf services. However, I'm spawning a thread from program B to make the actual service calls. If I set the thread to a background thread and process A crashes or terminates, will the thread terminate? If so, how can I decouple the thread from the process?
A process does not run within another process in windows (threads run within processes).
In your scenario, once program B terminates, the thread should also terminate.
What happens on process A will not affect the thread at all.
Windows Processes are independent of each other. Parent and child process lifetimes are not explicitly coupled at all.
A thread is owned for its lifetime by the process that created it, and terminates when (if not before) the creating process exits.
If a process wishes to control another process's lifetime, it needs to have a HANDLE
to the controlled process. This can be gotten either by being the creator of the controlled process (here, the handle is returned from the creation call), or (given correct permissions) via OpenProcess. In .Net, this is done using Get*
methods on Process class.
精彩评论