From: "Zhenyu Wu" <y030729@njupt.edu.cn>
To: linux-os@analogic.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: about kernel_thread!
Date: Mon, 13 Dec 2004 21:36:09 +0800 [thread overview]
Message-ID: <302944969.22286@njupt.edu.cn> (raw)
> 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;
}
next reply other threads:[~2004-12-13 12:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-13 13:36 Zhenyu Wu [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-12-13 13:52 about kernel_thread! Zhenyu Wu
2004-12-13 13:25 ` linux-os
2004-12-13 13:12 Zhenyu Wu
2004-12-13 12:31 ` linux-os
2004-12-13 12:44 ` Juergen Quade
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=302944969.22286@njupt.edu.cn \
--to=y030729@njupt.edu.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).