Any idea why the signal handler goes to infinite loop?
Here is the code.
Please help me.
enter code here
9 void SIGSEGV_handler(int signal)
10 {
11 printf("Segmentation fault caught....
");
12 printf("Value of instance variable: i = %d
", i);
13 }
16
17 int main()
18 {
19 char *mallocPtr, *callocPtr, *reallocPtr, *memalignPtr, *vallocPtr;
20 struct sigaction sa;
21
22 sa.sa_handler=SIGSEGV_handler;
23 sigaction(SIGSEGV, &sa, NULL);
24
37
38 printf("The segmentation fault handler will be entered for i = 3, 4, 5 and 6
");
39
40
41 for(i=0; i<7; i++)
42 {
43 printf("i = %d
",i);
44
45 mallocPtr=(char*)malloc(3);
46 printf("Malloc address : %x
",mallocPtr);
47 strcpy(mallocPtr, "Hhvhgvghsvxhvshxv");
48 puts(mallocPtr);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…