POSIX Timers on Linux 2.4



Hello Folks,

I am having problems with some POSIX timers code under kernel 2.4.32.
It seems that, as far as I can tell, the timer that I create via
timer_create() and timer_settime() is not firing.

Upon my timer firing, the code should generate SIGINT and execute a
signal handler (sighandler()) that I installed via sigaction(). This
is not occuring. The handler does, however, get invoked and do its
thing if I do a Ctrl-C via the keyboard. Just not by the POSIX timer.

This timer code works correctly under IRIX 6.5.22 and SunOS 5.7 and
a system running the Linux 2.6.13 kernel.

The code follows. Any feedback re the above is welcome.

Thanks,

Josh.


/*** timer.c ***/

#include "timer.h"

int intr = 0;
timer_t timerOne = 0;

int main()
{
struct sigaction sigAct;
int i = 0;
struct sigevent evpTimerOne;
struct itimerspec spec;

if( sigemptyset( &sigAct.sa_mask ) != 0 )
{
perror( "timer: ERROR: sigemptyset" );
exit( EXIT_FAILURE );
}

sigAct.sa_handler = sighandler;
sigAct.sa_flags = 0;

evpTimerOne.sigev_notify = SIGEV_SIGNAL;
evpTimerOne.sigev_signo = SIGINT;

if( timer_create( CLOCK_REALTIME, &evpTimerOne, &timerOne ) != 0 )
{
perror( "timer: ERROR: timer_create" );
exit( EXIT_FAILURE );
}

spec.it_value.tv_sec = 3;
spec.it_value.tv_nsec = 0;
spec.it_interval.tv_sec = 3;
spec.it_interval.tv_nsec = 0;

if( timer_settime( timerOne, 0, &spec, NULL ) != 0 )
{
perror( "timer: ERROR: timer_settime" );
exit( EXIT_FAILURE );
}

if( sigaction( SIGINT, &sigAct, NULL ) != 0 )
{
perror( "timer: ERROR: sigaction" );
exit( EXIT_FAILURE );
}

for( ;; )
{
intr = 0;

pause();

if( intr )
{
printf( "caught SIGINT\n" );
}
}

return (0);
}


static void sighandler( int si_signo )
{
switch( si_signo )
{
case SIGINT:
{
intr++;
break;
}
}
}


/*** timer.h ***/

#ifndef TIMER_H
#define TIMER_H

#include <stdio.h>
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>

static void sighandler( int si_signo );

#endif /* TIMER_H */
.



Relevant Pages