* SIGFPE captured repeatedly..
@ 2004-09-02 11:36 Vijayekkumaran.M
0 siblings, 0 replies; 3+ messages in thread
From: Vijayekkumaran.M @ 2004-09-02 11:36 UTC (permalink / raw)
To: linux-c-programming
Hi,
I am trying to write a small program which handles
SIGFPE..
The problem is that the handler is called infinitely..
Could somebody please tell me what I am missing..?
Please find the program below..
"Red Hat Linux release 7.3 (Valhalla)
Kernel 2.4.18-3 on an i686
gcc version 2.96"
Regards
Vijay
/*********************************************/
#include <signal.h>
#include <stdio.h>
void sig_s(int signo)
{
printf("Hai Division by zero:Floation point
exception\n");
/*signal(SIGFPE,sig_s);*/
}
#define BUFFER_SIZE 1024
int main()
{
int i,j,z;
char Buffer[BUFFER_SIZE];
int x;
FILE* fp = fdopen(0,"r");
signal(SIGFPE,sig_s);
for(x=0;x<5;x++)
{
fflush(fp);
i=0;j=0;
printf("Accepted i = %d and j= %d \n",i,j);
z = i/j;
printf("Result = %d\n",z);
}
return 0;
}
/*********************************************/
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: SIGFPE captured repeatedly..
@ 2004-09-02 11:48 Ganesh_Borse
0 siblings, 0 replies; 3+ messages in thread
From: Ganesh_Borse @ 2004-09-02 11:48 UTC (permalink / raw)
To: m_vkumaran, linux-c-programming
See 4th paragraph in Notes section in "man signal"
-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org]On Behalf Of
Vijayekkumaran.M
Sent: Thursday, September 02, 2004 5:07 PM
To: linux-c-programming@vger.kernel.org
Subject: SIGFPE captured repeatedly..
Hi,
I am trying to write a small program which handles
SIGFPE..
The problem is that the handler is called infinitely..
Could somebody please tell me what I am missing..?
Please find the program below..
"Red Hat Linux release 7.3 (Valhalla)
Kernel 2.4.18-3 on an i686
gcc version 2.96"
Regards
Vijay
/*********************************************/
#include <signal.h>
#include <stdio.h>
void sig_s(int signo)
{
printf("Hai Division by zero:Floation point
exception\n");
/*signal(SIGFPE,sig_s);*/
}
#define BUFFER_SIZE 1024
int main()
{
int i,j,z;
char Buffer[BUFFER_SIZE];
int x;
FILE* fp = fdopen(0,"r");
signal(SIGFPE,sig_s);
for(x=0;x<5;x++)
{
fflush(fp);
i=0;j=0;
printf("Accepted i = %d and j= %d \n",i,j);
z = i/j;
printf("Result = %d\n",z);
}
return 0;
}
/*********************************************/
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread* RE: SIGFPE captured repeatedly..
@ 2004-09-02 12:24 Colovic (ext_evosoft) Aleksandar
0 siblings, 0 replies; 3+ messages in thread
From: Colovic (ext_evosoft) Aleksandar @ 2004-09-02 12:24 UTC (permalink / raw)
To: linux-c-programming
Hi,
here is slightly modified code:
#include <signal.h>
#include <stdio.h>
static int j;
void sig_s(int signo)
{
j = 3;
printf("Hai Division by zero:Floation point exception\n");
}
#define BUFFER_SIZE 1024
int main()
{
int i,z;
char Buffer[BUFFER_SIZE];
int x;
FILE* fp = fdopen(0,"r");
signal(SIGFPE,&sig_s);
for(x=0;x<5;x++)
{
fflush(fp);
i=0;j=0;
printf("Accepted i = %d and j= %d \n",i,j);
z = i/j;
printf("Result = %d\n",z);
}
return 0;
}
/*********************************************/
Explanation: In case of 'divide error' system sends SIGFPE to your process.
Default action would be core dump and abortion of the
process, but since you installed an exception handler for this signal,
system expects that your signal handler somehow corrects invalid
situation and transfers control again to problematic division. Since you
didn't corrected the problem, CPU raises again 'divide error' exception and
system's exception handler (divide_error()) sends again SIGFPE to your
signal handler ....
In the code above, I declared problematic j variable as static and corrected
its value in the signal handler ... so loop continues and everything's well.
I hope, this helps
Aleksandar Colovic,
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-09-02 12:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-02 11:36 SIGFPE captured repeatedly Vijayekkumaran.M
-- strict thread matches above, loose matches on Subject: below --
2004-09-02 11:48 Ganesh_Borse
2004-09-02 12:24 Colovic (ext_evosoft) Aleksandar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).