Spawning a process, then killing it on SIGINT

Steven Schveighoffer schveiguy at gmail.com
Sat Nov 23 12:19:27 UTC 2019


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.

-Steve


More information about the Digitalmars-d-learn mailing list