#include #include #include /* for memset */ #include #include int test=0; /* 1. Implement a signal handler function */ void handler(int signum) { //Set the variable to 1 test=1; } /* main program */ int main(void) { struct sigaction sa; /* for signal handler settings */ struct itimerval timer; /* for timer setting */ /* 2. set up the signal handler here */ memset(&sa, NULL, sizeof(sa)); sa.sa_handler = handler; sigaction(SIGALRM, &sa, NULL); /* 3. Set up the periodic timer here*/ timer.it_interval.tv_usec = 0; timer.it_interval.tv_sec = 1; timer.it_value.tv_usec = 0; timer.it_value.tv_sec = 1; /* set up the timer to run */ setitimer(ITIMER_REAL, &timer, NULL); /* NULL can be replaced with another timer object that will store the old timer settings */ /* Do some other processing. Nothing extra for exercise */ while(1) { if(test==1){ printf("Test."); test=0; } } return 0; }