package-benchmark icon indicating copy to clipboard operation
package-benchmark copied to clipboard

kill child processes when benchmarking is terminated with Ctrl-C

Open dimlio opened this issue 2 years ago • 3 comments

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

dimlio avatar Feb 27 '23 16:02 dimlio

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 avatar Mar 16 '23 09:03 hassila

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 avatar Mar 17 '23 13:03 hassila

I filed this case too:

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

hassila avatar Mar 20 '23 08:03 hassila