GeeksforGeeks
A computer science portal for geeks
#include <stdio.h>
#include <signal.h>
/* Signal Handler for SIGINT */
void sigintHandler(int sig_num)
{
/* Reset handler to catch SIGINT next time.
Refer http://en.cppreference.com/w/c/program/signal */
signal(SIGINT, sigintHandler);
printf("\n Cannot be terminated using Ctrl+C \n");
fflush(stdout);
}
int main ()
{
/* Set the SIGINT (Ctrl-C) signal handler to sigintHandler
Refer http://en.cppreference.com/w/c/program/signal */
signal(SIGINT, sigintHandler);
/* Infinite loop */
while(1)
{
}
return 0;
}
Ouput: When Ctrl+C was pressed two times
Cannot be terminated using Ctrl+C Cannot be terminated using Ctrl+C