http://blog.csdn.net/tigerjibo/article/details/8299686
Preface:
from the kernel point of view, it does not have the concept of threading . Linux implements all threads as processes. The kernel does not prepare special scheduling algorithms or define special data structures to represent threads. Instead, a thread is only considered a process that shares certain resources with other processes. each thread has its own unique task_struct, so in the kernel it looks like a normal process (just that the process and some other processes share some resources, such as address space)
one. Kernel Threads
1. The kernel often needs to perform some operations in the background. This task can be done through kernel threads (kernel thread).
2. The difference between a kernel thread and a normal process is that the kernel thread does not have a separate address space (the actual mm pointer is set to NULL)
3. Kernel threads run only in kernel space and never switch to user space. Kernel processes, like normal processes, can be scheduled or preempted
4. Kernel threads can also be created only by other kernel threads. The method for creating a new kernel thread in an existing kernel thread is as follows:
Intkernel_thread (int (*FN) (void *), void *arg, unsigned long flags)
The new task is also created by passing a specific flags parameter to the normal clone () system call. When the above function returns, the parent thread exits and returns a pointer to the child thread task_struct. The child thread starts running the function that the FN points to, and Arg is the parameter that is required at run time.
5. In general, the kernel thread will always execute the function it created at the time of creation (unless the system restarts). The change function is usually made up of a loop, and when needed, the kernel thread is awakened and executed, and the current task is completed, and it will hibernate itself.
The difference between kernel threads and processes