ordo-one / package-benchmark

Swift benchmark runner with many performance metrics and great CI support
Apache License 2.0
310 stars 23 forks source link

kill child processes when benchmarking is terminated with Ctrl-C #74

Open dimlio opened 1 year ago

dimlio commented 1 year ago

Now when a benchmark hangs and I terminate it with Ctrl-C spawned processes remain running.

hassila commented 1 year ago

Agree, this is a bit irritating - it's a bit unclear how I can trap signals easily in the top level command plugin portably though, needs investigation.

hassila commented 1 year ago

I did a try on this, but it seems even with --disable-sandbox I can't send a signal to the child process, with sandbox I get EPERM and with sandbox disabled I get ESRCH (with the correct pid provided).

I basically did this (in benchmark command plugin, command tool and benchmark runner all the way):

  var childPid: pid_t = 0
...
                _ = signal(SIGINT, callback)
...
    typealias SignalCallbackType = @convention(c) (Int32) -> Void
    let callback: SignalCallbackType = { signalNumber in
        let result = kill(childPid, SIGINT)
        print("\(childPid) Errno \(errno), result \(result)")
        exit(0)
    }

I can get a printout so the signal handler is correctly installed, I just can't kill the child processes.

hassila commented 1 year ago

I filed this case too:

https://github.com/apple/swift-package-manager/issues/6307