3

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

Thanks.

WilliamKF
  • 41,123
  • 68
  • 193
  • 295

5 Answers5

4

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
  • 24,631
  • 8
  • 32
  • 29
2

This answer indicates that destructors aren't called.

Community
  • 1
  • 1
Bill Zeller
  • 1,336
  • 1
  • 9
  • 13
1

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
  • 33,849
  • 3
  • 67
  • 87
0

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 --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
0

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
  • 473
  • 1
  • 3
  • 10