问题
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.
回答1:
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();
回答2:
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.
来源:https://stackoverflow.com/questions/22318493/does-process-start-terminate-the-child-program-when-the-parent-terminates