[cs631apue] kernel vs process

Jan Schaumann jschauma at stevens.edu
Tue Dec 6 12:08:05 EST 2022


Hello,

On my way home last night I was thinking about how to
better explain the difference between when a process
runs on the CPU versus what the kernel does.  One way
to get better clarity here is to understand that the
kernel itself is not process like any others:

When the kernel boots, it is running on the CPU in
kernel space (ring 0).  It bootstraps the system, and
as part of initiates the scheduler.  It then doesn't
really do much of anything until a suitable interrupt
causes kernel code to be executed (e.g., hardware
interrupt for I/O, preemption by the scheduler).

When a user process executes (e.g., explicit creation
of init(8) by the kernel or any of its child
processes), that will run in user space (ring 3).
When it makes system calls, the CPU switches to kernel
mode and the syscall completes.  At this point, the
kernel "has the CPU", so to speak. The user process
may be preempted (i.e., by an interrupt as above) or
terminate, and control returns to the kernel.

That is, rather than thinking of the kernel as a
process that runs and needs to be preempted to let a
user process run, think of the kernel as the larger
program that runs _in between user processes_, as the
kernel simply isn't a process itself and doesn't
behave like one.

Perhaps this chapter of O'Reilly's "Understanding the
Linux Kernel" can also help you clarify your
understanding:
https://www.oreilly.com/library/view/understanding-the-linux/0596002130/ch01s06.html

Hope that helps,
-Jan


More information about the cs631apue mailing list