- 论坛徽章:
- 0
|
我写了一个线程创建和退出的内核小程序,但是内核模块无法正常卸载,造成死机。求大神帮我看一下问题出在哪里?- #include <linux/sched.h>
- #include <linux/kthread.h>
- #include <linux/module.h>
- #include <linux/err.h>
- #include <linux/wait.h>
- #include <linux/delay.h>
- static struct task_struct *test_task;
- MODULE_LICENSE("GPL");
- static int test_thread(void *data)
- {
- while(1){
- if (kthread_should_stop())
- {
- printk("The program is over!\n");
- return -1;
- }
- printk("This is my first kernal therad!\n");
- mdelay(500);
- }
- return 0;
- }
- static int __init test_init_module(void)
- {
- int err;
- printk("Entering the kthread module!\n");
- test_task = kthread_create(test_thread, NULL, "test_task");
- if(IS_ERR(test_task)){
- printk("Unable to start kernel thread./n");
- err = PTR_ERR(test_task);
- test_task = NULL;
- return err;
- }
- wake_up_process(test_task);
- return 0;
- }
- static void __exit test_cleanup_module(void)
- {
- kthread_stop(test_task);
- printk("Leaving the kthread module!\n");
- }
- module_init(test_init_module);
- module_exit(test_cleanup_module);
复制代码 |
|