unsigned long j = jiffies + 10 * HZ; while(jiffies < j) { // do something. }
struct timer_list { struct list_head entry; //链表头 unsigned long expires; //延迟的时间 struct tvec_base *base; void (*function)(unsigned long); //目标函数,定时时间到达时会被调用 unsigned long data; //目标函数携带的数据 …… };
#include <linux/module.h> #include <linux/init.h> MODULE_LICENSE("GPL"); MODULE_AUTHOR("Jack Chen"); MODULE_DESCRIPTION("Hello World"); MODULE_ALIAS("A simple module"); MODULE_VERSION("V1.0"); struct timer_list timer; static void _function(int data) { printk("<3> time is up data:%d\n",data); } static int timer_init() { init_timer(&timer); timer.expires = jiffies + 5*HZ; timer.function = _function; timer.data = 10; add_timer(&timer); return 0; } static void timer_exit() { del_timer(&timer); } module_init(timer_init); module_exit(timer_exit);
原文地址:http://blog.csdn.net/jack_chen_00/article/details/38948681