Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In what context Kernel Thread runs in Linux?

I am newbie to Linux Kernel.
I know that there are two context
1. Process Context, running in user space or in Kernel Space (for ex: as part of System call)
2. Interrupt Context

In what context Kernel Thread (not related to any User Thread, for ex:flush task) runs ?

Is there any other context other than Process and Interrupt context in Linux Kernel ?

like image 635
user405369 Avatar asked Feb 22 '12 05:02

user405369


People also ask

What is context in Linux kernel?

Context. ● Context: Entity whom the kernel is running code on behalf of. ●

How threads are implemented in Linux kernel?

To the Linux kernel, there is no concept of a thread. Linux implements all threads as standard processes. The Linux kernel does not provide any special scheduling semantics or data structures to represent threads. Instead, a thread is merely a process that shares certain resources with other processes.

Where are kernel threads used?

Many device drivers utilize the services of kernel threads to implement assistant or helper tasks. For example, the khubd kernel thread, which is part of the Linux USB driver core (covered in Chapter 11, "Universal Serial Bus") monitors USB hubs and configures USB devices when they are hot-plugged into the system.

How are kernel threads scheduled?

Kernel threads are scheduled by the OS's scheduling algorithm, and require a "lightweight" context switch to switch between (that is, registers, PC, and SP must be changed, but the memory context remains the same among kernel threads in the same process).


1 Answers

Kernel threads run in process contexts in kernel space. Though there are some kernel threads which handle interrupts too. They are called threaded interrupt handlers. But they still run in process context!

Here is an excellent explanation of the vital difference between the 2 contexts!

Here is one which'll help you gain more understanding!

What context does the scheduler code run in?

As far as I know, process and interrupt are the only 2 contexts.

like image 177
Pavan Manjunath Avatar answered Sep 18 '22 14:09

Pavan Manjunath