2

We know a program is a process (ex: gedit, ssh....etc ).

How about kernel and driver?

are they individual processes?

ex:

A process running kernel code.

B process running driver foo.

1
  • Asking which process is the kernel is like asking which web page is the address bar. And yet, sometimes the address bar is a web page - if it wants to be. If you're using Firefox right now, you can copy/paste this address to see: chrome://browser/content/browser.xhtml Aug 5, 2022 at 18:20

1 Answer 1

5

In Unix-style contexts, some people think of the kernel as “process 0” (coming before process 1, init). However that’s not really accurate, notably because kernels aren’t scheduled in the same way as processes.

Unix-style kernels, in general, only run in response to some event. These events come under two or three major categories:

  1. System calls: when a process calls a system call, the kernel is invoked; this happens in the context of the calling process, and doesn’t involve any other process.

  2. Hardware interrupts: when hardware needs the attention of the main CPU, it issues a hardware interrupt, and the kernel is invoked to handle it. How this is accounted for varies from one operating system to another, but in most cases it the initial interrupt handling doesn’t involve any new process either.

  3. Faults (which could be considered as a form of hardware interrupt): when something goes wrong, and the CPU needs the attention of a “responsible adult”, it issues a fault, and the kernel is invoked to handle it. This happens in the context of the faulting process. This can happen for example when a process accesses unmapped memory; if the process was allowed to do so, the kernel will map the missing memory, and return to the process; if it wasn’t, the kernel will kill the process.

Some kernels do use processes for part of their tasks; for example, Linux uses processes for long-running tasks. This includes device drivers, for long-running tasks, not all uses of device drivers. In most systems, device drivers aren’t separate from the kernel when they’re running; once loaded, they become part of the kernel.

See also How does the Linux kernel knows which process made a system call?

Note that all the above assumes a typical Unix-style large kernel; microkernels take a different approach, and many parts of what is commonly considered the kernel’s responsibility are handled by processes. See the Hurd for example.

4
  • The most extreme example would probably be no-kernel operating systems which (as the name implies) have no kernel at all, only processes. Aug 5, 2022 at 17:48
  • 1
    In the past, there used to be a Wikipedia page: wikipedia.org/wiki/No-kernel but it now redirects to Kernel. I remember reading about no-kernels the first time in the context of the TUNES OS, but the website has fallen into disarray. There's also the Unununium OS, which was originally an experiment to write a modern OS ("modern" meaning object-oriented with automatic, orthogonal persistence, distributed, safe, high-level, etc.) in Python, but was later re-written in assembly. I found a paper about a Zero Kernel OS: web.mit.edu/ha22286/www/papers/MEng20_4.pdf Aug 5, 2022 at 18:54
  • 1
    It looks like almost all traces of Unununium have disappeared, including the website, but some of the source code seems to be preserved: github.com/ekscrypto/Unununium Aug 5, 2022 at 18:55
  • 1
    BTW, in some sense, exokernel OSs also don't have a kernel per se, since the privileged parts of the OS (i.e. the "kernel" part of "exokernel") are actually libraries that are linked into the user processes. Aug 5, 2022 at 18:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .