Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Catching Signals in 'C' Message-ID: <1990Sep28.231904.24123@virtech.uucp> Date: 28 Sep 90 23:19:04 GMT References: <1990Sep28.120043.17628@NCoast.ORG> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 44 In article <1990Sep28.120043.17628@NCoast.ORG> ramsey@NCoast.ORG (Cedric Ramsey) writes: >main() >{ > signal (SIGINT, (*handler1) ()); > signal (SIGQUIT, (*handler2) ()); On initial inspection I would say there was a problem with your call to signal. This is probably due to the fact that you left off some important code. Normally the signal would be used as follows: main() { int handler1(); int handler2(); (void) signal(SIGINT,handler1); (void) signal(SIGQUIT,handler2); Anyway, on to the real problem.... >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. To solve this problem you have to know that whenever a signal is caught the action for that signal is automatically reset to the default state. To fix this you must call signal() each time the handler is executed. For example, handler1(sig) int sig; { signal(sig,handler1); . . . -- Conor P. Cahill (703)430-9247 Virtual Technologies, Inc., uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160 Sterling, VA 22170