-
January 5th, 2004, 11:48 AM
#1
Catching CTRL+C signal...
I am using "select()" to select from a read list.
the timeval is set to 1/2 second.
I have many objects allocated in which a CTRL+C or CTRL+BREAK would leak if i dont free them up.
So, what is a good strategy to catch CTRL+C so i may break out of the select() loop and free what needs be.
example source would be handy, for i have tried using "signal()" and was not able to get it to work appropriatly.
This source will be running on win32 as well as linux.
thanks ahead of time.
andy
-
January 5th, 2004, 01:38 PM
#2
Have a look at atexit. You basically set up a callback which executes when the program terminates. Sorry - I don't have an example.
Succinct is verbose for terse
-
January 5th, 2004, 01:41 PM
#3
Actually, I do have an example. Have a look at memory leaks
I use atexit to print out the memory leaks.
Succinct is verbose for terse
-
January 5th, 2004, 07:38 PM
#4
neat function, havnt seen that one before...
but that doesnt solve the problem when waiting on select() and a signal happens.
I thought of something while staring at the wall... would it be that im not handing the execpt read list in select(), so when a user tries to CTRL+C out, its trying to write the the except read list, but since its null, it is crashing?
i will have to do some studying.
Thanks again for the input, and any other input you may be able to give.
andy
-
January 5th, 2004, 07:48 PM
#5
Just to let you know...
The atexit() function adds the function func to a list of functions to be called without parameters on normal termination of the program. Normal termination occurs by either a call to exit() or a return from main(). The functions are called in the reverse order of their registration.
so it wont catch CTRL+C
-
January 5th, 2004, 07:54 PM
#6
I don't know if my Console Signals Handler sample helps but you can look at it in case it does.
-
January 5th, 2004, 08:23 PM
#7
ok i feel like a doofus...
It was catching the signals in release mode.. the only time it would "crash" was in debug. And the msg was telling me "1st chance exception - control-c"
So, that problem is solved. but a new one has arrived. Does anyone know how to disable 1st chance exceptions in debug mode using microsoft visual C++ 6.0
I have _CrtSetDbgFlag() enabled and would like to see the memory leaks, but if i hit ctrl+c, it gives me that message and quits. i need it to cleanly exit as it does in release mode.
thanks
andy
-
January 5th, 2004, 09:40 PM
#8
boy, not my day! i am zero for three today... you can just hit "ok" the the exception and the compiler just asks if you want your program to handle it anyway.
lol.. ok i am good to go. sometimes it just helps to type stuff out to other people
thanks all
andy
-
January 6th, 2004, 05:40 AM
#9
On Unix, You could try catching sighup, sigint or sigterm. One of them might equate to ctrl-C. sigkill or kill -9 isn't catchable. If ctrl-c equates to that, then you cannot catch it. The OS has been made this way so it is possible to kill rogue processes and the rogue processes cannot trap that signal to stop themselves from being killed.
On Windows, Ctrl-C is copy, Ctrl-X is cut, Ctrl-V is paste so you can probably catch it but it won't do what you want. In windows programming: you could try trapping the WM_KEYDOWN. The Ctrl-Break sequence is called VK_CANCEL.
Succinct is verbose for terse
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|