최상단

컨텐츠

[RT] 1ms마다 이벤트 발생시키기-

글 정보

Category
컴퓨터 이야기
2006. 3. 6. 16:32

본문


소스코드

[CODE] #include <stdio.h> #include <time.h> #include <signal.h> struct timespec x; struct itimerspec ispec; struct itimerspec ospec; struct sigaction sa; time_t tid; void alrm_handler(int signo, siginfo_t *info, void *context) { clock_gettime(CLOCK_REALTIME,&x); printf("%ld.%09ld \n",x.tv_sec, x.tv_nsec); } int main() { x.tv_sec=0; x.tv_nsec=100000; tid=1; sa.sa_sigaction = alrm_handler; sa.sa_flags = SIGEV_SIGNAL; sigaction(SIGALRM, &sa, NULL); timer_create(CLOCK_REALTIME,NULL,&tid); ispec.it_value.tv_sec = 0; ispec.it_value.tv_nsec = 100000; ispec.it_interval.tv_sec = 0; ispec.it_interval.tv_nsec = 1; timer_settime(tid, TIMER_ABSTIME, &ispec, &ospec); while(1) sleep(1); } [/CODE]


결과

1141630302.569839000
1141630302.570838000
1141630302.571838000
1141630302.572839000
1141630302.573838000
1141630302.574838000
1141630302.575838000
1141630302.576837000
1141630302.577837000
1141630302.578837000
1141630302.579837000
1141630302.580837000
1141630302.581836000

약간의 오차는 발생하지만 1ms마다 이벤트가 발생한것을 알수있다.
그러나-..ㅡㅜ


난 마이크로 단위의 이벤트를 원한다.ㅡㅜ;;;
혹시나 해결방법 아시는분?...

트랙백과 댓글 여닫기

TOP