Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: signal catc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 10 of 10 Topic 1078 of 1134
Post > Topic >>

Re: signal catching not work

by Terry <cong818@[EMAIL PROTECTED] > May 5, 2008 at 04:01 PM

When I use the siglongjmp and sigsetjmp which are in C99, and the 
problem solved!!! :-)
Because a normal longjmp may not save the signal context in it jump
buffer.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>

jmp_buf buf;
volatile int i=0;
void sighandler(int a){
     siglongjmp(buf, ++i);
}

union {
     int *p;
     int i;
} a;

int *p;

int main(){
     if(signal(SIGSEGV, sighandler)==SIG_ERR){
         perror("error signal");
         abort();
     }
     while(1){
         switch(sigsetjmp(buf,1)){
             case 0:
                 a.i=0;
                 printf("%d\n", *(a.p));
                 break;
             case 1:
                 puts("Union way has failed to access value in position 
0.");
                 memset(&p,0,sizeof(int*));
                 printf("%d\n", *p);
                 break;
             default:
                 puts("Memset way has failed to access value in position 
0.");
                 return;
         }
     }
}
-- 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 10 Posts in Topic:
signal catching not work
Terry <cong818@[EMAIL   2008-04-16 16:56:15 
Re: signal catching not work
jgd@[EMAIL PROTECTED] (J  2008-04-18 16:10:59 
Re: signal catching not work
Keith Thompson <kst-u@  2008-04-21 13:18:42 
Re: signal catching not work
Jack Klein <jackklein@  2008-04-18 16:11:11 
Re: signal catching not work
=?ISO-8859-1?Q?Hans-Bernh  2008-04-18 16:11:13 
Re: signal catching not work
Kenneth Brody <kenbrod  2008-04-18 16:11:30 
Re: signal catching not working
Markus Elfring <Markus  2008-04-18 16:11:26 
Re: signal catching not work
Thomas Richter <thor@[  2008-04-18 16:11:23 
Re: signal catching not work
Terry <cong818@[EMAIL   2008-04-21 13:19:41 
Re: signal catching not work
Terry <cong818@[EMAIL   2008-05-05 16:01:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:14:34 CDT 2008.