spawnProcess: Exit parent process without terminating child process
FreeSlave via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Aug 26 01:22:40 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?
Note that in your particular case the spawnProcess as used now
should work too. It should run in parallel with its parent.
Parent will exit and child process will remain. I'm not sure why
the parent does not exit in your case. When starting this program
without parameters it will not run into while(1) branch at all.
More information about the Digitalmars-d-learn
mailing list