//* The handling control queue signals in Posix *

#include <signal.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #define BUFFER_SIZE 50 static const char buffer[] = "Caught <ctrl><c>\n"; /* the signal handler function */ void handle_SIGINT(int num) { // On Windows higher level IO can be used here // On *nix try to stay way from that write(STDOUT_FILENO,buffer,strlen(buffer)); // Cleanup and close up stuff here // Terminate program exit(0); } int main(int argc, char *argv[]) { // Register signal and signal handler struct sigaction handler; handler.sa_handler = handle_SIGINT; handler.sa_flags = 0; sigemptyset(&handler.sa_mask); sigaction(SIGINT, &handler, NULL); // Doing the program while (1) ; return 0; }