Spawning a process, then killing it on SIGINT

Steven Schveighoffer schveiguy at gmail.com
Sun Nov 24 16:59:05 UTC 2019


On 11/24/19 10:36 AM, aliak wrote:
> On Saturday, 23 November 2019 at 12:19:27 UTC, Steven Schveighoffer wrote:
>> On 11/23/19 4:54 AM, aliak wrote:
>>> Is there a way to go about killing a process after spawning it on a 
>>> SIGINT?
>>>
>>> I can't do this for e.g. because kill is not @nogc.
>>>
>>> Pid currentSpawnedPid;
>>> extern(C) void killCurrentPidHandler(int sig) nothrow @nogc @system {
>>>    kill(currentSpawnedPid, sig);
>>> }
>>>
>>> int main() {
>>>    currentSpawnedPid = spawnProcess(["docker-compose", "up"], stdin, 
>>> stdout, stderr);
>>>    signal(SIGINT, &killCurrentPidHandler);
>>>    return wait(currentSpawnedPid);
>>> }
>>>
>>> Any other ways to go about this?
>>
>> Yeah, fix phobos. kill should be @nogc/nothrow, and probably @safe.
>>
> 
> Looked in to it, seems step one is getting phobos compiling with dip1008 :/
> Kill uses enforce.

Oof, yeah. I saw the short kill function and thought it was simply 
calling the kill syscall, but it's calling something more complex. Error 
handling in general in Phobos is somewhat of a mixed bag. Would be great 
to have a clearly defined error handling scheme, or even one that's 
configurable.

Or as you said, make dip1008 mandatory ;)

-Steve


More information about the Digitalmars-d-learn mailing list