signal handler c
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
void sig_handler(int signum){
//Return type of the handler function should be void
printf("nInside handler functionn");
}
int main(){
if(signal(SIGINT,sig_handler) == SIG_ERR)
// Register signal handler and checking if it gets error
exit(-1);
else{
for(int i=1;;i++){ // Infinite loop
printf("%d : Inside main functionn",i);
sleep(1); // Delay for 1 second
}
}
// Remember SIGINT signal is sent by pressing CTRL + C
}