免费注册 查看新帖 |

Chinaunix

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

Linux内核定时器 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-06-06 15:31 |只看该作者 |倒序浏览
Linux内核定时器的应用
  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. #include
  8. MODULE_LICENSE("GPL");
  9. static DECLARE_WAIT_QUEUE_HEAD(wq);
  10. static int flag = 0;
  11. struct timer_list my_timer;
  12. void timer_test(unsigned long data)
  13. {
  14.         printk("this is a test\n");
  15.         flag = 1;
  16.         wake_up_interruptible(&wq);
  17. }
  18. static int __init hello_init(void)
  19. {
  20.         init_timer(&my_timer);
  21.         my_timer.expires = jiffies + 5000;
  22.         my_timer.data = 0;
  23.         my_timer.function = timer_test;
  24.         add_timer(&my_timer);
  25.         wait_event_interruptible(wq, flag != 0);
  26.         flag = 0;
  27.         return 0;
  28. }
  29. static void __exit hello_exit(void)
  30. {
  31.         del_timer(&my_timer);
  32.         printk(KERN_ALERT "Goodbye\n");
  33. }
  34. module_init(hello_init);
  35. module_exit(hello_exit);
复制代码

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36290/showart_315944.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP