Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!necntc!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpda!hpesoc1!hpcllla!hpclisp!hpclmar!mar From: mar@hpclmar.HP.COM (Michelle Ruscetta) Newsgroups: comp.unix.questions Subject: question about signal Message-ID: <720001@hpclmar.HP.COM> Date: Thu, 24-Sep-87 22:54:19 EDT Article-I.D.: hpclmar.720001 Posted: Thu Sep 24 22:54:19 1987 Date-Received: Sun, 27-Sep-87 02:07:57 EDT Organization: HP ITG/ISO Computer Language Lab Lines: 42 Question about signal(): Should the return from a signal handling routine specified by a call to signal() go to the instruction which caused the signal, or to the instruction immediately following that which caused the signal? For example: void (*p_my_handler)(); main() { extern void my_handler(); int y = 0; int x = 3; p_my_handler = my_handler: signal(SIGFPE, p_my_handler); x = x/y; /* should my_handler return to here? */ printf("return from signal\n"); /* or should my_handler return to here? */ } void my_handler() { signal(SIGFPE, SIG_IGN); /* do something useful */ signal(SIGFPE, p_my_handler); } --------------------------- I have run this example on two different machines, with different results; (both were running implementations of System V) one returned to the statement following that which cause the signal (the printf), and the other returned to the instruction which caused the signal -- hence throwing the program into an infinite loop continuously executing x/y and catching the floating point exception. I know it is not very good practice to return from signal-handlers but this question came up in a discussion and I would be interested to hear opinions as to which is the 'correct' way for signal to handle this.