I was wondering if I have a program that creates another process, does 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?
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
HANDLEto 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 usingGet*methods on Process class.