How to stop Linux kernel threads on rmmod?

后端 未结 3 858
礼貌的吻别
礼貌的吻别 2021-01-30 18:25

I wrote the following code to create a kernel thread:

#include
#include
#include
#include

        
3条回答
  •  离开以前
    2021-01-30 18:56

    I hope the below program resolves your problem.... thumbs up :-)

    `#include
     #include
     #include
     #include
     #include`
    
    struct task_struct *task;
    int data;
    int ret;
    int thread_function(void *data)
    {
      int var;
     var = 10;
         printk(KERN_INFO "IN THREAD FUNCTION");
         while(!kthread_should_stop()){
                 schedule();
                 }
         /*do_exit(1);*/
      return var;
    
    }
    
    static int kernel_init(void)
    {
       data = 20;
       printk(KERN_INFO"--------------------------------------------");
       /*task = kthread_create(&thread_function,(void *)data,"pradeep");*/
       task = kthread_run(&thread_function,(void *)data,"pradeep");
       printk(KERN_INFO"Kernel Thread : %s\n",task->comm);
       return 0;
    }
    
    static void kernel_exit(void)
    {
       kthread_stop(task);
    }
    
    module_init(kernel_init);
    module_exit(kernel_exit);
    MODULE_AUTHOR("SHRQ");
    MODULE_LICENSE("GPL");
    

提交回复
热议问题