/* * sigint-ignorer.c */ #include #include #include #include #include void handler(int signum); int main(int argc, char *argv[]) { struct sigaction sa; /* set up the struct that defines what to do on receipt of a signal */ memset(&sa, '\0', sizeof(sa)); sa.sa_handler = handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; /* associate that action with a particular signal */ if(sigaction(SIGINT, &sa, NULL) < 0) { perror("sigaction"); exit(1); } /* be helpful */ printf("My pid is %d\n", getpid()); /* infinite loop */ while(1) { printf("I'm going to sleep now.\n"); sleep(10); } } void handler(int signum) { printf("You pressed Ctrl-C and I'm not going to terminate!\n"); printf("Ha ha\n"); }