Catching Signals in 'C'

Paul John Falstad pfalstad at bow.Princeton.EDU
Sat Sep 29 00:48:36 AEST 1990


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. 

I quote from K&R, p. 255:

"When a signal 'sig' subsequently occurs, the signal is __restored to its
default behavior__; then the signal-handler is called, as if by (*handler)(sig)."

The signal handler should reinstall itself before returning.  signal() apparently
does not act this way in my implementation (SunOS)...  Fortunately.

-- 
Here is the address to complain to:
pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD CIS: 70016,1355
That address again,
sync at thumper.princeton.edu PLink:OHS738 GEnie:OHS738 CIS: 4128 143 1234 937



More information about the Comp.lang.c mailing list