From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96075322406801.tru64-unix-managers.marc@archive.invalid> From: joe () resptk ! bhp ! com ! au Date: Wed, 30 Aug 1995 03:37:10 +0000 To: tru64-unix-managers Subject: Does 'setitimer' library function work ?? X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96075322406801 Hi all, I have a problem of using the 'setitimer' library function. It just does not want to work which I do not have the foggiest why. The following code sets up a 'timer' to call a function every second. The code compiles ok, but fails when the 'setitimer' function is called. The code works fine on Sun-Sparcs. Would anybody know if the 'setitimer' library function has a bug ?? Or can anybody see if my code is suspect. Thanks in advance. Joe joe@resptk.bhp.com.au -------------------------->>>>> code (test.c) <<<<<----------------------------- #include #include #include #include /******************************************************************************/ /* Check Interrupt - check if have to stop and return from code */ /******************************************************************************/ void check_interrupt() { static int count = 0; printf("Got Blinked: %d", count++); return; } /******************************************************************************/ /* Setup Timer - routine to set up a repetitive timer for SIGALRM */ /******************************************************************************/ struct itimerval blink_timer; int setup_timer(useconds, seconds) int useconds; int seconds; { int ret; /* * Set the interval which to Re-Load repeatedly the timer */ blink_timer.it_interval.tv_usec = useconds; blink_timer.it_interval.tv_sec = seconds; /* * Set the initial value with which to set the timer */ blink_timer.it_value.tv_usec = useconds; blink_timer.it_value.tv_sec = seconds; /* * Turn on the timer NOW */ ret = setitimer(ITIMER_REAL, blink_timer, NULL); /* * Return 0 - setitimer set OK * Return -1 - setitimer FAILED */ return ret; } /******************************************************************************/ /* Start Blinker - start the timer blinking on 1sec intervals */ /******************************************************************************/ int start_blinker() { int ret; /* * Set the timer to blink on 1sec intervals */ ret = setup_timer(0, 1); if(ret == -1) { return -1; } signal(SIGALRM, check_interrupt); return 0; } /******************************************************************************/ /* Stop Blinker - stop the timer & remove signal trap */ /******************************************************************************/ void stop_blinker() { /* * Turn off timer */ (void)setup_timer(0, 0); signal(SIGARLM, SIG_IGN); return; } /******************************************************************************/ /* Main Code */ /******************************************************************************/ main() { if(start_blinker() == -1) { printf("Failed start_blinker\n"); } for(;;) { pause(); } } --------------------->>>>> end of code <<<<<<<<<<------------------------------- How to compile: cc -o test test.c