I am new to signals in Unix, the purpose of this exercice is to disable SIGINT for stopping the program and use SIGQUIT instead, and it is successfully ignoring SIGINT when i press ctrl-c but the printf isnt showing until i press the Ctrl-/ which is for the SIGQUIT, and all the messages appear at once.
Example: if i press ctrl-c 4 times then ctrl-/: Only after pressing ctrl-\ i get 4 messages saying i have pressed Ctrl-c then the quitting you sent the SIGQUIT signal.
If i press ctrl-c only i get nothing but at least it is being ignored
struct sigaction action;
void hand(int sig)
{
switch(sig){
case SIGINT:
printf("You have presed ctrl-c");
break;
case SIGQUIT:
printf("Quittin you sent a SIGQUIT signal");
exit(SIGQUIT);
break;
default:
printf("WRONG SIGNAL");
exit(-1);
break;
}
}
int main()
{
action.sa_handler=hand;
printf("Ctrl-C disabled, press Ctrl-/ to quit...\n");
sigaction(SIGINT,&action,NULL);
sigaction(SIGQUIT,&action,NULL);
while(1){
sleep(1);
}
}