// A demo of using signal handlers. #include #include #include #include // a signal handler function void sig_handler(int signo) { if (signo == SIGINT) { printf("\nIf you strike me down, I shall become more powerful than you can possibly imagine!\n"); } else if (signo == SIGTERM) { printf("\nI feel a great disturbance in the Force...\n"); } } int main() { // install the signal handler if (signal(SIGINT, sig_handler) < 0 || signal(SIGTERM, sig_handler) < 0) { printf("error installing handler\n"); exit(1); } while (1) { printf("Use the Force, Luke\n"); getchar(); // wait for user to press enter (or anything else) } return 0; }