std.process: spawnProcess

Basile B. b2.temp at gmx.com
Sat Sep 8 02:38:51 UTC 2018


On Friday, 7 September 2018 at 14:36:42 UTC, Russel Winder wrote:
> From what I can see, processes created with std.process: 
> spawnProcess are not terminated when the creating process 
> terminates, i.e. it seems Config.detached is the default for 
> these process.
>
> Is there a way of all spawned processes being terminated on 
> main termination?

You can wrap in a Process struct or class and take advantage of 
the destructor to do that. Assuming you write standard GC-ed code 
the destructor should be called at the end or if you free 
manually the resources.

example API:

struct SpawnedProcess
{
private:
     Pid pid;
public:
     this();
     void execute();
     void terminate();
     bool running();
     ~this(){ if (running) terminate();}
}

P.S: i just see that in my own Process class i forgot to do that.


More information about the Digitalmars-d-learn mailing list