Catching Signals in 'C'
Conor P. Cahill
cpcahil at virtech.uucp
Sat Sep 29 09:19:04 AEST 1990
In article <1990Sep28.120043.17628 at NCoast.ORG> ramsey at 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
More information about the Comp.lang.c
mailing list