Linux – When the OS is loaded, does the kernel continue to run as a normal program

linuxlinux-kernel

There is a similar question to mine here: https://stackoverflow.com/questions/43819072/does-the-kernel-stop-running-on-its-own-when-the-os-is-fully-loaded, but it has conflicting answers (so please do not mark this question as a duplicate).


Back to my question. I know that when the computer is powered on, the BIOS starts running, and the BIOS will run the boot loader, and the boot loader will run the kernel.

Now the kernel starts running as a normal program (by "normal program" I mean that the kernel is not just a group of functions that other programs calls, but rather it is also a program that runs on its own). Now the kernel will perform tasks such as:

  • Initializes hardware as well as kernel data structures.
  • Switch to protected mode.
  • Initialize Interrupt Descriptor Table.
  • etc. (this article lists a lot more tasks that the kernel does).

After the kernel finishes these tasks, the OS becomes loaded and the user can start using it.

My question is: now that the OS is loaded, does the kernel continue to run as a normal program, or will it stop running in this way and only run when an interrupt happens?

Best Answer

Any kernel is pretty much the complete opposite of a "normal program". Even though microkernel folks might like the idea of OS services running as processes in the same level as user application, the kernel is always going to have to include some part that's not. If nothing else, there must be some part of the OS that handles scheduling of and switching between the processes, and communication between them.

Particularly, on Linux, the kernel is mapped to the address space of all processes, in the upper part of the address space. In a sense, it's part of each process, in that some processes might be running kernel code while at the same time some other process might be running user-space code.

I wouldn't say the kernel runs as a normal program, but it also doesn't run "only" on interrupts, as user-space code can also call into kernel routines: that's what system calls are. Quotes around "only", since interrupts aren't at all exceptional, some sort of a regular timer tick is quite common to have.

Related Question