Kernel

In a nut or seed, the kernel is the innermost part, surrounded by a shell. In an operating system, the kernel is the lowest level of software, surrounded by several other layers, including an interface called a “shell.”1 The kernel sits between the user interface and the hardware and manages many tasks that happen within the computer.

The terminal wakes up the shell and lets you communicate with the kernel via the shell. In Windows, you might access the shell via Powershell, whereas on a Mac/Linux you may use a zsh or bash shell (the sh in these words means shell!).

There are different kinds of kernels, but most modern OSs (such as Windows, Mac OS X, and Linux) use monolithic kernels.

Monolithic kernels provide general services such as:

  • Interfacing (two services)
    • System call API
    • Device driver API
  • File system and virtual file system
  • Process and task management
  • Scheduling
  • Memory management and virtual memory
Image reference:
6.033 Computer System Engineering, MIT OCW, Spring 2018

Interfaces

Most modern kernels, like those used in Windows or MacOS, implement a level of hardware abstraction, or a set of basic operations that are universal to all devices of a certain type. The hardware abstraction provides an interface to the hardware and eliminates complexity by hiding the specific hardware details. In order to provide this set of abstractions, the kernel needs to know how to use the hardware. Since many combinations of hardware are possible, the kernel relies on device drivers to use the hardware directly.

The abstraction that the kernel provides for application developers is called the system call API. It allows software developers to easily build applications that are capable of running on different types of hardware. Each kernel provides its own APIs, which is why a Mac program doesn’t work on a Windows computer, and vice versa.

File System

From an OS viewpoint, a file system is a piece of software that keeps track of data on a drive. The kernel provides a set of system calls for dealing with the file system. Operations such as opening, closing, reading, writing, and deleting files are supported using system calls.

Since each file system has its own format, sharing files on external media can be difficult. To alleviate this problem, developers came up with the virtual file system (VFS). The VFS is similar to a driver API, in that it allows different file systems to “plug-in” to the kernel, and it tells the kernel how to access disks in a certain format. The VFS also offers a consistent interface to those files no matter what format they’re in.

Process Management

A process (sometimes called a task) is an instance of a running program. Programs are stored on the disk as files containing information about the program, as well as the initial data and executable code. When you run a program, the kernel:

  1. finds the program in the file system,
  2. loads it into memory (along with its context, the set of data that the program uses as it runs), and
  3. manages the process (provides system calls for dealing with processes, including actions such as running or quitting a program.)

Scheduling

The kernel is to run programs and provide access to the machine’s hardware. Because there are many programs and resources are limited, the kernel also decides when and how long a program should run. This process is known as scheduling.2

A processor core can only run a single process at any given point in time. That means a dual-core processor can only run two processes simultaneously. Scheduling allows users to have more processes open, providing an illusion of multitasking by rapidly switching the processor core(s) between tasks. The kernel handles scheduling automatically, but some system calls imply that the kernel will switch to a different process, such as calls that quit a running process or wait for user input.

Memory management

The kernel uses memory management to give each process its own region of memory to store code and data. The kernel keeps track of which region belongs to each process, and restricts that process to accessing its own memory. This makes the system a lot safer and more stable, since a process’s memory is protected from other (possibly malicious) processes.

The memory management system often also provides virtual memory. On a system with only 2 gigabytes of main memory, the kernel can use a part of the hard drive (known as swap space or a page file) as extra memory. A system with 2 gigabytes of main memory and sufficient swap space can utilize the full 4 gigabytes of address space (however, the swap space is much slower). The memory management system keeps track of which memory is in use by a process, and automatically “swaps” it in and out of main memory as it is needed.


  1. Allen Downey, Think OS ↩︎
  2. Reference: Garg, R., and G. Verma. Operating Systems : An Introduction, Mercury Learning & Information, 2017. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/ncsu/detail.action?docID=5389038.
    Created from ncsu on 2024-07-18 20:59:25. ↩︎