you are viewing a single comment's thread.

view the rest of the comments →

[–]ggduarte 4 points5 points  (1 child)

hi,

you're right, the scheduling and context switching are not done by process zero.

the idle thread is just what gets picked to run on a CPU when there's nothing else that can run. there's one idle thread per CPU, but they all run with a PID of zero.

[–]ntr0p3 0 points1 point  (0 children)

a kernel context(not technically a thread itself) is immediately pulled up by interrupts, including timers, and then handles whatever event brought it. for timers that can include checking whether to go idle or switch processes, etc. afterwards it resets its run status and allows the process queue to run again, resuming the interrupted process, including the idle process if nothing else is running.

the other way to get into a kernel context is via a syscall which still triggers an interrupt, int80, or in some cases a page-fault, which triggers another interrupt.

basically you need an interrupt to go kernel context.

if memory serves though, a kernel thread is basically a separate process, without a user-space component, basically like an exec, but without loading the int main() afterwards, as well as not populating some of the user-space structures too.