Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start new process, without being a child of the spawning process

How would I go about starting a new process without it being the child of the calling process.

Example:

Main Program (Caller.exe)

process.start("file.exe") 

Image:

enter image description here

like image 931
Andrew Paglusch Avatar asked Dec 08 '11 16:12

Andrew Paglusch


People also ask

Can a child process create another child process?

Yes. The process creates a child, which then creates another child, becoming it's parent. You can differentiate child and parent by using fork return number.

What happens to child process when parent is killed Windows?

In chrome on Windows, the child processes are in a job object and so the OS takes care of killing them when the parent process dies.


2 Answers

If the spawning process (parent) ends before the spawned process (child) does, then the parent-child chain is broken. To make use of this, you'd have to use an intermediate stub-process like so:

Caller.exe → Stub.exe → File.exe.

Here Stub.exe is simple launcher program that ends just after starting File.exe.

like image 90
Josh Avatar answered Oct 14 '22 09:10

Josh


If you start a process, then you'll be its parent.

Maybe you could try to start your process from cmd.exe instead, so cmd.exe will be the parent.

Process proc = Process.Start(new ProcessStartInfo { Arguments = "/C explorer", FileName = "cmd", WindowStyle = ProcessWindowStyle.Hidden }); 
like image 40
ken2k Avatar answered Oct 14 '22 07:10

ken2k