← Back to context

Comment by loeg

1 day ago

In particular, one of the first questions is "What is the fundamental difference between the kernel and a process?" It rejects "The kernel is a special process with elevated privileges" (which is essentially correct) and prefers "The kernel is not a process—it's the system itself that serves processes," which is sort of wrong? The kernel represents itself as a process (process zero), because kernel threads also need scheduling. And it is privileged, obviously.

> The kernel represents itself as a process (process zero)

This isn't true of any modern operating system. Kernel code isn't confined to a single process or even a limited number of processes. Transitioning to kernel mode doesn't necessitate switching to a dedicated process. Prior to the emergence of CPU speculative execution vulnerabilities, it was common for kernel code to be mapped directly into the virtual address spaces of userspace processes.

PID 0 is merely an implementation detail of the scheduler shared among many Unices. It doesn't function like a normal process, nor is it an accurate representation of how the large part of the kernel operates.

  • This article (and comment you’re replying to) is about Linux, which does represent its own threads as pid 0. Yes, there are concepts that aren’t threads. Nevertheless, in a very real sense the kernel is a special process zero.

    • Again, no it's not. Most kernel code doesn't run as PID 0. What you're talking about is the idle task, a very small part of the kernel.

      I also did have Linux in mind when writing my comment, but this is basic to how any major general purpose operating system works. Besides, I can't possibly exclude Linux when I say "any modern operating system."

      1 reply →

Also in Chapter 6 1. What is the relationship between CPU state and kernel state?, it prefers "CPU is stateless; kernel manages state" instead of "They share state equally". I also wouldn't divide it down as "equally" as the kernel manages much more state, but CPUs have registers and cache lines so I wouldn't say they're stateless either.