Re: about kernel_thread!

From: Zhenyu Wu
Date: Mon Dec 13 2004 - 07:47:24 EST

> 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 a
> complete_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)
int ret;
struct task_struct *tsk = current;
printk("child's pid =%d\n",tsk->pid);
for (;;) {
static long recalc = 0,limit = 0;
if (time_after(jiffies, recalc + 5*HZ)) {
recalc = jiffies;
if(limit++ == 5) { // if limit ==5, break, then return
//terminate this thread
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;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at