On Wednesday 12 January 2005 23:38, Mark Hounschell wrote: There are a no. of problems with this code :
#include
#include #include long prev_fact, i; /* global variables */ void SIGhandler(int); /* RT-SIGNAL handler */
void SIGhandler(int sig) { printf("\nReceived Signal.\n"); exit(0); }
you cannot call printf from a signal handler - it is not a defined safe function according to posix 1003.1-2003... Generally any I/O cannot be done from a signal handler. You also cannot call exit() - you must call _exit() directly so that any exit functions added by the atexit() in other parts of your code will not be executed.
int main(void) {
printf("About to send signal\n");
signal(SIGRTMIN + 5, SIGhandler); /* setup handler */ raise(SIGRTMIN + 5); /* fire the signal */
printf("We did not receive the signal Oops...\n"); exit(0);
}
The signal() call is deprecated. You should be using the POSIX signals as defined in sigaction() and related functions. Usually all signal handlers do is set a global flag of type sigatomic_t. It is up to the calling function test the global flag and take appropriate action. Which kernel are you using ? Maybe you have tripped up on some weird interaction between signal(), SIGRTMIN and your kernel version... The signal() called may not support correctly the newer signals such as SIGRTMIN. Paul H -- Paul Hewlett (Linux #359543) Email:`echo az.oc.evitcaten@ttelweh | rev` Tel: +27 21 852 8812 Cel: +27 72 719 2725 Fax: +27 86 672 0563 --