Operating system basics
Explore the role of the operating system kernel, system calls, process scheduling, virtual memory paging, file systems, device drivers, and security.
Learning Objectives
- ✓Define the fundamental purpose of an operating system and differentiate between user mode and kernel mode.
- ✓Trace the lifecycle of a process across Ready, Running, and Blocked states in preemptive multitasking.
- ✓Explain virtual memory, paging, and page fault handling mechanisms.
- ✓Contrast monolithic kernels, microkernels, and major operating system families across platforms.
Prerequisites
- →Hardware and CPU architecture fundamentals
- →Basic concepts of memory and persistent storage
1. The Operating System as Resource Manager#
An operating system (OS) is the fundamental system software that manages a computer's hardware resources and provides common services for application programs. Without an OS, every software application would need to contain custom machine code to directly command disk spindles, network cards, graphics adapters, and physical memory controllers.
The OS fulfills two complementary core missions:
- Hardware Abstraction Layer (HAL): It presents applications with clean, standardized, device-independent interfaces (such as "read 100 bytes from file
document.txt"), hiding the messy physical quirks of different manufacturers' hardware. - Resource Manager: It arbitrates conflicting requests for processor cycles, memory space, network bandwidth, and input/output devices, ensuring system stability, efficiency, and security.
+-------------------------------------------------------------+
| USER APPLICATIONS |
| (Web Browser, Text Editor, Media Player) |
+------------------------------+------------------------------+
| System Calls (APIs)
+------------------------------v------------------------------+
| OPERATING SYSTEM |
| +-------------------------------------------------------+ |
| | KERNEL (Core Privileged Engine) | |
| | [Process Scheduler] [Memory Manager / Virtual Mem] | |
| | [File System Driver] [I/O & Device Driver Subsystem] | |
| +-------------------------------------------------------+ |
+------------------------------+------------------------------+
| Hardware Instructions
+------------------------------v------------------------------+
| PHYSICAL HARDWARE |
| (CPU, RAM, NVMe SSD, GPU, Network Card) |
+-------------------------------------------------------------+
Dual-Mode Operation: User Mode versus Kernel Mode
To prevent errant or malicious programs from crashing the entire system, modern CPUs feature hardware-enforced protection rings:
- User Mode (Ring 3): Normal applications execute here with restricted privileges. They cannot directly execute hardware instructions, modify page tables, or access physical peripherals.
- Kernel Mode (Ring 0 / Supervisor): The core operating system kernel executes with unrestricted access to all CPU instructions and physical memory addresses.
When an application needs to read a file from disk or send a network packet, it triggers a system call (such as read(), write(), or fork()), which executes a software trap that securely switches the CPU into kernel mode to perform the action on the application's behalf.
2. Process and Thread Management#
A program is a passive collection of instructions stored on disk (an executable file). A process is an active program in execution, encompassing its program counter, registers, memory stack, and open file handles.
The Five-State Process Lifecycle Model
+------------+
| NEW |
+-----+------+
| Admitted
v
+------------+ Scheduler Dispatch +------------+
| READY +------------------------------>| RUNNING |
| |<------------------------------+ |
+-----+------+ Time Slice Interrupt +-----+------+
^ |
| I/O or Event Finished | I/O or Event Wait
| v
| +------------+
+--------------------------------------+ BLOCKED |
| (WAITING) |
+------------+
- New: The process is initialized and memory structures are allocated.
- Ready: The process is loaded in RAM and waiting in the CPU scheduler's queue for execution time.
- Running: Instructions are currently being decoded and executed by a CPU core.
- Blocked (Waiting): The process is paused waiting for an external event (such as a disk read completion or user keyboard input).
- Terminated: The process finishes execution and the OS reclaims its allocated memory.
Preemptive Multitasking
Modern operating systems employ preemptive scheduling. A hardware timer periodically interrupts the CPU (typically every 1 to 10 milliseconds). The OS kernel pauses the currently executing process, saves its exact register state in a Process Control Block (PCB) (a context switch), and allocates the CPU to another ready process. This rapid switching creates the smooth illusion of simultaneous execution even on a single CPU core.
3. Memory Management and Virtual Memory#
Early operating systems loaded programs into fixed physical addresses in RAM. If a program contained a bug that overwrote memory outside its boundaries, other programs or the OS itself would immediately crash.
Virtual Memory and Paging
Modern operating systems solve this with virtual memory:
- Each process is provided with an independent, private virtual address space (e.g., $0\text{x}00000000$ to $0\text{x}7\text{FFFFFFFFFFF}$ in 64-bit systems).
- The operating system and the CPU's Memory Management Unit (MMU) divide memory into fixed-sized blocks called pages (typically 4 kilobytes in size).
- The MMU maintains a Page Table that maps virtual pages to physical frames in physical RAM.
Virtual Address Space Physical RAM
(Process View) (Hardware View)
+-----------------+ +-----------------+
| Page 0 (Code) |---------------->| Frame 4 (RAM) |
+-----------------+ +-----------------+
| Page 1 (Data) |---+ | Frame 5 (Other) |
+-----------------+ | +-----------------+
| Page 2 (Heap) |---|------------>| Frame 2 (RAM) |
+-----------------+ | +-----------------+
| Page 3 (Stack) | +------------>| Frame 7 (RAM) |
+-----------------+ +-----------------+
(Disk Swap / Pagefile)
[ Inactive Page 4 ]
Page Faults and Swapping
If total memory demand exceeds physical RAM:
- The OS temporarily moves inactive memory pages from physical RAM onto secondary storage (the swap space or pagefile).
- When the application attempts to read from a paged-out virtual address, the MMU triggers a Page Fault exception.
- The kernel pauses the process, reads the missing page back from disk into a free RAM frame, updates the page table, and resumes execution seamlessly.
4. File Systems: Persistent Data Organization#
The file system provides a structured hierarchical namespace mapping human-readable directories and filenames to physical disk blocks:
| File System | Primary Platforms | Key Architectural Features | | :--- | :--- | :--- | | NTFS | Microsoft Windows | Master File Table (MFT), journaling for crash recovery, ACL security permissions, file compression | | ext4 | Linux / Android | Extents-based allocation, journal checksumming, rapid multi-terabyte volume scaling | | APFS | Apple macOS / iOS | Copy-on-Write (CoW), 64-bit inode architecture, instantaneous directory snapshotting and cloning | | FAT32 / exFAT | Cross-platform USB drives | Universal compatibility across devices; lacks journaling and granular file security permissions |
Journaling
Modern file systems use journaling: before writing data to disk, the OS logs the intended operation in a dedicated circular log (journal). If a power outage occurs midway through a write, the OS replays or rolls back the journal during the next boot, eliminating file system corruption.
5. Major Operating System Architectures Compared#
| OS Family | Primary Use Case | Kernel Philosophy | License / Ecosystem | | :--- | :--- | :--- | :--- | | Microsoft Windows | Desktop workstations, enterprise networks, PC gaming | Hybrid kernel; proprietary hardware abstraction layer (HAL) | Commercial, closed-source | | Linux (Distros: Ubuntu, Fedora, Debian) | Web servers, cloud infrastructure, supercomputers, Android devices | Monolithic kernel; modular loadable kernel modules | Free and Open Source (GPL) | | Apple macOS / iOS | Creative workstations, mobile consumer electronics | XNU hybrid kernel based on Mach microkernel and FreeBSD | Commercial / proprietary | | Real-Time OS (RTOS: FreeRTOS, VxWorks) | Medical devices, automotive engine control, aerospace avionics | Deterministic, ultra-low latency microkernel | Embedded, safety-critical |
6. Common Pitfalls and Diagnostic Traps#
- Trap 1: Confusing an Operating System with its Graphical User Interface (GUI). A desktop shell (like Windows Explorer or GNOME) is merely an application program presenting visual windows and icons. The OS kernel operates identically in command-line environments without any graphical shell.
- Trap 2: Believing More RAM Makes CPU Clock Speed Faster. Adding RAM allows the OS to keep more programs and data in memory simultaneously without swapping to disk, eliminating page-fault stalls. It does not alter the CPU's internal clock frequency.
- Trap 3: Assuming User Mode Software Can Directly Access Hardware. Applications must never talk directly to sound cards, graphic buffers, or disk sectors; all hardware access is mediated through system calls to maintain system integrity.
- Trap 4: Conflating Multitasking with True Parallel Execution. On a single CPU core, multitasking is rapid time-slicing (concurrency). True simultaneous execution (parallelism) requires multiple physical processor cores.
Key points
- The operating system acts as an intermediary resource manager and hardware abstraction layer for software.
- The kernel executes in privileged kernel mode; applications execute in unprivileged user mode using system calls.
- Preemptive process scheduling guarantees fair CPU time distribution and responsive multitasking.
- Virtual memory provides each process with an isolated, contiguous address space backed by physical RAM and swap space.
References & Further Reading
- Silberschatz, A., Galvin, P. B., and Gagne, G. Operating System Concepts. 10th edition. Wiley.
- Tanenbaum, A. S., and Bos, H. Modern Operating Systems. 4th edition. Pearson.
- Arpaci-Dusseau, R. H., and Arpaci-Dusseau, A. C. Operating Systems: Three Easy Pieces (OSTEP)