Hi,
Does the stack get unwound (destructors run) when a SIGABRT occurs in C++?
Thanks.
Hi,
Does the stack get unwound (destructors run) when a SIGABRT occurs in C++?
Thanks.
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...
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.
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
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.