Skip to content

Commit 05672c3

Browse files
committed
Use the NSConcreteTask.setStartsNewProcessGroup private API to terminate subprocesses when the parent process exits
1 parent 8420220 commit 05672c3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Sources/Task.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,13 @@ extension Task {
402402
process.launchPath = self.launchPath
403403
process.arguments = self.arguments
404404

405+
// This is for terminating subprocesses when the parent process exits.
406+
// See https://github.com/Carthage/ReactiveTask/issues/3 for the details.
407+
let selector = Selector(("setStartsNewProcessGroup:"))
408+
if process.responds(to: selector) {
409+
process.perform(selector, with: false as NSNumber)
410+
}
411+
405412
if let cwd = self.workingDirectoryPath {
406413
process.currentDirectoryPath = cwd
407414
}
@@ -484,8 +491,8 @@ extension Task {
484491
process.standardError = stderrPipe.writeHandle
485492

486493
group.enter()
487-
process.terminationHandler = { nstask in
488-
let terminationStatus = nstask.terminationStatus
494+
process.terminationHandler = { process in
495+
let terminationStatus = process.terminationStatus
489496
if terminationStatus == EXIT_SUCCESS {
490497
// Wait for stderr to finish, then pass
491498
// through stdout.

0 commit comments

Comments
 (0)