-[NSConcreteTask waitUntilExit] 结果 KERN_PROTECTION_FAILURE

-[NSConcreteTask waitUntilExit] results in KERN_PROTECTION_FAILURE

我收到如下错误(经过删减以保护专有信息):

Process:               MyExecutable [7150]
Path:                  /Applications/Company Name/Parent App.app/Contents/PlugIns/MyExecutable
Identifier:            MyExecutable
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           MyExecutable [7150]
User ID:               1129915948
Date/Time:             2018-03-27 11:42:12.401 -0400
OS Version:            Mac OS X 10.12.6 (16G1212)
Report Version:        12
Anonymous UUID:        013E2942-CED9-22FA-438A-E3D0BA89EB5C
Time Awake Since Boot: 6200 seconds
System Integrity Protection: enabled
Crashed Thread:        0  Dispatch queue: com.apple.main-thread
Exception Type:        EXC_BAD_ACCESS (SIGBUS)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x00007fa9bc632b10
Exception Note:        EXC_CORPSE_NOTIFY
Termination Signal:    Bus error: 10
Termination Reason:    Namespace SIGNAL, Code 0xa
Terminating Process:   exc handler [0]
VM Regions Near 0x7fa9bc632b10:
    MALLOC_TINY            00007fa9bc400000-00007fa9bc600000 [ 2048K] rw-/rwx SM=PRV  
--> MALLOC_TINY            00007fa9bc600000-00007fa9bc700000 [ 1024K] rw-/rwx SM=COW  
    MALLOC_TINY            00007fa9bc700000-00007fa9bc800000 [ 1024K] rw-/rwx SM=PRV  
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   ???                             0x00007fa9bc632b10 0 + 140366986816272
1   com.apple.Foundation            0x00007fffa3225051 -[NSConcreteTask waitUntilExit] + 213
2   MyExecutable                    0x000000010dcfeb86 _TTSf4gs_gs_g___TF8MyExecutableP33_446BC8CF8CAA764CF050D96869CE3A5A18mySwiftFunctionFTSS7purposeSS18callbackFCSo7ProcessT__T_ + 1254
3   MyExecutable                    0x000000010dcfdbb7 _TZFC8MyExecutable12MyClassP33_446BC8CF8CAA764CF050D96869CE3A5A31someSwiftFunctionfT_T_ + 215
4   MyExecutable                    0x000000010dcfd985 _TZFC8MyExecutable12MyClass40someSwiftFunctionfT_T_ + 21
5   MyExecutable                    0x000000010dcd8e0f main + 241
6   libdyld.dylib                   0x00007fffb6ef3235 start + 1

有问题的代码试图通过在 Objective-C 中使用 Process (AKA NSTask 来 运行 终端命令;由 NSConcreteTask 实施)。它是这样准备的:

process.launchPath = "/bin/bash"
process.arguments = ["-c", bashCommand]
process.terminationHandler = callback
process.launch()
process.waitUntilExit()

在调用 waitUntilExit 之前 运行 一切正常。当 运行s 时,应用程序立即崩溃并输出类似于上面的内容。

由于各种原因,我无法 运行 调试器对此进行测试,但我可以将日志行打印到控制台。 为什么它会这么严重地崩溃? 我什至看到那里有总线错误,大声哭泣...

同步 waitUntilExit() 和异步完成处理程序不能很好地协同工作。

如果使用异步完成处理程序等待退出实际上是没有意义的。

直接删行

process.waitUntilExit()