digitalmars.D.learn - Spawning a process, then killing it on SIGINT
- aliak (17/17) Nov 23 2019 Is there a way to go about killing a process after spawning it on
- mipri (18/21) Nov 23 2019 Well, this works:
- aliak (2/24) Nov 24 2019 Thanks, looks like I'll have to go that route.
- Steven Schveighoffer (3/20) Nov 23 2019 Yeah, fix phobos. kill should be @nogc/nothrow, and probably @safe.
- aliak (5/28) Nov 24 2019 Looked in to it, seems step one is getting phobos compiling with
- Steven Schveighoffer (8/34) Nov 24 2019 Oof, yeah. I saw the short kill function and thought it was simply
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? Cheers, - Ali
Nov 23 2019
On Saturday, 23 November 2019 at 09:54:48 UTC, 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.Well, this works: import std; import core.stdc.signal; extern(C) int kill(int pid, int sig) nothrow nogc system; int currentSpawnedPid; extern(C) void killCurrentPidHandler(int sig) nothrow nogc system { if (currentSpawnedPid > 1) kill(currentSpawnedPid, sig); } int main() { auto pid = spawnProcess(["sleep", "50s"], stdin, stdout, stderr); currentSpawnedPid = pid.processID; signal(SIGINT, &killCurrentPidHandler); return wait(pid); }
Nov 23 2019
On Saturday, 23 November 2019 at 10:09:51 UTC, mipri wrote:On Saturday, 23 November 2019 at 09:54:48 UTC, aliak wrote:Thanks, looks like I'll have to go that route.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.Well, this works: import std; import core.stdc.signal; extern(C) int kill(int pid, int sig) nothrow nogc system; int currentSpawnedPid; extern(C) void killCurrentPidHandler(int sig) nothrow nogc system { if (currentSpawnedPid > 1) kill(currentSpawnedPid, sig); } int main() { auto pid = spawnProcess(["sleep", "50s"], stdin, stdout, stderr); currentSpawnedPid = pid.processID; signal(SIGINT, &killCurrentPidHandler); return wait(pid); }
Nov 24 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
Nov 23 2019
On Saturday, 23 November 2019 at 12:19:27 UTC, Steven Schveighoffer wrote:On 11/23/19 4:54 AM, aliak wrote:Looked in to it, seems step one is getting phobos compiling with dip1008 :/ Kill uses enforce.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
Nov 24 2019
On 11/24/19 10:36 AM, aliak wrote:On Saturday, 23 November 2019 at 12:19:27 UTC, Steven Schveighoffer wrote: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 ;) -SteveOn 11/23/19 4:54 AM, aliak wrote:Looked in to it, seems step one is getting phobos compiling with dip1008 :/ Kill uses enforce.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.
Nov 24 2019