lkml.org 
[lkml]   [2004]   [Dec]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: about kernel_thread!
> 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)
{
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;
}



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:08    [W:0.210 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site