免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3171 | 回复: 2
打印 上一主题 下一主题

aix下通过jni调用含有定时器的c的so报alarm clock,为什么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-12 12:25 |只看该作者 |倒序浏览
我在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;
}

论坛徽章:
0
2 [报告]
发表于 2006-06-13 08:05 |只看该作者
报“alarm clock" 的意思就是说,程序收到 SIGALRM 而没有进行处理,被强制退出了。
Unix 系统的提示一向惜墨如金……

定时器在第二次执行时报alarm clock
是说第二次执行你的 Java 程序么?

论坛徽章:
0
3 [报告]
发表于 2006-06-13 09:09 |只看该作者
不是第二次执行java程序。这个java程序是个多线程的服务,起来后调一次so进行初始化,通过定时器定期更新缓存的数据,而当程序第二次收到SIGALRM信号时,就报alarm clock,然后程序就退出了。但如果服务是c写的就没有问题:(
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP