根据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);
阅读(2752) | 评论(0) | 转发(0) |