Advertisement
Guest User

Untitled

a guest
May 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/timer.h>
  3.  
  4. static struct timer_list timer;
  5. static __u8 liczba_max_aktywacji = 10;
  6. static __u8 obecna_aktywacja = 0;
  7. static __u8 opoznienie = 2;
  8.  
  9. static void timer_handler(unsigned long int data) {
  10.  
  11. pr_info("Licznik %lu obecna aktywacja %d \n", data, ++obecna_aktywacja);
  12.  
  13. if (obecna_aktywacja < liczba_max_aktywacji) {
  14. timer.expires = jiffies + opoznienie*HZ;
  15. add_timer(&timer);
  16. }
  17. }
  18.  
  19. static int __init module_constructor(void) {
  20.  
  21. init_timer(&timer);
  22. timer.data = 1;
  23. timer.function = timer_handler;
  24. timer.expires = jiffies + opoznienie*HZ;
  25. add_timer(&timer);
  26. return 0;
  27. }
  28.  
  29. static void __exit module_destructor(void) {
  30.  
  31. if (del_timer_sync(&timer)) {
  32. pr_notice("Timer was not active\n");
  33. }
  34. }
  35.  
  36. module_init(module_constructor);
  37. module_exit(module_destructor);
  38.  
  39. MODULE_LICENSE("GPL");
  40. MODULE_AUTHOR("Piotr Zieba, Karol Wrona");
  41. MODULE_VERSION("1.0");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement