Handling SIGFPE signal

Hi,

I have a signal handler routine for SIGFPE as follows:

void myOverflowHandler(int number1) {

  printf("Error occurred: \n");
  signal(SIGFPE,myOverflowHandler);

}

The calling function in main is:

printf("%d", 10/0);
printf("Came out of loop\n");

In the routine, I do not want to terminate the process, but return control back to the error causing statement and continue to the next line. But this seems to go on in an endless loop, printing the first statement (never coming to "Came out of loop"). Can anybody let me know what is the problem?

Regards,
nganesh.
LVL 1
nganeshAsked:
Who is Participating?
 
sunnycoderConnect With a Mentor Commented:
nganesh,

Sorry for the previous post
> In the routine, I do not want to terminate the process, but return control back to the error
> causing statement and continue to the next line
Look into sigsetjmp() and siglongjmp()

Sunnycoder
0
 
sunnycoderCommented:
Hi nganesh,



Sunnycoder
0
 
ahoffmannCommented:
if you want to exit after the very first SIGPIPE then remove
  signal(SIGFPE,myOverflowHandler); in your myOverflowHandler()
0
 
nganeshAuthor Commented:
Thanks a lot for the answer, Sunnycoder. sigsetjmp() and siglongjmp() solved my problem. I wanted to return control back to the program after executing the handler.

Regards,
nganesh.
0
All Courses

From novice to tech pro — start learning today.