summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mokha@cisco.com>2016-06-24 13:57:14 -0400
committermo <mokha@cisco.com>2016-06-24 13:57:14 -0400
commit6bfe6482696164902f831aebae4a4ef99a0f9562 (patch)
tree333abba8a12c7ee506e161c9ed2eaf20ed18cbc5
parent4c0e550705dd2baa57ceaebbfcfe7db93bfab488 (diff)
complete lab9
-rw-r--r--lab09/timer.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/lab09/timer.c b/lab09/timer.c
index 6c609f5..467b3b4 100644
--- a/lab09/timer.c
+++ b/lab09/timer.c
@@ -17,17 +17,19 @@ void alarm_handler(int x) {
int main()
{
- /* define the initial and interval to run at 5 hz */
- struct timeval initial = {0, ???/RATE};
- struct timeval interval = {0, ???/RATE};
+ struct timeval initial = {0, 1000000/RATE};
+ struct timeval interval = {0, 1000000/RATE};
struct itimerval t;
t.it_value = initial;
t.it_interval = interval;
-
- /* install a signal handler for SIGALRM and start timer ticking */
-
- /* use the count variable to terminate after 10 seconds */
-
+ if (signal(SIGALRM, alarm_handler) != SIG_ERR) {
+ if (!setitimer(ITIMER_REAL, &t, 0)) {
+ /* Perform other tasks waiting for our SIGALRMs */
+ while(count <= 50) {
+ ;
+ }
+ }
+ }
exit(0);
}