Determine which signal uncaught by terminated child process

1

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
cocoa
macos
ipc
signals
nstask
asked on Stack Overflow Jun 1, 2011 by zpasternack • edited Jun 5, 2011 by zpasternack

1 Answer

2

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

answered on Stack Overflow Apr 13, 2019 by ial

User contributions licensed under CC BY-SA 3.0