======Project: Timers n' signals====== A project for Systems Programming by Brandon Kennedy during the fall 2011 semester. This project was begun on 12-15-2011 and is anticipated to take 4 hours. =====Objectives===== By undertaking this project I hope to refresh myself on the use of timers and signal handling. I am going to review a previous program and reformat it to be an alarm clock(soundless). =====Prerequisites===== In order to successfully accomplish/perform this project, the listed resources/experiences need to be consulted/achieved: * wikipedia and the c programming guide on timers and signals * c pocket reference * matt Hass (back in september =====Background===== The idea of this project is to use timers and signals to create a nagging alarm clock. I am hoping that by reviewing and re-implementing this program that I can brush up on timers and signal handling enough to be able to implement this concept in other programs. =====Attributes===== State and justify the attributes you'd like to receive upon successful approval and completion of this project. * attribute1: Signals -> this program handles signals * attribute2: timers -> this program implements a timer as an alarm clock =====Code===== Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within blocks here. //signal.c //An alarm function by brandon kennedy for systems programming //This function implements timers and signals as an alarm clock // //written in september of 2011 //Now being reused as a project for systems programming on 12-15-2011 //this file was created on 12-15-2011 #include #include #include #include #define INTERVAL 5 int howmany = 0; void alarm_wakeup (int i) { struct itimerval tout_val; signal(SIGALRM,alarm_wakeup); howmany += INTERVAL; printf("\n%d sec up, time to Wakeup!!!\n",howmany); tout_val.it_interval.tv_sec = 0; tout_val.it_interval.tv_usec = 0; tout_val.it_value.tv_sec = INTERVAL; /* 10 seconds timer */ tout_val.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &tout_val,0); } void exit_func (int i) { signal(SIGINT,exit_func); printf("\nYour up! Bye!!!\n"); exit(0); } int main () { struct itimerval tout_val; tout_val.it_interval.tv_sec = 0; tout_val.it_interval.tv_usec = 0; tout_val.it_value.tv_sec = INTERVAL; /* 10 seconds timer */ tout_val.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &tout_val,0); signal(SIGALRM,alarm_wakeup); /* set the Alarm signal capture */ signal(SIGINT,exit_func); while(1) { //printf("!"); } return 0; } =====Execution===== Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code: lab46:~/src/SysProg/signals$ ./signal 5 sec up, time to Wakeup!!! 10 sec up, time to Wakeup!!! 15 sec up, time to Wakeup!!! 20 sec up, time to Wakeup!!! 25 sec up, time to Wakeup!!! ^C Your up! Bye!!! lab46:~/src/SysProg/signals$ =====Reflection===== Timers rock! I can deffinitely see a future for timers in my programming. As for signals, I could play some pretty sweet tricks on people with those bad boys, talk about a runaway program :) =====References===== In performing this project, the following resources were referenced: * wiki page of timers and signal * the c programming guide of timers * matt haas * manual pages for signal and setitimer