确定终止的子进程未捕获哪个信号
我有一个 Mac OS X 应用程序 (Cocoa),它生成一个 C++ 控制台帮助程序应用程序来完成一些工作。 GUI 通过 NSTask 生成助手,它们通过命名管道相互通信。这一切都很好。
如果帮助程序应用程序终止,GUI 会收到 NSTaskDidTerminateNotification,并且可以调用终止原因来确定帮助程序是否正常退出或被终止 (NSTaskTerminationReasonUncaughtSignal)。但是,有什么方法可以准确确定哪些信号未被捕获呢?例如,我想知道它是 SIGBUS 还是 SIGABRT。
这可能吗? NSTask 似乎没有这个功能,但也许有一些 UNIX-y 巫毒?
更新: Terminal.app 肯定知道。例如:
$ cat >crash.c
int main( void ) {
int *crashy = 0;
*crashy = 0xdeadbeef;
return 0;
}
^C
$ clang crash.c
$ ./a.out
Segmentation fault
I have a Mac OS X app (Cocoa), which spawns a C++ console helper app to do some work. The GUI spawns the helper via NSTask, and they communicate with each other via named pipes. This is all good.
If the helper app dies, the GUI gets an NSTaskDidTerminateNotification, and can call terminationReason to determine if the helper quit normally or was killed (NSTaskTerminationReasonUncaughtSignal). But, is there any way to determine precisely what signal was uncaught? I'd like to know if it was SIGBUS, or SIGABRT, for example.
Is this possible? NSTask seems not to have this functionality, but perhaps there's some UNIX-y voodoo?
Update:
Terminal.app sure knows. For example:
$ cat >crash.c
int main( void ) {
int *crashy = 0;
*crashy = 0xdeadbeef;
return 0;
}
^C
$ clang crash.c
$ ./a.out
Segmentation fault
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需采取退出代码
task.terminationStatus 就是您所需要的,它是信号之一的代码 https://www.tutorialspoint.com/unix/unix-signals-traps.htm
Just take exit code
task.terminationStatus is what you need, it is the code of signal one of https://www.tutorialspoint.com/unix/unix-signals-traps.htm