Chinaunix首页 | 论坛 | 博客
  • 博客访问: 841019
  • 博文数量: 150
  • 博客积分: 5123
  • 博客等级: 大校
  • 技术积分: 1478
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:03
文章分类

全部博文(150)

文章存档

2011年(2)

2010年(139)

2009年(9)

分类: C/C++

2010-10-02 21:19:50



#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <event.h>

void signal_cb(int fd, short event, void *arg)
{
    fprintf(stderr, "Hello, signal\n");
    exit(0);
}
int main(int argc, char *argv[])
{
    struct event ev;
    struct itimerval itv;

    event_init();
    signal_set(&ev, SIGALRM, signal_cb, &ev);
    signal_add(&ev, NULL);
    memset(&itv, 0, sizeof(itv));
    itv.it_value.tv_sec = 0;
    itv.it_value.tv_usec = 50000L;
    if (setitimer(ITIMER_REAL, &itv, NULL) == -1)
        goto skip_simplesignal;
    event_dispatch();
skip_simplesignal:
    signal_del(&ev);
    return 0;
}


阅读(835) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~