Components of OS & System Calls
Essential interfaces and architecture of modern operating systems.
The OS Architecture
Modern operating systems are divided into two primary logical spaces. This separation ensures that normal user applications cannot accidentally (or maliciously) interfere with the critical hardware management tasks.
User Space
The space where user applications (like Chrome, VS Code, or Python) reside. It provides a convenient environment for users without direct access to hardware.
- No direct hardware access
- Convenient user environment
Kernel Space
The "Heart" of the OS. It has full, privileged access to all hardware components and resources (CPU, RAM, Storage).
- Full hardware access
- Resource prioritization
High-Level Interaction Flow
Modes of Operation
The CPU switches between modes based on the task it is performing. This switching is the foundation of system security and stability.
User Mode
When the CPU is in User Mode, it executes code belonging to user applications. It cannot access memory outside its allocated space or talk to hardware.
Kernel Mode
To perform kernel-level work (like saving a file), the CPU must Switch itself into Kernel Mode.
Mode Switching Overhead
Switching between modes takes time and computational resources. This is known as Overhead. Modern OS design aims to minimize frequent switching for better performance.
Software Interrupt
Occurs to stop a running task so the CPU can perform another, higher-priority task. Can also occur if hardware fails.
Step 1: User Command
User types mkdir documents and presses Enter.
Step 2: The Switch (Trap)
CPU initiates a Trap, switching from User Mode to Kernel Mode.
Step 3: Execution
Kernel's File Management component interacts with Hardware to create the folder.
Interacting with the System
Users interact with the system through two main interfaces. Regardless of the interface, the underlying goal is to translate user intent into kernel commands.
GUI
Graphical User Interface. Interaction via icons, menus, and mouse clicks.
CLI
Command Line Interface. Interaction via typed text commands.
Under the Hood:
"To create a folder, you can right-click (GUI) or use mkdir (CLI). Fact: GUI actions often translate into CLI-like commands behind the scenes!"
# Creating a directory via CLI mkdir documents # Under the hood, this triggers a system call to the KernelThe Kernel Execution Flow
Kernel acts as the intermediary. When you run a piece of code, it doesn't talk to the hardware directly.
Case Study: Python print("Hello")
Python Shell: The execution happens in User Space.
Request: To display text, Python needs the CPU and I/O (Monitor).
Kernel Interaction: The shell interacts with the Kernel to request CPU time.
Hardware: Kernel instructs the CPU and display hardware to print "Hello".
Key Responsibility
Process management (creation, deletion, and scheduling of processes & threads) is entirely managed by the Kernel.
Separation of Concerns
This division prevents a bug in an app (User Space) from crashing the entire computer (Kernel Space).
Kernel Functionalities
Process Management
- Creation & Termination
- Scheduling
- Synchronization
- Inter-Process Comm
Memory Management
- Allocation & Deallocation
- Free Space Mapping
- Virtual Memory
- Protection
File Management
- File CRUD operations
- Directory management
- Disk mapping
- Permissions
I/O Management
- Spooling
- Buffering
- Caching
- Driver Interaction
File System Hierarchy Example
Inter-Process Communication (IPC)
How do processes communicate?
Since User Space and Kernel Space are totally independent and isolated, processes cannot directly peek into each other's memory. IPC is the mechanism used to bridge this gap.
Shared Memory
Fastest way. Multiple processes access a shared region.
Message Passing
Processes communicate via logical boxes or pipes.
Message Queues
Asynchronous communication using buffered lists.
Sockets
Used for communication across different networks.
Kernel Architectures
Monolithic Kernel
The oldest design where all kernel services (Process, Memory, File, I/O) run in the same privileged address space.
Micro-kernel
Keeps only core services (IPC, Process, Memory) in Kernel. Others move to User Space.
Hybrid Kernel
A balanced approach combining Monolithic speed with Micro-kernel stability.
- Reduced Context-Switching overhead.
- MacOS, Windows NT (v7.0+)
Exo/Nano Kernel
Minimalist approach providing absolute minimum services required to function.
- Tiny size (few 1000 lines of code).
- Fastest Performance, Ideal for IoT & RTOS.