tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: joe () resptk ! bhp ! com ! au
To: tru64-unix-managers
Subject: Does 'setitimer' library function work ??
Date: Wed, 30 Aug 1995 03:37:10 +0000	[thread overview]
Message-ID: <96075322406801.tru64-unix-managers.marc@archive.invalid> (raw)

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 <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include <time.h>

/******************************************************************************/
/* 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

                 reply	other threads:[~1995-08-30  3:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox