Catching Signals in 'C'

Christopher R Volpe volpe at underdog.crd.ge.com
Sat Sep 29 05:45:02 AEST 1990


In article <2905 at idunno.Princeton.EDU>, subbarao at phoenix.Princeton.EDU
(Kartik Subbarao) writes:
|>In article <2901 at idunno.Princeton.EDU> pfalstad at bow.Princeton.EDU
(Paul John Falstad) writes:
|>>In article <1990Sep28.120043.17628 at NCoast.ORG>, ramsey at NCoast.ORG
(Cedric Ramsey) writes:
|>>|> Hello peoplekind. I have a question about the behavior of the
|>>|> signal function. Firstly, I want to trap the control-c, break,
|>>|> and other interrupt keys the user may use to stop a program.
|>>|> I did this by ;
|>>|> 
|>>|> main()
|>>|> {
|>>|>   signal (SIGINT, (*handler1) ());
|>>|>   signal (SIGQUIT, (*handler2) ());
|>>|>   ... 
|>>|> }
|>>|> 
|>>|> 
|>>|> But, when I type a control-c the program handles the signal as
|>>|> expected; however, when I type the control-c a second time the program 
|>>|> doesn't catch it and simply exits. 

Isn't the above call to signal messed up to begin with? He is INVOKING
the handler itself and using the return value as the argument to
"signal". Shouldn't he just be passing "handler1" and "handler2", i.e.,
the *addresses* of the functions? Shouldn't the code read:
main()
{
  signal(SIGINT,handler1);
  signal(SIGQUIT,handler2);
}
                                                            
==================
Chris Volpe
G.E. Corporate R&D
volpecr at crd.ge.com



More information about the Comp.lang.c mailing list