I have a process using sockets, database connections and the likes. It is basically a server process relaying between sensor data and a web interface, and as such it is impo
I sometimes like to get a backtrace on SIGSEGV, the catching part goes like:
#include
#include
#include
void sig_handler(int);
int main() {
signal(SIGSEGV, sig_handler);
int *p = NULL;
return *p;
}
void sig_handler(int sig) {
switch (sig) {
case SIGSEGV:
fprintf(stderr, "give out a backtrace or something...\n");
abort();
default:
fprintf(stderr, "wasn't expecting that!\n");
abort();
}
}
You do want to be very careful handling these things, e.g. make sure you can't trigger another signal.