From: Brian Gerst <bgerst@didntduck.org>
To: Sylvain <autofr@gmail.com>
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: distinguish kernel thread / user task
Date: Fri, 03 Dec 2004 14:24:27 -0500 [thread overview]
Message-ID: <41B0BD6B.2010809@didntduck.org> (raw)
In-Reply-To: <64b1faec041203091654251b18@mail.gmail.com>
Sylvain wrote:
> Hi all,
>
> I have little question while doing some kernel implementation.
> How can I distinguish whether a task_struct is actually kernel thread
> or mere user task?
>
> My idea was to look at task_struct "mm" field to discriminate them,
> but that was wrong...
>
> Thanks,
>
> Sylvain
To the scheduler, a thread is a thread. It doesn't care if it's a
kernel thread or not. The difference is execution context, which is
cpu-dependant. For example, on x86 the difference is in the code
segment the task runs in. Kernel threads run in KERNEL_CS (ring 0), and
user threads run USER_CS (or any other ring 3 code segment, or vm86 mode
set in eflags). Other cpus might have a flag in the status register.
What are you trying to do that you need to know whether a thread is
kernel or user? I suppose if there were a compelling enough reason, a
kernel/user flag could be added to the task struct, set in do_fork() for
kernel threads, and cleared by execve().
--
Brian Gerst
next prev parent reply other threads:[~2004-12-03 19:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-03 17:16 distinguish kernel thread / user task Sylvain
2004-12-03 19:24 ` Brian Gerst [this message]
2004-12-03 20:15 ` Sylvain
2004-12-03 20:50 ` Brian Gerst
2004-12-03 21:32 ` Sylvain
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=41B0BD6B.2010809@didntduck.org \
--to=bgerst@didntduck.org \
--cc=autofr@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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