[Stick] Linux kernel Timer

Source: Internet
Author: User

# Include <Linux/module. h>

# Include <Linux/init. h>

# Include <Linux/sched. h>

# Include <Linux/Timer. h>

 

Struct timer_list my_timer;

 

Void func (unsigned long data)

{

Printk ("time out! \ N data: % lD, PID: % LD \ n ", data, current-> PID );

Mod_timer (& my_timer, jiffies + 3 * Hz );//Modify the timer time2Seconds

}

 

Static int _ init my_timer_init (void)

{

Init_timer (& my_timer );//Initialize Timer

My_timer.expires = jiffies + 5 * Hz ;//Set the timer time5Seconds

My_timer.function = func ;//Timer time to the function to be executed

My_timer.data = (unsigned long) 99; // funcFunction Parameters

Add_timer (& my_timer );//Register a timer

Printk ("this is my timer PID: % LD \ n", current-> PID );

 

Return 0;

}

 

Static void _ exit my_timer_exit (void)

{

Del_timer (& my_timer );//Logout Timer

Printk ("good bye \ n ");

}

 

Module_license ("GPL ");

Module_author ("Mike Chen ");

Module_init (my_timer_init );

Module_exit (my_timer_exit );

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.