wu :: forums
« wu :: forums - signal handler execution path »

Welcome, Guest. Please Login or Register.
Nov 25th, 2024, 10:50am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: Eigenray, william wu, Grimbal, ThudnBlunder, towr, SMQ, Icarus)
   signal handler execution path
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: signal handler execution path  (Read 435 times)
morningkiran
Newbie
*





   
WWW

Gender: male
Posts: 1
signal handler execution path  
« on: Nov 20th, 2007, 9:00pm »
Quote Quote Modify 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: male
Posts: 7527
Re:  signal handler execution path  
« Reply #1 on: Nov 21st, 2007, 1:36am »
Quote Quote Modify 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
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board