Operating Systems Panoramic Overview
What is an Operating System?
An Operating System (OS) is the system software that manages computer hardware and software resources. It serves as the bridge between user applications and the underlying hardware.
To understand it through an analogy: if a computer is a hotel, the OS is the management team. It allocates rooms (memory management), queues guests at the reception (process scheduling), manages warehouse inventory (file system), and coordinates communication between departments (inter-process communication). The guests (applications) do not need to interact directly with the plumber (hardware); they simply make requests to the reception (system calls).
Four Core Responsibilities of an OS
| Responsibility | Management Target | Core Problem | Analogy |
|---|---|---|---|
| Process Management | CPU Time | How do multiple programs share a single CPU? | Scheduling staff shifts |
| Memory Management | Physical Memory | How to make each program believe it owns the entire memory? | Allocating hotel rooms |
| File Systems | Disk Storage | How is data systematically stored and retrieved? | Library cataloging |
| I/O Management | Peripheral Devices | How to efficiently interact with keyboards, disks, and network cards? | Hotel logistics coordination |
These four responsibilities form the skeleton of the OS. Subsequent articles will dissect them one by one.
The Kernel: The Core of the OS
The most critical component of an OS is the Kernel, which directly manages hardware resources and runs at the highest privilege level of the CPU.
Two Schools of Kernel Architecture
┌──────────────────────────────────────────────┐
│ Monolithic Kernel │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ Kernel Space │ │
│ │ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ │ │
│ │ │Process │ │Memory │ │File │ │Device │ │ │
│ │ │Mgmt │ │Mgmt │ │System │ │Drivers│ │ │
│ │ └──────┘ └──────┘ └──────┘ └──────┘ │ │
│ │ All functions run in kernel mode. High perf.│ │
│ └──────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────┐ │
│ │ User Space: Applications │ │
│ └──────────────────────────────────────────┘ │
│ Examples: Linux, Unix │
└──────────────────────────────────────────────┘
┌──────────────────────────────────────────────┐
│ Microkernel │
│ │
│ ┌──────────────────────────────────────────┐ │
│ │ Kernel Space (Minimalist) │ │
│ │ ┌──────────┐ ┌──────────┐ │ │
│ │ │ Process │ │ IPC │ │ │
│ │ │ Scheduling│ │ Comm │ │ │
│ │ └──────────┘ └──────────┘ │ │
│ └──────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────┐ │
│ │ User Space │ │
│ │ ┌──────┐ ┌──────┐ ┌──────┐ │ │
│ │ │File │ │Device │ │Network │ │ │
│ │ │System │ │Drivers│ │Protocol│ │ │
│ │ └──────┘ └──────┘ └──────┘ │ │
│ │ Most functions run in user mode. High stab. │ │
│ └──────────────────────────────────────────┘ │
│ Examples: Minix, QNX, HarmonyOS │
└──────────────────────────────────────────────┘
| Feature | Monolithic Kernel | Microkernel |
|---|---|---|
| Kernel Size | Large, contains all functionality | Small, retains only core functions |
| Performance | High (Direct function calls) | Lower (Requires IPC overhead) |
| Stability | A module crash can panic the entire system | Module crashes do not affect the kernel |
| Maintainability | Difficult to maintain | Easy to maintain and extend |
| Representative OS | Linux, Windows (Hybrid) | Minix, QNX, HarmonyOS |
Linux employs a monolithic kernel architecture, but it introduces the flexibility of a microkernel through the Loadable Kernel Module (LKM) mechanism—drivers can be dynamically loaded and unloaded at runtime without recompiling the entire kernel.
User Mode and Kernel Mode
The operating system divides the CPU's execution state into two privilege levels:
- Kernel Mode (Ring 0): Possesses the highest privileges, can execute all CPU instructions, and has unrestricted access to hardware and all memory addresses.
- User Mode (Ring 3): Has restricted privileges, can only execute a safe subset of instructions, and cannot access hardware directly.
User Mode Kernel Mode
┌─────────────┐ ┌─────────────┐
│ Application │ ── System Call ─▶ │ Kernel Code │
│ (Restricted)│ ◀── Return ── │ (Full Auth) │
└─────────────┘ └─────────────┘
Ring 3 Ring 0
│ │
│ Cannot directly access HW │ Can operate on anything
│ Cannot access kernel memory │
▼ ▼
Why Do We Need This Division?
If all programs could directly manipulate hardware, a buggy program could easily corrupt disk data, overwrite other programs' memory, or induce a complete system panic. The segregation of User Mode and Kernel Mode is fundamentally a security isolation mechanism.
Three Paths from User Mode to Kernel Mode
- System Calls: The application actively requests kernel services, such as
read(),write(),fork(). - Exceptions: Triggered by program execution errors, such as divide-by-zero or page faults.
- Interrupts: Triggered by external hardware events, such as keyboard input, network data arrival, or timer expiration.
For an in-depth exploration of User Mode and Kernel Mode, see
02-linux-basics/01-user-kernel-mode.md.
System Calls: The Interface Between User Programs and the Kernel
A system call (syscall) is the only legitimate pathway for an application to request kernel services.
Application C Library Kernel
│ │ │
│ printf() │ │
│ ──────────────▶│ │
│ │ write() syscall │
│ │ ──────────────▶│
│ │ │ Execute write
│ │ Return Result │
│ │ ◀──────────────│
│ printf return │ │
│ ◀──────────────│ │
Common System Call Categories
| Category | Common Calls | Purpose |
|---|---|---|
| Process Control | fork() exec() wait() exit() |
Create / Execute / Wait / Exit process |
| File Operations | open() read() write() close() |
Open / Read / Write / Close files |
| Memory Management | mmap() brk() munmap() |
Map / Allocate / Free memory |
| Network Comm. | socket() bind() listen() accept() |
Create / Bind / Listen / Accept connections |
| Device I/O | ioctl() poll() select() |
Device control / I/O multiplexing |
The Overhead of System Calls
Every system call mandates a context switch from user mode to kernel mode, involving:
- Saving user-mode context (registers, program counters).
- Switching to the kernel stack.
- Executing the kernel code.
- Restoring the user-mode context and returning.
This process is significantly slower than standard function calls (often tens to hundreds of times slower). Therefore, high-performance applications strive to minimize the frequency of system calls. For instance, printf() will initially write data to a user-space buffer and only invoke the write() system call once the buffer is full.
Operating System Knowledge Map
The following map illustrates the core knowledge topology of operating systems, which also dictates the structure of this article series:
Operating Systems
│
┌────────┬───────┼───────┬────────┐
▼ ▼ ▼ ▼ ▼
Linux Process & Memory File I/O
Basics Threads Mgmt Systems Models
│ │ │ │ │
├──User/ ├──Proc/ ├──Paging ├──inode ├──BIO
│ Kernel │ Thread │ /Segs ├──Links ├──NIO
├──File Sys├──Sched ├──Virtual ├──Perms ├──Multiplexing
└──Shell ├──IPC └──Alloc └──ext4 │ (select/
└──Deadlock /Frag │ poll/
└ epoll)
Recommended Learning Path: First master Linux Basics (User/Kernel mode is the foundational concept), then study Process & Threads, proceed to Memory Management, followed by File Systems, and finally I/O Models. This sequence guarantees that each concept is built securely upon prerequisite knowledge.