lkml.org 
[lkml]   [2004]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: distinguish kernel thread / user task
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
-
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.051 / U:0.664 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site