lkm内核编程实例 - timer

2783阅读 0评论2006-04-21 flyboy
分类:C/C++

根据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);
                                                                                            
上一篇:每天给爱10分钟
下一篇:男人这辈子挺难的