From: Fawad Lateef <fawadlateef@gmail.com>
To: Yan Zheng <yanzheng@21cn.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Question about the usage of kernel_thread
Date: Sat, 5 Nov 2005 16:31:37 +0500 [thread overview]
Message-ID: <1e62d1370511050331l7e71d15i7c3cdc0d153e31a6@mail.gmail.com> (raw)
In-Reply-To: <436C6FF7.4060206@21cn.com>
On 11/5/05, Yan Zheng <yanzheng@21cn.com> wrote:
> Hi.
>
> In LKD2, Robert say:
> Linux delegates several tasks to kernel threads, most notably the pdflush task and the ksoftirqd task. These threads are created on system boot by other kernel threads. Indeed, a kernel thread can be created only by another kernel thread.
>
>
> But I found that kernel_thread(...) are used wildly like:
>
> #include <linux/kernel.h>
> #include <linux/module.h>
>
> static int noop(void *dummy)
> {
> printk("current->mm = %p\n", current->mm);
> return 0;
> }
>
> static int test_init(void)
> {
> kernel_thread(noop, NULL, CLONE_KERNEL | SIGCHLD);
> return 0;
> }
>
> static void test_exit(void) {}
> module_init(test_init);
> module_exit(test_exit);
>
>
> In this circumstances, The thread created by kernel_thread has "current->mm != NULL".
>
> My question is:
> The new thread is truely kernel thread ? The usage of kernel_thread(...) like this is correct?
>
AFAIK the thread created like above is a true kernel thread but in
general practice what I saw and used that by creating thread from
init_module, the thread first call daemonize which actually drops the
mm related to thread and then through reparent_to_init it makes init
as a parent of the thread/process newly created. So after daemonize
call current->mm becomes NULL and when the scheduling is going to be
done the previous_process->mm will be used as the current->mm and
creating thread like above is correct.
--
Fawad Lateef
next prev parent reply other threads:[~2005-11-05 11:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-05 8:40 Yan Zheng
2005-11-05 11:31 ` Fawad Lateef [this message]
2005-11-05 12:20 ` Yan Zheng
2005-11-05 12:54 ` Fawad Lateef
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=1e62d1370511050331l7e71d15i7c3cdc0d153e31a6@mail.gmail.com \
--to=fawadlateef@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=yanzheng@21cn.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
all inboxes | Powered by JetHome®