The signal()
call:
- Sets the handler that you specify as the new signal handler, and
- Tells you what the old handler is.
The new handler will be called instead of the old. If you want to link them, you need to do something like:
typedef void (*Handler)(int signum); static Handler old_int_handler = SIG_IGN; static void int handler(int signum) { ...do your signal handling... if (old_int_handler != SIG_IGN && old_int_handler != SIG_DFL) (*old_int_handler)(signum); } static void set_int_handler(void) { Handler old = signal(SIGINT, SIG_IGN); if (old != SIG_IGN) { old_int_handler = old; signal(SIGINT, int_handler); } } static void rst_int_handler(void) { Handler old = signal(SIGINT, SIG_IGN); if (old == int_handler) { signal(SIGINT, old_int_handler); old_int_handler = SIG_IGN; } } ...in another function... { ... set_int_handler(); ... rst_int_handler(); ... }
If interrupts are ignored, it ignores them. If interrupts were handled by a custom interrupt handler, then this calls your signal processing code and the signal processing source code.
Please note that the advice from Christian.K about the lack of signal processing in the DLL (shared library) is also relevant and relevant. The description above assumes that you decide to ignore this advice.
source share