dep2.c 557 B

123456789101112131415161718192021222324252627282930313233
  1. #include <linux/delay.h> /* usleep_range */
  2. #include <linux/kernel.h>
  3. #include <linux/kthread.h>
  4. #include <linux/module.h>
  5. extern int lkmc_dep;
  6. static struct task_struct *kthread;
  7. static int work_func(void *data)
  8. {
  9. while (!kthread_should_stop()) {
  10. usleep_range(1000000, 1000001);
  11. lkmc_dep++;
  12. }
  13. return 0;
  14. }
  15. static int myinit(void)
  16. {
  17. kthread = kthread_create(work_func, NULL, "mykthread");
  18. wake_up_process(kthread);
  19. return 0;
  20. }
  21. static void myexit(void)
  22. {
  23. kthread_stop(kthread);
  24. }
  25. module_init(myinit)
  26. module_exit(myexit)
  27. MODULE_LICENSE("GPL");