The difference between kernel threads and processes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.