- 论坛徽章:
- 0
|
我在aix下编译了一个包含定时器的c的so;当我用c调用这个so时定时器执行正常;但通过JNI接口去调用这个so时,定时器在第二次执行时报alarm clock,然后程序就退出了。请问这是为什么?
下面是定时器函数的定义:
#include <stdio.h> /* Needed for printf */
#include <sys/time.h> /* Needed for gettimer */
#include <sys/types.h> /* Needed for gettimer */
#include <unistd.h> /* Needed for setitimer */
#include <signal.h> /* Needed for sigemptyset... */
#define SECS_DELAY 10 /* Period of interrupt in seconds */
#define USECS_DELAY 0 /* Period of interrupt in microseconds */
static void sigroutine(int signo);
void InitMyTimer()
{
struct itimerval setup_clock, old_clock; /* Define */
struct timeval time_setting; /* Define */
long *old_handler = (long *) -1; /* Define and initialize */
sigset_t set, old_set; /* Define */
struct sigaction action, oaction; /* define */
sigemptyset(&set); /* Get a clean set */
sigaddset(&set, SIGALRM); /* Add SIGALARM */
/* Setup the handler */
action.sa_handler = &sigroutine;
/* Setup signal handler */
if (sigaction(SIGALRM, &action, &oaction) != 0)
{
perror("-------------sigaction > ");
return;//exit(1);
}
/* Setup the interrupt characteristics */
time_setting.tv_sec = SECS_DELAY;
time_setting.tv_usec = USECS_DELAY;
/* Setup the control structure */
setup_clock.it_interval = time_setting;
setup_clock.it_value = time_setting;
/* OK, ready to go, start the interrupt */
if (setitimer(ITIMER_REAL, &setup_clock, &old_clock) != 0) {
perror("-------------setitimer > ");
return;//exit(1);
}
return;
}
static void sigroutine(int signo)
{
unsigned long mRv;
time_t t;
struct tm tm1;
time(&t);
tm1 = *localtime(&t);
printf("----更新时间%d:%d:%d-------\n", tm1.tm_hour, tm1.tm_min, tm1.tm_sec);
return;
} |
|