Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 08-04-2009, 11:48 PM   #1
LQ Newbie
Registered: Aug 2009
Posts: 6

Rep: Reputation: 0
difference between kthread_create(), kernel_thread()

I am new to linux kernel programming...

As I heard in linux kernel there is no special handling for threads, all threads will be treaded like processes.

I want to just create threads in kernel mode and try to access global memory by writing a kernel module which will be loaded at run time using insmod.
To have kernel thread, I am getting two functions those are kthread_create()and kernel_thread(). what is the difference between these functions.what are all the resources shared for child process(thread) if we create using above functions.

What is the procedure to create a new process which is independent of parent process.
Old 08-05-2009, 10:52 PM   #2
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,704
Blog Entries: 4

Rep: Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029Reputation: 3029
You're actually mixing two entirely-separate concepts here. (It's okay... the names are confusingly similar!)

"The kernel" lives in the highest-heavens of the computer. It creates the environment in which all user-level processes run. It knows about all processes, and all threads within those processes, and "it gives them life." But in so doing, it does not ... actually cannot ... play by their rules. It does not have access, itself, to the programming facilities that it affords to the user-land threads and processes which run under its benevolent tutelage.

Well ... somewhere along the way, some kernel-programmer thought that this was rather an unfair limitation. It occurred to this person that many of the essential tasks that the kernel performs can most-easily be thought of in terms of "threads," which are dispatched much like ordinary user-land threads but which run entirely in kernel-space. Such threads are, in other words, "entirely part of the kernel ... entirely divine..." but they are also "threads" and therefore capable of doing the things that threads can do. Things like "waiting," and "doing I/O," and so-on.

Typical example? How about "the virtual-memory swapper?" When you set about to describe how it works and what it does, you might find yourself saying that it ... waits for the amount of available memory to drop, then scans through (and locks...) virtual memory segments and performs I/O to move them out to disk ... and signals other threads, and ... you get the idea. All of these things, are things that threads can quite-naturally do.

But what if "'the kernel' can't do what threads do?"

The obvious answer is: "figure out a way for 'the kernel' to be able to support 'threads!'" So... somebody did.

A "kernel thread," then, is a thing which the kernel actually can "dispatch," under most (but not all) of the usual rules and conditions that apply to "threads," but which is nevertheless a fully-privileged part of "the kernel." It is an asynchronous "part of the kernel."

Ponder that for a while . . .

Last edited by sundialsvcs; 08-05-2009 at 10:59 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to find the difference betwwn two file and place the difference to other kittunot4u Linux - General 3 07-19-2010 05:26 AM
what is the difference? mjm70 Mandriva 1 06-14-2005 12:04 PM
What does the call kernel_thread() do. asurya Programming 1 04-20-2005 12:32 PM
What is the difference? pearsonx4 Linux - Newbie 4 10-05-2003 11:34 PM
Design Question (b_end_io kernel_thread buffer_head queueing) devershetty Linux - Newbie 0 08-08-2003 03:45 AM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration