Do programs started with Process.Start(exepath);
terminate when the parent process ends? I'm getting some strange behavior with it and believe that could be the issue.

- 15,217
- 20
- 82
- 139
2 Answers
On Windows child processes normally live on their own and once started they do not depend on their parent process. You are looking for job objects. With jobs you can control an entire process tree lifetime, all child processes can be deterministically terminated if the parent ends (by having the parent own the job, strictly speaking all child processes terminate if the job is killed). There is no managed .Net API for it, but p-Invoke works fine.
So if you experience unexpected "strange behavior" make sure your process is not launched in the context of a job, causing your child processes to also be part of the job. Process Explorer can show job properties of a process.

- 288,378
- 40
- 442
- 569
-
Thanks for the detailed response, but I think you're reading too far into my question. I just wanted to know if the process would die or not - as the problem I was seeing was that the child process would end once the parent ended. It turned out the problem was entirely different – Christian Stewart Mar 11 '14 at 22:13
-
@ChristianStewart do you remember what your problem was? I'm seeing similar behavior but it's also weird - if the processes are in my dev folder, it works fine. In an application that's packaged into an MSI and installed, killing the parent kills the child. Any chance that's what you dealt with? – Dave Jul 26 '17 at 19:43
-
@Dave unfortunately I don't, I don't really use C# anymore :) Good luck! – Christian Stewart Jul 26 '17 at 22:50
The short answer to your question is No, they don't. You will have to kill them explicitly.If you want to kill the process that you have started then you can use the handle returned by process.start. Something like this
Process p = Process.Start("someprocess");
if (p != null)
p.Kill();

- 31,833
- 6
- 56
- 65