Reputation: 15058
I use Eclipse for C/C++ Developers version in order to write a code that has to respond to Ctrl+C click by sending the signal SIGINT. However, when I run my code from the console I find out that it doesn't respond to Ctrl+C at all. I diabled the functionality of Ctrl+C as a keymap for copy, and it still doesn't solve the problem. Do you know what I can do to solve it?
A Code example:
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
static void sig_int(int num) {
printf("\nerror\n");
}
int main (int argc, char *argv[]) { //7
sigset_t zeromask;
if (signal(SIGINT, sig_int) == SIG_ERR)
fprintf(stderr,"signal(SIGINT) error");
printf("Hello\n");
if (sigsuspend(&zeromask) != -1)
fprintf(stderr,"sigsuspend error");
}
If you run this code from Linux terminal, when you click "Ctrl+C", you'll get an "error" output. However, of you run it from Eclipse console, nothing will happen. Eclipse console doesn't treat Ctrl+C as keyboard interrupt.
Upvotes: 1
Views: 681
Reputation: 756
The reason is that gdb is catching the SIGINT signal and not passing it on.
If you go to the gdb console (the one with the gdb version; not the one labeled "traces") and enter "info signals" you'll see a list like the following:
info signals
Signal Stop Print Pass to program Description
SIGHUP Yes Yes Yes Hangup
SIGINT Yes Yes No Interrupt
SIGQUIT Yes Yes Yes Quit
SIGILL Yes Yes Yes Illegal instruction
Note that Pass for SIGINT is set to NO.
enter: handle SIGINT pass
SIGINT is also used by gdb so it may ask if you are really sure.
EDIT:
When I tried a simple program from Eclipse, the program is not receiving the SIGINT until the program has been paused. This may be a problem with Eclipse. When running directly from gdb, the program works as expected.
Upvotes: 1