#include /* for errno() */ #include /* for signal(), SIG* */ #include /* for printf(), ... */ #include /* for atoi() */ #include /* for strerror() */ #include /* for sleep() */ #include "funcs.h" /* for infomsg(), errormsg() */ /* * Macros */ #define TIMEOUT 5 /* * Type and struct definitions */ /* * Global variables */ int timed_out; /* * Forward declarations */ void sigint_handler(int); /* * Functions */ int main( int argc, char *argv[]) { char response[50]; infomsg("setting up signal handlers ..."); signal(SIGINT, sigint_handler); timed_out = FALSE; /* * Schedule timeout alarm. */ infomsg("scheduling timeout alarm ..."); alarm(TIMEOUT); /* * Ask user and read response. */ printf("continue (y/n): "); infomsg("calling fgets() ..."); fgets(response, sizeof(response), stdin); infomsg("returned from fgets()"); /* * Clean up and exit. */ infomsg("cleaning up and exiting ..."); signal(SIGINT, SIG_DFL); return(0); } void sigint_handler( int sig) { infomsg("received SIGINT"); }