diff --git a/c_expert/chapter7/cache.c b/c_expert/chapter7/cache.c index e217648..e5a8c8f 100644 --- a/c_expert/chapter7/cache.c +++ b/c_expert/chapter7/cache.c @@ -1,4 +1,5 @@ #include +#include #define DUMBCOPY for (i=0;i< 65536;i++) \ destination[i] = source[i] diff --git a/c_expert/chapter7/singnal_test.c b/c_expert/chapter7/singnal_test.c new file mode 100644 index 0000000..ff358ab --- /dev/null +++ b/c_expert/chapter7/singnal_test.c @@ -0,0 +1,22 @@ +#include +#include +#include + +void handler(int s) +{ + if (s == SIGBUS) printf(" now got a bus error signal \n"); + if (s == SIGSEGV) printf(" now got a segmentation violation signal \n"); + if (s == SIGILL) printf(" now got a illegal instruction signal \n"); + exit(1); +} + +int main(void) +{ + printf("begin \n"); + int *p = NULL; + signal(SIGBUS, handler); + signal(SIGSEGV, handler); + signal(SIGILL, handler); + *p = 0; + printf("end \n"); +}