Guest User

Untitled

a guest
Dec 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/kthread.h>
  4. #include <linux/delay.h>
  5.  
  6. struct task_struct* ts;
  7.  
  8. static int thread_func(void)
  9. {
  10. while (1)
  11. {
  12. printk("I am a kernel thread!\n");
  13.  
  14. msleep(100);
  15. if (kthread_should_stop())
  16. break;
  17. }
  18.  
  19. return 0;
  20. }
  21.  
  22. static int __init kthread_test_init(void)
  23. {
  24. printk(KERN_INFO "kthread_test kthread_test_init called\n");
  25. ts = kthread_run(thread_func, 0, "kthread");
  26. return 0;
  27. }
  28.  
  29. static void __exit kthread_test_exit(void)
  30. {
  31. printk(KERN_INFO "kthread_test kthread_test_exit called\n");
  32. kthread_stop(ts);
  33. }
  34.  
  35. MODULE_LICENSE("GPL");
  36. module_init(kthread_test_init);
  37. module_exit(kthread_test_exit);
Add Comment
Please, Sign In to add comment