Catching Signals in 'C'

Cedric Ramsey ramsey at NCoast.ORG
Mon Oct 1 02:30:38 AEST 1990


In article <12253 at crdgw1.crd.ge.com> volpe at underdog.crd.ge.com (Christopher R Volpe) writes:
>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

Oh, i'm sorry, please excuse me. I met to pass a pointer to a function namely,
signal(SIGINT, handler1);
signal(SIGQUIT, handler2);
I was thinking about function prototypes when I goofed there, an ansi c lint
checker would have caught it at compile though, but that's okay; I'm willing 
to take the flame for it; a minimum price for knowledge, hey.

Thankyou 4 your support.

	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%% Ignorance is the lack of knowledge, now you know ! ;-)  %%
	%%                                                         %% 
	%% Cedric A. Ramsey                                        %% 
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 



More information about the Comp.lang.c mailing list