📄 periodic_handler.c
字号:
/* vim: set ts=4: *//* * Written by Der Herr Hofrat <der.herr@hofr.at> * Copyright Der Herr Hofrat * Released under GPL V2 *//* * call a user-space allplication signal handler under control of an rt-clock * source (periodic rt-thread actually). */#include <stdio.h>#include <rtlinux_signal.h>#define PERIOD 50000 /* period in nanoseconds */void my_handler(int);struct rtlinux_sigaction sig, oldsig;long long rt_count=0;int main(void) { int i=0; sig.sa_handler = my_handler; sig.sa_flags = RTLINUX_SA_PERIODIC; sig.sa_period = PERIOD; if(rtlinux_sigaction(RTLINUX_SIGTIMER0,&sig,&oldsig)) { fprintf(stderr,"errore creating signal handler\n"); return -1; } /* keep the handler active for 10 seconds then reset it and exit * note that the loop takes longer than one second as the loop * time is sleep(1) + loop overhead - you actually can "measure" * the loop overhead by running the same handler for 10 seconds * without the while loop and compare the number of timer-invocations */ while(i++<10){ sleep(1); printf("periodic handler called %lld times\n",rt_count); }// sleep(10); /* instead of the while() loop above */// printf("periodic handler called %lld times\n",rt_count); /* reset the handler befor exiting */ sig.sa_handler = RTLINUX_SIG_IGN; return 0;}void my_handler(int argument){ rt_count++;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -