|
发表于 2006-1-4 10:17:38
|
显示全部楼层
[code:1]
#include <stdio.h>
#include <signal.h>
#include <time.h>
//采集数据
void collect_data(int signum)
{
printf("collect_data\n");
}
//处理数据
void handle_data()
{
while(1)
sleep(1);
}
main()
{
timer_t tm_id;
struct sigevent evp;
struct itimerspec value;
struct itimerspec ovalue;
struct sigaction sigact;
int ret;
signal(SIGRTMAX,collect_data);
evp.sigev_notify = SIGEV_SIGNAL;
evp.sigev_signo = SIGRTMAX;
evp.sigev_value.sival_ptr = &tm_id;
ret = timer_create(CLOCK_REALTIME, &evp, &tm_id);
if(ret != 0)
return;
value.it_value.tv_sec = 1;
value.it_interval.tv_sec = 1;
value.it_value.tv_nsec = 0;
value.it_interval.tv_nsec = 0;
ret = timer_settime(tm_id,0,&value,&ovalue);
if(ret == 0)
handle_data();
timer_delete(tm_id);
}
[/code:1] |
|