C program which doesn't terminate when ctrl+c is pressed!!!
We can use signal handling in C for this. When ctrl+c is pressed, SIGINT signal is generated, we can catch this signal and run our defined signal handler.
#include <stdio.h>
#include <signal.h>
/* Signal Handler for SIGINT */
void sigintHandler(int sig_num)
{
//Reset handler to catch the SIGINT the next time
signal(SIGINT, sigintHandler);
printf("\n Cannot be terminated using Ctrl+C \n");
fflush(stdout);
}
int main ()
{
//Set the SIGINT signal handler to sigintHandler
signal(SIGINT, sigintHandler);
//infinite loop
while(1)
{}
return 0;
}
We can use signal handling in C for this. When ctrl+c is pressed, SIGINT signal is generated, we can catch this signal and run our defined signal handler.
#include <stdio.h>
#include <signal.h>
/* Signal Handler for SIGINT */
void sigintHandler(int sig_num)
{
//Reset handler to catch the SIGINT the next time
signal(SIGINT, sigintHandler);
printf("\n Cannot be terminated using Ctrl+C \n");
fflush(stdout);
}
int main ()
{
//Set the SIGINT signal handler to sigintHandler
signal(SIGINT, sigintHandler);
//infinite loop
while(1)
{}
return 0;
}
No comments:
Post a Comment