about kernel_thread!
Quoted 4 lines
You copy the method used in other kernel modules. This involves a semaphore and having the module removing routine send the task a signal. FYI, there is a
wait_for_completion()routine and acomplete_and_exit()routine already defined.
Thank you, my kernel version is 2.4.20. If i use return to terminate the thread, then i can remove the module without errors, but if not, there are still errors, Below is my simple test:
#define __KERNEL__
#define MODULE
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/spinlock.h>
static int child(void *para)
{DECLARE_WAIT_QUEUE_HEAD(child_wait);
int ret;
struct task_struct *tsk = current;daemonize();printk("child's pid =%d\n",tsk->pid);sprintf(tsk->comm,"%s","child");
for (;;) {
static long recalc = 0,limit = 0;
if (time_after(jiffies, recalc + 5*HZ)) {
recalc = jiffies;
printk("%s,pid=%d\n",(char*)para,tsk->pid);
if(limit++ == 5) { // if limit ==5, break, then return
will
//terminate this thread
break;
}
}interruptible_sleep_on_timeout(&child_wait,5*HZ);
}
return 0;
}
int init_module(void)
{
int ret;printk("insmod's pid =%d\n",current->pid);
ret = kernel_thread(child,"child",0); //I create a thread here
return 0;
}
int cleanup_module()
{
return 0;
}