>_
EngineeringNotes
← Back to OS Internals
Chapter 03

Components of OS & System Calls

Essential interfaces and architecture of modern operating systems.

01

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
User Space (Apps)
Kernel Space (Privileged)
Hardware (CPU, RAM, I/O)

High-Level Interaction Flow

02

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.

Restricted Privileges

Kernel Mode

To perform kernel-level work (like saving a file), the CPU must Switch itself into Kernel Mode.

Full Privileges

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.

03

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!"

User Space Example
bash
# Creating a directory via CLI mkdir documents  # Under the hood, this triggers a system call to the Kernel
04

The 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")

1

Python Shell: The execution happens in User Space.

2

Request: To display text, Python needs the CPU and I/O (Monitor).

3

Kernel Interaction: The shell interacts with the Kernel to request CPU time.

4

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).

05

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

/
Code
Web-Dev
ML
College
DevOps
Sem-5
06

Inter-Process Communication (IPC)

Interview Hot Topic

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.

07

Kernel Architectures

Monolithic Kernel

The oldest design where all kernel services (Process, Memory, File, I/O) run in the same privileged address space.

AdvantageFast performance & low overhead.
DisadvantageBulky and low reliability. One crash kills all.
Example: Linux, Unix, MS-DOS
Kernel Space
Process
Memory
FileSystem
I/O
User Space
FileSystem
I/O Device
Kernel (Micro)
Process
Memory

Micro-kernel

Keeps only core services (IPC, Process, Memory) in Kernel. Others move to User Space.

AdvantageHighly Reliable & Stable.
DisadvantagePerformance hit due to frequent mode switching.
Example: L4 Linux, Symbian OS

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.