signal test

This commit is contained in:
LingZhaoHui 2020-08-02 19:03:29 +08:00
parent 3e23f7fdb3
commit 08944c8ed0
2 changed files with 23 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#define DUMBCOPY for (i=0;i< 65536;i++) \
destination[i] = source[i]

View File

@ -0,0 +1,22 @@
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
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");
}