Author |
Topic: signal handler execution path (Read 435 times) |
|
morningkiran
Newbie
Gender:
Posts: 1
|
|
signal handler execution path
« on: Nov 20th, 2007, 9:00pm » |
Quote Modify
|
Hi all Iam having trouble with signal handler. Where will the execution return after invoking a signal handler when that particular signal is recieved? will return to the point where we register the signal? The following code is recieveing recursive signals. Code: 1 #include <signal.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 6 void handle_sigsegv(int sig) 7 { 8 printf("Caught SIGSEGV!!\n"); 9 sleep(1); 10 } 11 12 int sig_segv(){ 13 int *p = NULL; 14 *p = 10; 15 return 0; 16 } 17 18 int main() 19 { 20 int ret_val = 0; 21 signal(SIGSEGV,handle_sigsegv); 22 printf("before segfault \n"); 23 ret_val = sig_segv(); 24 printf("after segfault \n"); 25 return 0; 26 } |
| Please throw some light.
|
« Last Edit: Nov 20th, 2007, 11:20pm by morningkiran » |
IP Logged |
|
|
|
Grimbal
wu::riddles Moderator Uberpuzzler
Gender:
Posts: 7527
|
|
Re: signal handler execution path
« Reply #1 on: Nov 21st, 2007, 1:36am » |
Quote Modify
|
I played a bit with it and it seems that it returns to the very instruction that caused the exception. And some unixes will remove the handler when the signal is raised, which means that after printint the message, your program tries to dereference the null pointer again and this times fails the usual way with a core dump. If you want to return to anywhere else, you should probably use a long jump (search man longjmp).
|
|
IP Logged |
|
|
|
|