Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Process.Start terminate the child program when the parent terminates?

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.

like image 734
Christian Stewart Avatar asked Mar 20 '23 07:03

Christian Stewart


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

like image 106
Remus Rusanu Avatar answered Apr 26 '23 02:04

Remus Rusanu