Definition
Kernel
The kernel is the core component of an operating system that acts as the primary interface between a computer’s hardware and its processes. It manages system resources (CPU, memory, I/O devices) and provides essential services for user applications.
The kernel typically resides in a protected area of memory called kernel space, preventing user applications from interfering with its operation or accessing hardware directly.
Functions
- Resource Management: Allocating CPU time (scheduling) and memory to active processes.
- Hardware Abstraction: Providing a consistent interface for diverse hardware devices through drivers.
- Process Management: Creating, executing, and terminating processes (see Process States).
- Security and Isolation: Enforcing permissions and isolating process memory to prevent system crashes or data theft.
Implementation Models
There are three primary ways a kernel can be structured in relation to user processes:
Non-Process Kernel
The kernel is a separate entity that exists outside any process.
- Context: When a process makes a system call or an interrupt occurs, the processor switches to kernel mode, but the execution is considered to be “outside” all processes.
- Memory: The kernel has its own dedicated memory and stack.
Execution within User Processes
Most OS routines execute within the context of a user process.
- Shared Space: The OS code and data are mapped into a shared address space of every process image.
- Context: A process does not switch to a “kernel process” but simply switches from user mode to kernel mode to execute OS code using a dedicated kernel stack.
- Switching: A true process switch only occurs when the scheduler decides to run a different process.
Process-Based Operating System
OS services are implemented as a collection of system processes.
- Structure: Only a tiny core (the microkernel) manages process switching and IPC. All other services (file system, drivers) are processes that communicate via messages.
- Advantage: High modularity and the ability to distribute services across multiple processors or machines.