>_
EngineeringNotes
← Back to OS Internals
Chapter 01

Introduction to OS

What, Why, and How? The silent manager of your digital life.

01

What is an OS?

An Operating System (OS) is a piece of System Software that manages all the resources of a Computer System (both Hardware and Software).

It acts as an Interface between the User/Application and the Computer Hardware. Without it, talking to the CPU or RAM would be incredibly complex.

# Official Definition

"An interface is a shared boundary across which two or more separate components of a computer system exchange information. It abstracts the underlying implementation details, allowing users to interact with complex hardware through simple commands."

Think of it like a Restaurant Waiter 🍽️

You (the User) don't go into the kitchen (Hardware) to cook your own food. You just tell the Waiter (OS) what you want, and they handle the chaotic kitchen staff to get your meal ready.

User: Click "Save File"
OS (Interface): "Okay! driving the Hard Disk motor, finding empty sector 0x4F, writing binary data..."
Without OS: You would have to write code to spin the disk motor yourself! 😱

User / Apps (Instagram, BGMI)

Operating System

Interface & Resource Allocator

Hardware (CPU, RAM, Disk)

Application Software

Designed for end-users to perform specific tasks.

BrowsersGamesWord Processors

System Software

Designed to run the computer hardware and application programs.

Operating SystemDevice DriversFirmware
02

Why do we need it? (The No-OS Nightmare)

Imagine there is NO Operating System...

You open Instagram. Since there is no manager, Instagram has to write its own code to talk to the CPU and RAM. Greedy as it is, it decides it needs ALL the power to render reels smoothly.

Chaos Mode
Instagram
Hardware ResourcesLOCKED BY INSTAGRAM
CPU
RAM
GPU
BGMI

"I can't start... Resources are locked!"

Problem 1: Resource Hacking

Without an OS, specific apps can "hack" or lock resources entirely for themselves. Instagram effectively owns your phone now.

Problem 2: No Multitasking

If you want to play BGMI while Instagram is open? Impossible. The hardware is already allocated.

Problem 3: Violation of DRY

Don't Repeat Yourself. Every single developer would have to write complex code just to manage RAM. Bundling this logic in every app makes them huge and buggy.

03

The Solution: OS as Allocator

We introduce the Operating System layer using the policy of Resource Allocation. The OS is the boss. Apps ask the OS for resources, and the OS decides how much to give.

Managed Mode

Operating System (The Kernel)

"I will allocate resources fairly."

Instagram
CPU Usage5%
Memory10%
BGMI
CPU Usage50%
Memory50%
04

Functions of Operating System

The OS works as a Government for the computer, managing all major departments.

Process Management

Creating, scheduling, and terminating processes (programs in execution). Decides who gets the CPU.

Memory Management

Tracks which bytes of RAM are used by which app. Handles allocation and de-allocation.

Device Management

Manages device drivers (Keyboard, Mouse, Printer). Handles inputs and outputs efficiently.

F

File Management

Organizes data into files and directories. Handles creation, deletion, and access permissions.

S

Security

Prevents unauthorized access (Password protection). Protects OS memory from malicious apps.

C

Command Interpreter

Interprets user commands (CLI/GUI) and translates them into system calls.

05

Goals of Operating System

01. Max CPU Utilization

We never want the CPU to be idle.

P1 goes for I/O?
→ OS Switch to P2
"Don't let the brain sleep!"
02. No Starvation

Every process must get a chance to execute.

If P1 has while(True)...
P2 waits forever?
NO! OS force switches.
03. Priority Execution

Important jobs (like Antivirus or System tasks) run first.

P1, P2 (Normal) waiting...
Antivirus (High) comes
→ OS runs AVL first.
06

Types of Operating Systems

Single Process OS Oldest

  • Only ONE process executes at a time.
  • Violates all goals (CPU Idle during I/O, Starvation possible).
  • Example: MS-DOS.

Batch Processing OS

Jobs with similar requirements are grouped into "Batches" and executed one by one. (Like washing all white clothes together, then colored ones).

User Jobs
Operator (Batches)
CPU (Executes Batch)

Multi-Programming OS Efficient

Maximizes CPU utilization using Context Switching.

How it works:If Process A needs to wait for I/O (e.g. read a file), the CPU doesn't sit idle. It immediately switches to Process B.
The Flaw (Starvation):If Process A has a while(true) loop and never waits for I/O, it will keep the CPU forever. Process B starves.
Modern Standard

Multi-Tasking (Time Sharing) OS

Logical extension of Multi-programming. Solves starvation using Time Quantum (Round Robin).

P1 (2s)P2 (2s)P3 (2s)P1 (2s)...

Each process gets the CPU for a fixed time (e.g., 2 nanoseconds). Even if P1 has an infinite loop, it is forced out after 2ns so P2 can run.

RTOS (Real Time OS)

Strict time deadlines. Data must be processed within a fixed time limit.

Hard RTOS

Missing deadline = Failure.

Airbags, Parachutes
Soft RTOS

Missing deadline = Lag.

Video Streaming

Distributed OS

Multiple independent computers appear as a single system. Loosely connected.
Example: LOCUS, Cloud Computing clusters.