Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2548123
  • 博文数量: 351
  • 博客积分: 76
  • 博客等级: 上将
  • 技术积分: 3555
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-13 21:27
文章分类

全部博文(351)

文章存档

2013年(1)

2012年(4)

2011年(7)

2010年(16)

2009年(34)

2008年(34)

2007年(34)

2006年(68)

2005年(82)

2004年(71)

分类: C/C++

2006-04-21 15:16:07

根据lkd 2.0 Chapter 10. Timers and Time Management一章写的.

运行环境:2..6..14
运行结果:
[17181062.388000] jiffies:298301
[17181062.388000] seconds:1193
[17181065.388000] jiffies:299051
[17181065.388000] seconds:1196

源代码:
/*
 * timer.c - a sample code to timer
 *
 * Author:      Kevin Zhou
 * Date:        2006/4/21
 */

#include
#include
#include
#include

struct timer_list my_timer;

static void print_time(unsigned long data)
{
        printk("jiffies:%lu\n", jiffies);
        printk("seconds:%lu\n", jiffies / HZ);
}

static int __init init(void)
{
        unsigned long delay = 3 * HZ;

        init_timer(&my_timer);

        my_timer.expires = jiffies + delay;
        my_timer.data = 0;
        my_timer.function = print_time;

        print_time(0);
        add_timer(&my_timer);

        return 0;
}

static void __exit fini(void)
{
        return;
}

module_init(init);
module_exit(fini);
                                                                                            
阅读(2702) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~