* Query on SIGFPE handling
@ 2004-11-22 6:26 Jagadeesh Bhaskar P
2004-11-22 7:00 ` Manish Regmi
0 siblings, 1 reply; 10+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-22 6:26 UTC (permalink / raw)
To: Linux Newbie
Hi,
I wrote a the small program, to c how signals can be caught by
customized routines.
/*********** start of code ********/
#include <stdio.h>
#include <signal.h>
void fe(void){
printf("floating pt exception:\n");
}
int main(void){
signal(SIGFPE, (void *)fe);
printf("%f\n", (1/0));
return 0;
}
/********** end of code *************/
It goes on catching the signal infinitely, and if i didnt do the
customization of that signal handling, it comes only once and then
exits.
What is the reason? Isnt it supposed to generate a signal once per
event?
Someone please do reply,
--
With regards,
Jagadeesh Bhaskar P
R&D Engineer
HCL Infosystems Ltd
Pondicherry
INDIA
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 6:26 Query on SIGFPE handling Jagadeesh Bhaskar P
@ 2004-11-22 7:00 ` Manish Regmi
2004-11-22 7:15 ` Jagadeesh Bhaskar P
0 siblings, 1 reply; 10+ messages in thread
From: Manish Regmi @ 2004-11-22 7:00 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: linux-newbie
On Mon, 22 Nov 2004 11:56:12 +0530, Jagadeesh Bhaskar P
<jbhaskar@hclinsys.com> wrote:
> Hi,
>
> I wrote a the small program, to c how signals can be caught by
> customized routines.
>
> /*********** start of code ********/
>
> #include <stdio.h>
> #include <signal.h>
>
> void fe(void){
> printf("floating pt exception:\n");
> }
>
> int main(void){
> signal(SIGFPE, (void *)fe);
> printf("%f\n", (1/0));
> return 0;
> }
>
> /********** end of code *************/
>
> It goes on catching the signal infinitely, and if i didnt do the
> customization of that signal handling, it comes only once and then
> exits.
>
> What is the reason? Isnt it supposed to generate a signal once per
> event?
>
> Someone please do reply,
>
> --
> With regards,
>
> Jagadeesh Bhaskar P
> R&D Engineer
> HCL Infosystems Ltd
> Pondicherry
> INDIA
>
According to the history of UNIX, signal caught by signal function is
unreliable. You need to reload handler on each signal.
ie,
void fe(void){
printf("floating pt exception:\n");
signal(SIGFPE, (void *)fe);
}
It is a good idea to use sigaction(). It is a reliable function doing
the same thing .
see man sigaction
Regards manish
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 7:00 ` Manish Regmi
@ 2004-11-22 7:15 ` Jagadeesh Bhaskar P
2004-11-22 8:24 ` Jagadeesh Bhaskar P
[not found] ` <652016d3041122001540a047fd@mail.gmail.com>
0 siblings, 2 replies; 10+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-22 7:15 UTC (permalink / raw)
To: Manish Regmi; +Cc: Linux Newbie
On Mon, 2004-11-22 at 12:30, Manish Regmi wrote:
>
> > /*********** start of code ********/
> >
> > #include <stdio.h>
> > #include <signal.h>
> >
> > void fe(void){
> > printf("floating pt exception:\n");
> > }
> >
> > int main(void){
> > signal(SIGFPE, (void *)fe);
> > printf("%f\n", (1/0));
> > return 0;
> > }
> >
> > /********** end of code *************/
> >
> According to the history of UNIX, signal caught by signal function is
> unreliable. You need to reload handler on each signal.
> ie,
> void fe(void){
> printf("floating pt exception:\n");
> signal(SIGFPE, (void *)fe);
> }
I changed the code like above. But no change came. Is this caused by the
signal being generated many times, or is it just the problem with the
signal() function?
>
> It is a good idea to use sigaction(). It is a reliable function doing
> the same thing .
> see man sigaction
Im seeing into that also
--
With regards,
Jagadeesh Bhaskar P
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 7:15 ` Jagadeesh Bhaskar P
@ 2004-11-22 8:24 ` Jagadeesh Bhaskar P
[not found] ` <01ca01c4d071$5b35f080$121aa8c0@ascindia.com>
2004-11-22 11:15 ` joy merwin monteiro
[not found] ` <652016d3041122001540a047fd@mail.gmail.com>
1 sibling, 2 replies; 10+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-22 8:24 UTC (permalink / raw)
To: Manish Regmi; +Cc: Linux Newbie
Hi Manish,
As suggested, I rewrote the C program using sigaction, as follows:
/****** start of code **********/
#include <stdio.h>
#include <signal.h>
void fe(int x){
printf("floating pt exception:\n");
}
int main(void){
struct sigaction p;
p.sa_handler = fe;
sigaction(SIGFPE, &p, NULL);
printf("%f\n", (1/0));
return 0;
}
/********* end of code *******/
But then again the signal is being caught by the program infinitely. Why
is that happening, if last time it was a problem with the signal()
function.
Please do help!!
--
With regards,
Jagadeesh Bhaskar P
R&D Engineer
HCL Infosystems Ltd
Pondicherry
INDIA
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
[not found] ` <01ca01c4d071$5b35f080$121aa8c0@ascindia.com>
@ 2004-11-22 9:05 ` Jagadeesh Bhaskar P
2004-11-22 9:19 ` Manish Regmi
2004-11-22 9:26 ` Manish Regmi
0 siblings, 2 replies; 10+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-22 9:05 UTC (permalink / raw)
To: Yogesh Bute; +Cc: Linux Newbie
On Mon, 2004-11-22 at 14:27, Yogesh Bute wrote:
> hi,
> u need to inform the shell that the signal is handled - so u need to
> SIG_IGN the singal ie. signal (signum, SIG_IGN) once u have done with
> handling the signal
> or u could send SIG_DFL, so that default singal handler will handle the
> signal, after your specific signal handler code.
How can I generate and send a signal from a function of mine? Is it
possible from a userlevel C program, using some functions like
signal()??
Please do help
--
With regards,
Jagadeesh Bhaskar P
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: further query signal handling!
[not found] ` <1101113860.5382.36.camel@myLinux>
@ 2004-11-22 9:09 ` Manish Regmi
0 siblings, 0 replies; 10+ messages in thread
From: Manish Regmi @ 2004-11-22 9:09 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: linux-newbie
On Mon, 22 Nov 2004 14:27:40 +0530, Jagadeesh Bhaskar P
<jbhaskar@hclinsys.com> wrote:
> > You are generating a divide by zero exception (on i386) which is a
> > fault (it means the instruction is restartable). So what happens is
> > you catch an exception and print and return. The same code is
> > restarted again. so processor gets exception again and again.
>
> If the fault was not attached to a function written by me, and leaving
> it to be handled by the kernel, there was no problem. How can that
> happen? Shouldnt the kernel restart the instruction in that case also.
> Why didnt that happen?
>
> --
> With regards,
>
> Jagadeesh Bhaskar P
> R&D Engineer
> HCL Infosystems Ltd
> Pondicherry
> INDIA
In UNIX and like, the exceptions generate UNIX signals. IEEE POSIX
have defined what to do on generation of signals. The signal may have
default action, run user 's signal handler. For SIGFPE signal, The
default action is Abnormal termination of the process. But when you
set your handler, it does not terminate but runs your handler. After
returning from your handler it again tries to execute the faulting
instruction and signal is generate again and so on.
BTW:
For UNIX programming, Advanced UNIX programming by richard stevens is
the Best book (i have ever seen).
Regards Manish
--
Manish Regmi
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 9:05 ` Jagadeesh Bhaskar P
@ 2004-11-22 9:19 ` Manish Regmi
2004-11-22 9:26 ` Jagadeesh Bhaskar P
2004-11-22 9:26 ` Manish Regmi
1 sibling, 1 reply; 10+ messages in thread
From: Manish Regmi @ 2004-11-22 9:19 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: linux-newbie
> How can I generate and send a signal from a function of mine? Is it
> possible from a userlevel C program, using some functions like
> signal()??
>
> Please do help
> --
> With regards,
>
> Jagadeesh Bhaskar P
>
yes,
see man kill, raise
regards manish
--
Manish Regmi
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 9:05 ` Jagadeesh Bhaskar P
2004-11-22 9:19 ` Manish Regmi
@ 2004-11-22 9:26 ` Manish Regmi
1 sibling, 0 replies; 10+ messages in thread
From: Manish Regmi @ 2004-11-22 9:26 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: linux-newbie, yogeshb
On Mon, 22 Nov 2004 14:35:24 +0530, Jagadeesh Bhaskar P
<jbhaskar@hclinsys.com> wrote:
> On Mon, 2004-11-22 at 14:27, Yogesh Bute wrote:
> > hi,
> > u need to inform the shell that the signal is handled - so u need to
> > SIG_IGN the singal ie. signal (signum, SIG_IGN) once u have done with
> > handling the signal
> > or u could send SIG_DFL, so that default singal handler will handle the
> > signal, after your specific signal handler code.
Doing that will probably put you in infinite loop.
Infact, the is no way to go further unless you resolve the cause of
the exception.
For playing with Signals,
you can generate SIGUSR1 kill(pid, SIGUSR1) and catch.
--
Manish Regmi
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 9:19 ` Manish Regmi
@ 2004-11-22 9:26 ` Jagadeesh Bhaskar P
0 siblings, 0 replies; 10+ messages in thread
From: Jagadeesh Bhaskar P @ 2004-11-22 9:26 UTC (permalink / raw)
To: Manish Regmi; +Cc: Linux Newbie
On Mon, 2004-11-22 at 14:49, Manish Regmi wrote:
> see man kill, raise
Thank you. I got that!!
--
With regards,
Jagadeesh Bhaskar P
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Query on SIGFPE handling
2004-11-22 8:24 ` Jagadeesh Bhaskar P
[not found] ` <01ca01c4d071$5b35f080$121aa8c0@ascindia.com>
@ 2004-11-22 11:15 ` joy merwin monteiro
1 sibling, 0 replies; 10+ messages in thread
From: joy merwin monteiro @ 2004-11-22 11:15 UTC (permalink / raw)
To: Jagadeesh Bhaskar P; +Cc: Manish Regmi, Linux Newbie
The basic mistake is that the variable values have not changed.
1/0 will generate a FPE no matter what you do.
use variables like a=0;b=1;
and if b/a generates an FPE,
change its value.(bit hazy how to implement this... google around)
the reason for giving you a signal handler
is obviously to help you correct the error,
not commit it over and over again!
reagrds,
Joy.M.Monteiro
PS: Such questions will be better answered on linux-cprogramming list....
try it.
On Mon, 22 Nov 2004 13:54:36 +0530, Jagadeesh Bhaskar P
<jbhaskar@hclinsys.com> wrote:
> Hi Manish,
>
> As suggested, I rewrote the C program using sigaction, as follows:
>
> /****** start of code **********/
>
> #include <stdio.h>
> #include <signal.h>
>
> void fe(int x){
> printf("floating pt exception:\n");
> }
>
> int main(void){
> struct sigaction p;
> p.sa_handler = fe;
> sigaction(SIGFPE, &p, NULL);
> printf("%f\n", (1/0));
> return 0;
> }
>
> /********* end of code *******/
>
> But then again the signal is being caught by the program infinitely. Why
> is that happening, if last time it was a problem with the signal()
> function.
>
> Please do help!!
>
>
>
> --
> With regards,
>
> Jagadeesh Bhaskar P
> R&D Engineer
> HCL Infosystems Ltd
> Pondicherry
> INDIA
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.linux-learn.org/faqs
>
--
people always turn away,
from the eyes of a stranger...
Afraid to know
what lies behind the stare.......
--QueensRyche
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-11-22 11:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-22 6:26 Query on SIGFPE handling Jagadeesh Bhaskar P
2004-11-22 7:00 ` Manish Regmi
2004-11-22 7:15 ` Jagadeesh Bhaskar P
2004-11-22 8:24 ` Jagadeesh Bhaskar P
[not found] ` <01ca01c4d071$5b35f080$121aa8c0@ascindia.com>
2004-11-22 9:05 ` Jagadeesh Bhaskar P
2004-11-22 9:19 ` Manish Regmi
2004-11-22 9:26 ` Jagadeesh Bhaskar P
2004-11-22 9:26 ` Manish Regmi
2004-11-22 11:15 ` joy merwin monteiro
[not found] ` <652016d3041122001540a047fd@mail.gmail.com>
[not found] ` <1101113860.5382.36.camel@myLinux>
2004-11-22 9:09 ` further query signal handling! Manish Regmi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox