spawnProcess: Exit parent process without terminating child process

FreeSlave via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 26 01:16:47 PDT 2017


On Friday, 25 August 2017 at 19:55:09 UTC, timvol wrote:
> Hi guys,
>
> I want execute a process. I know, I can execute a process using 
> "spawnProcess" or "executeShell". But I want exit the parent.
>
> My code for testing purposes is the following:
>
> int main(string[] asArgs_p)
> {
>     if ( (asArgs_p.length >= 2) && asArgs_p[1].isDir() )
>     {
>         while(1) {}
>     }
>     else
>     {
>         import std.process;
>         spawnProcess([asArgs_p[0], "test"]);
>     }
>     return 0;
> }
>
> So, starting the application without any parameter, it calls 
> "spawnProcess" with an parameter. Now, I want that the parent 
> process (the process started without parameter) terminates, 
> while the created process remains running.
>
> At the moment, the parent process creates the child and remains 
> open (because of the while(1)-loop).
>
> Any ideas how I can exit the parent and keep the child process 
> running?

Running process in detached state will be available in the future 
versions of Phobos. This functionality has been already merged in 
master https://github.com/dlang/phobos/pull/5483

Until then you may consider to use a third-party library 
https://github.com/FreeSlave/detached


More information about the Digitalmars-d-learn mailing list