Catching Signals in 'C'
Brad Appleton
brad at SSD.CSD.HARRIS.COM
Sat Sep 29 06:31:56 AEST 1990
There is a difference between AT&T and BSD signal calls (that has already been
hinted at) that is important to know in this situation:
When you set-up a signal handler in the AT&T universe, your handler
is only called the very next time that signal is caught and subsequent
calls refer back to the default handler unless you reset your handler
in the handler-code.
When you set up a signal handler in the BSD universe, your handler
is called for all subsequent trappings of that signal unless you
specifically reset the handler to be something else in the handler-code.
The following code fragment might be used to set up a minimal
Control-C handler that would be portable accross Unixes (assuming that
"att_universe" is #defined for an AT&T system and "ucb_universe" is
#defined for a BSD system):
#include <stdio.h>
#include <signal.h>
void ctrl_c_handler()
{
printf( "\n+++ in ctrl_c_handler() +++\n" );
#ifdef att_universe
/* need to reset this handler so we can trap the signal again */
if ( signal( SIGINT, ctrl_c_handler ) < 0 )
perror( "unable to set-up SIGINT handler" );
#endif
}
main()
{
if ( signal( SIGINT, ctrl_c_handler ) < 0 )
perror( "unable to set-up SIGINT handler" );
printf( "about to loop forever\n\n" );
while (1);
}
Anybody know about DOS and/or VMS???
______________________ "And miles to go before I sleep." ______________________
Brad Appleton brad at travis.ssd.csd.harris.com Harris Computer Systems
...!uunet!hcx1!brad Fort Lauderdale, FL USA
~~~~~~~~~~~~~~~~~~~~ Disclaimer: I said it, not my company! ~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list