Pthread vs. kthread in the Linux kernel v2.6 +

This is a conceptual question.

According to this post, pthread is actually implemented using the clone () system call. Thus, we can conclude that there is a kernel thread (or light process) that supports pthread in user space. The kernel is aware of pthread and can schedule it as a process.

Regarding kthread, according to Robert Love , kthreads are also created using the clone () system call:

clone(CLONE_VM| CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0)

Thus, pthread and kthread use the clone () call. My first question is:

  • Is there a difference between the two types of threads?

To answer my question, I read:

A significant difference between kernel threads and normal processes is that kernel threads do not have an address space (in fact, their mm pointer is NULL).

Is that one difference? I mean, the thread created by pthread_create () shares the address space with the regular process. In contrast, kthread does not have its own address space. It's right?

What else?

+4
source share
1 answer

In contrast, kthread does not have its own address space. It's right?

Yes

the thread created by pthread_create () shares the address space with the regular process.

kernel: how to find all threads from a task_struct process

pthreads: pthread_create() , . pthread, . pthreads . sone() clone(), struct task_struct .

kthreads. , softirqs, .. PAGE_OFFSET, current->mm NULL. kernel_thread() api do_fork() . , init, (, ).

+4

Source: https://habr.com/ru/post/1568457/


All Articles