Catch SIGBUS in C and C++
问题 I want to catch SIGBUS, my code is shown below: #include <stdlib.h> #include <signal.h> #include <iostream> #include <stdio.h> void catch_sigbus (int sig) { //std::cout << "SIGBUS" << std::endl; printf("SIGBUS\n"); exit(-1); } int main(int argc, char **argv) { signal (SIGBUS, catch_sigbus); int *iptr; char *cptr; #if defined(__GNUC__) # if defined(__i386__) /* Enable Alignment Checking on x86 */ __asm__("pushf\norl $0x40000,(%esp)\npopf"); # elif defined(__x86_64__) /* Enable Alignment