>I'm porting a program from WIN32 to linux and came across the function
>'SetConsoleCtrlHandler'. This function 'catches' to Ctrl C button and
>instead of breaking the program, it gets rerouted to a function. (--> very
>handy if you are doing tests and want to finish the current test before
>My question now is: how can you catch the Ctrl C being pressed, so that it
>gets rerouted to a function instead of ending the program?
for the SIGINT signal. It's not guaranteed that the SIGINT signal is
generated in response to the interrupt key, but it does work on UNIX
platforms as well as MS Visual C++. For utmost portability, have your
signal handler store a value to a static object of type volatile
sig_atomic_t. Your mainline can inspect the value of that object from
time to time to discover whether the interrupt key has been pressed.