Determine which signal uncaught by terminated child process
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.ou开发者_如何学JAVAt
Segmentation fault
Just take exit code
NSTask* task = ...
[task waitUntilExit];
task.terminationStatus is what you need, it is the code of signal one of https://www.tutorialspoint.com/unix/unix-signals-traps.htm
精彩评论