i am just started coding of device driver and new to threading, went through many documents for getting an idea about threads. i still have some doubts.
- what is a kernel thread ?.
- how it differs from user thread ?.
- what is the relationship between the two threads ?.
- how can i implement kernel threads ?.
- where can i see the output of the implementation?.
Can anyone help me ?. thanks.
A kernel thread is a way to implement background tasks inside the kernel. The task can be busy handling asynchronous events or sleep-waiting for an event to occur. Kernel threads are similar to user processes, except that they live in kernel space and have access to kernel functions and data structures.
Difference between User-Level & Kernel-Level ThreadUser-level threads are faster to create and manage. Kernel-level threads are slower to create and manage. Implementation is by a thread library at the user level. Operating system supports creation of Kernel threads.
These are the three kinds of threads. The kernel maintains thread- and process-related information in two types of structures. A process is always created with one thread, called the initial thread. The initial thread provides compatibility with previous single-threaded processes.
task_struct
with no userspace components.kthreadd
kernel thread instead of the init
process) and is created by a kernel-only API instead of sequences of clone
from fork/exec
system calls.kthreadd
as a parent. Apart from that, kernel threads enjoy the same "independence" one from another as userspace processes.kthread_run
function/macro from the kthread.h header You will most probably have to write a kernel module in order to call this function, so you should take a look a the Linux Device Drivers printk
calls), you can see this output in the kernel log using the dmesg
command.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With