[LCP]SIGFPE
Ram
ram123p at yahoo.com
Fri Jul 12 13:53:06 UTC 2002
Quoting from some net sources:
When the signal handler returns, processing resumes at
the point of interruption. Depending on the signal
this can be undesirable. For example, a return in
connection with SIGFPE will lead to an immediate
second SIGFPE unless you patch up the problem.
Patching is very difficult but even if possible, will
require some dirty machine dependent method. Rather
than returning from the handler, a siglongjmp or exit
is more reasonable in this case.
Also signal man page says that
" According to POSIX, the behaviour of a process is
undefined after it ignores a SIGFPE, SIGILL, or
SIGSEGV signal that was not generated by the
kill() or the raise() functions. ""Integer division
by zero has undefined result."" On some architectures
it will generate a SIGFPE signal. (Also dividing the
most negative integer by -1 may generate SIGFPE.)
Ignoring this signal might lead to an endless loop"
Both seem to suggest that it will go in loop.
But its not clear why ??
- Ram
--- Jack Lloyd <lloyd at acm.jhu.edu> wrote:
> Well, it actually only says that ignoring this
> signal can result in an
> infinte loop. I would presume this means using
> SIG_IGN, rather than
> requiring that the signal handler must abort.
>
> There is a workaround to this. Basically, use setjmp
> and longjmp. Do a
> setjmp right before you do the potentially bad
> instruction, and do a
> longjmp out of the signal handler.
>
> I'm not totally sure that you're allowed to do
> longjmp inside a signal
> handler (actually, I'm pretty sure it's undefined by
> POSIX). But I've seen
> it done in several pieces of reasonable portable
> pieces of software. I've
> never done this for SIGFPE but I've seen it for
> SIGILL and done it myself
> for SIGPIPE.
>
> -Jack
>
> On 11 Jul 2002, devraj sanyal wrote:
>
> > This is the default behaviour of the kernel.
> > on sigfpe the kernel loops on the signal
> > again and again. check out the man page
> > for signal.
> >
> >
> >
> >
> > On Thu, 11 Jul 2002 madhav morje wrote :
> > >Hello,
> > >
> > >I'm a novice in signal field. I was trying to out
> a simple
> > >program (which I've pasted below). When the
> binary was executed,
> > >signal handler for SIGFPE was executed
> continuously even though
> > >I've written a signal handler for it.
> > >
> > >My query is, why kernel continuously gives this
> signal to my
> > >program Or Am I missing something in my code??
> > >
> > >If I reset signal handler for SIGFPE to defualt
> one in the signal
> > >handler function, then my program gets
> terminated.
> > >
> > >Regards,
> > >Madhav.
> > >
> >
>
>======================================================
> > >#include <signal.h>
> > >#include <stdio.h>
> > >#include <unistd.h>
> > >
> > >void sighand(int sig)
> > >{
> > > printf("\nSig Recd %d", sig);
> > > /*
> > > ** Should signal handler be reset here for
> SIGFPE to default
> > >here ????
> > > */
> > >}
> > >
> > >int main()
> > >{
> > >
> > >struct sigaction act;
> > >int j=10,k;
> > >
> > >act.sa_handler = sighand;
> > >sigemptyset(&act.sa_mask);
> > >act.sa_flags = 0;
> > >
> > >sigaddset(&act.sa_mask, SIGFPE);
> > >
> > >(void) sigaction(SIGFPE, &act, 0);
> > >
> > >k=j/0;
> > >
> > >printf("\ndone!!\n");
> > >
> > >return 0;
> > >
> > >}
> >
>
>======================================================
> >
>
>_________________________________________________________
> > >There is always a better job for you at
> Monsterindia.com.
> > >Go now http://monsterindia.rediff.com/jobs
> > >
> > >
> > >_______________________________________________
> > >This is the Linux C Programming List
> > >:
> http://lists.linux.org.au/listinfo/linuxcprogramming
> List
> >
> >
>
_________________________________________________________
> > There is always a better job for you at
> Monsterindia.com.
> > Go now http://monsterindia.rediff.com/jobs
> >
> >
> > _______________________________________________
> > This is the Linux C Programming List
> > :
> http://lists.linux.org.au/listinfo/linuxcprogramming
> List
> >
>
>
> _______________________________________________
> This is the Linux C Programming List
> :
> http://lists.linux.org.au/listinfo/linuxcprogramming
List
__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
More information about the linuxCprogramming
mailing list