views:

250

answers:

5

Hi,

Does the stack get unwound (destructors run) when a SIGABRT occurs in C++?

Thanks.

A: 

The signal(3) man page on my Mac OS X box says

  No    Name         Default Action       Description
...
 6     SIGABRT      create core image    abort program (formerly SIGIOT)

which suggests to me that the default is to not unwind...

dmckee
+2  A: 

This answer indicates that destructors aren't called.

Bill Zeller
+1  A: 

No, only exceptions trigger stack unwinding. Signals are part of POSIX, which is a C API, so it's not "aware of" C++ facilities such as exceptions.

Wyzard
+3  A: 

No:

$ cat test.cc
#include <iostream>
#include <sys/types.h>
#include <signal.h>

class Test {
public:
   ~Test() { std::cout << "~Test called" << std::endl; }
};

int main(int argc, char *argv[])
{
   Test t = Test();
   if (argc > 1) {
      kill(0, SIGABRT);
   }
   return 0;
}
$ g++ test.cc
$ ./a.out
~Test called
$ ./a.out 1
Aborted
Zach Hirsch
A: 

the signal SIGABRT is used for making core file of running application some time. We some time use this signal to debug application. And as far as I know Destructors are not called by this signal.

Vivek