Terminating multiple processes
Steven Schveighoffer
schveiguy at yahoo.com
Wed Jan 31 18:26:40 UTC 2018
On 1/31/18 12:44 PM, Russel Winder wrote:
> So, I have an application which has a sort of nano-services
> architecture, basically it is a set of communicating processes.
> Terminating those processes blocked on an input channel is quite easy,
> send a terminate message on the input channel. But what about a process
> that has no input channel, one that is blocked on OS events?
>
> Is there a way of forcibly, but nicely, terminating a spawned process
> that never executes `receive()`?
>
You talking about processes or threads? `receive` I believe is an
inter-thread channel, no?
Terminating processes is generally done via signals or in the case of
windows, calling the right system call.
Threads are another story. Typically, you need to have the thread check
periodically for a termination event. There's no "nice" way to do it out
of band.
In my experience, the best way to do it is to never block, but use some
sort of "wait on input" for any would-be-blocking operation. You can use
a large timeout, like 1 second, if immediate termination isn't important.
If you are using Fibers, and all your i/o is done using some event-based
system (e.g. vibe.d), then things can be easier.
-Steve
More information about the Digitalmars-d-learn
mailing list