Is destructor called if SIGINT or SIGSTP issued?

No, by default, most signals cause an immediate, abnormal exit of your program. However, you can easily change the default behavior for most signals. This code shows how to make a signal exit your program normally, including calling all the usual destructors: #include <iostream> #include <signal.h> #include <unistd.h> #include <cstring> #include <atomic> std::atomic<bool> quit(false); // … Read more

How can I catch a ctrl-c event?

signal isn’t the most reliable way as it differs in implementations. I would recommend using sigaction. Tom’s code would now look like this : #include <signal.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> void my_handler(int s){ printf(“Caught signal %d\n”,s); exit(1); } int main(int argc,char** argv) { struct sigaction sigIntHandler; sigIntHandler.sa_handler = my_handler; sigemptyset(&sigIntHandler.sa_mask); sigIntHandler.sa_flags = 0; … Read more