Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!mailrus!usenet.ins.cwru.edu!ncoast!ramsey From: ramsey@NCoast.ORG (Cedric Ramsey) Newsgroups: comp.lang.c Subject: Re: Catching Signals in 'C' Message-ID: <1990Sep30.163038.10825@NCoast.ORG> Date: 30 Sep 90 16:30:38 GMT References: <2901@idunno.Princeton.EDU> <2905@idunno.Princeton.EDU> <12253@crdgw1.crd.ge.com> Organization: North Coast Public Access *NIX, Cleveland, OH Lines: 54 In article <12253@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes: >In article <2905@idunno.Princeton.EDU>, subbarao@phoenix.Princeton.EDU >(Kartik Subbarao) writes: >|>In article <2901@idunno.Princeton.EDU> pfalstad@bow.Princeton.EDU >(Paul John Falstad) writes: >|>>In article <1990Sep28.120043.17628@NCoast.ORG>, ramsey@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@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 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%