KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am supposed override the Ctrl C signal and use it to print a message. It is not supposed to end the program. What happens so far is that when Ctrl C is pressed it prints the message, but ends the program. When I asked my professor he told me to do this: You need to make your signal handler keep from continuing to process the signal. Right now the signal is being handled by your code and then going on to the parent handler. Is there a method I am supposed to add or do i need to move the signal installers someplace? This is my code so far: #include <stdio.h> #include <unistd.h> #include <sys/wait.h> #include <sys/types.h> #include <signal.h> #include "Input.h" #include "CircleBuff.h" //void handler_function(int signal_id); void catch_int(int sig_num){ //reset the signal handler again to catch_int, for next time signal(SIGINT, catch_int); //print message printf("Print History"); fflush(stdout); } void printHistory(CircleBuff hist){ cout << "Complete History:\n" << endl; hist.print(); cout << endl; } int main(int argc, char** argv){ struct sigaction signal_action; /* define table */ signal_action.sa_handler = catch_int; /* insert handler function */ signal_action.sa_flags = 0; /* init the flags field */ sigemptyset( &signal_action.sa_mask ); /* are no masked interrupts */ sigaction( SIGINT, &signal_action, NULL ); /* install the signal_action */ do{ //My code: where the value report will be assigned within. } while(report != 1) }
Tags (comma-separated)
Save Edits
Cancel