I have 2 processes talking to each other Sender and Receiver via socket.I would like to catch signal Control-C and instead of exiting - display some output.Sender and Receiver are working fine,so I added signal(SIGINT,handler) to Sender's body. handler() just outputs some text.So when I run them and hit Cnt-C - signal gets caught and handler outputs the text but exits the Sender process.Sender has a loop that listens for user input unless Cnt-D - so why handler is making Sender exit?
Asked
Active
Viewed 1,083 times
2 Answers
1
If you are not re-registering the signal inside the handler, then it will revert to the default value, and exit once a signal has been sent the second time. For more detailed explanation look at my post here.
-
Thanks! Reading your Do's and Don't helped.Fixed it. – user629034 Mar 11 '11 at 07:33
1
You need to trap/handle both signal 2 (SIGINT) and 3 (SIGEXIT I believe). Note that you generally do not want to do this: Control-C should always be a last-resort really exit strategy. The only legitimate reason to trap it is to do cleanup etc.
dtech
- 13,741
- 11
- 48
- 73