Hallo Liste,
Morgen !!!!!.
hat jemand schon Timers mit POSIX-Timers unter Linux programmiert? Ich
programmiere auf SuSE 9.0 und so viel ich wieß sind die
functionen von Posix-Timers in den C- Sources (Biblothek) ( timer_create,
timer_settime, timer_delete, clock_gettime ... etc. ).
Ich habe den folgenden Programcode: tools.c
#include
#include
#include
#include
#include
#include
#include
#ifndef OK
#define OK 0
#endif
#define INTERVAL_UHR 1000 /* interval for intern clock, in millisecs*/
timer_t timer_UHR; /* timer ID */
static unsigned long clk_internuhr_sec=0; /* intern clock
in sec.*/
/****************************************************************************
function name: testTimer
****************************************************************************/
int testTimer(void)
{
timer_UHR = start_timer(INTERVAL_UHR, timeHandler);
while (1)
{
};
stop_timer(timer_UHR);
return 0;
}
/****************************************************************************
Function name: start_timer
*****************************************************************************/
timer_t start_timer(int interval_msec, void* handler_func)
{
timer_t cTimer; /* ptr to return value */
int i;
struct itimerspec setTimer; /* time to be set */
struct sigaction sa;
/* Install timer_handler as the signal handler for SIGALRM. */
memset (&sa, 0, sizeof (sa));
sa.sa_handler = &timer_handler;
sigaction (SIGALRM, &sa, NULL);
setTimer.it_value.tv_sec =interval_msec/1000;
setTimer.it_value.tv_nsec =(interval_msec%1000)*1000000;
setTimer.it_interval.tv_sec =interval_msec/1000;
setTimer.it_interval.tv_nsec =(interval_msec%1000)*1000000;
if ((i=timer_create( CLOCK_REALTIME, NULL, &cTimer))!=OK)
{
printf("\nErr with timer_create");
return(0);
}
if ((i=timer_settime( cTimer, CLOCK_REALTIME, &setTimer, NULL))!=OK)
{
printf("\nErr with timer_settime");
return(0);
}
return(cTimer);
}
/****************************************************************************
Function name: void stop_timer(timer_t dTimer);
*****************************************************************************/
void stop_timer(timer_t dTimer)
{
if (timer_delete(dTimer)!=OK)
{
printf("\nErr with timer_delete");
}
}
/****************************************************************************
Function name: void* my_handler(timer_t timerid, int arg);
*****************************************************************************/
void* timeHandler(int arg)
{
clk_internuhr_sec++;
printf("\nTime %i",clk_internuhr_sec);
return(NULL);
}
/****************************************************************************
Function name: main()
*****************************************************************************/
int main()
{
printf("TTT\n");
return testTimer();
}
Compiliert mit dem Befehl:
test3: /home/uvdata/PTP> gcc -Wall -ggdb -o tools.o -D__USE_POSIX199309
tools.c
Fehler Meldungen:
/tmp/ccmSuZ08.o(.text+0x139): In function `start_timer':
/home/uvdata/PTP/tools.c:99: undefined reference to `clock_settime'
/tmp/ccmSuZ08.o(.text+0x171):/home/uvdata/PTP/tools.c:105: undefined
reference to `timer_create'
/tmp/ccmSuZ08.o(.text+0x1a9):/home/uvdata/PTP/tools.c:115: undefined
reference to `timer_settime'
/tmp/ccmSuZ08.o(.text+0x1f3): In function `stop_timer':
/home/uvdata/PTP/tools.c:141: undefined reference to `timer_delete'
collect2: ld returned 1 exit status
Muss ich beim compilieren eine Library angeben oder verpasse ich etwas beim
Posix-timers ? Wenn ja welche oder was?
Danke im vorraus.
Ashley