Operating Systems Explained — A Beginner's Guide
An Operating System (OS) is the software that manages computer hardware and software resources — acting as a bridge between you and the machine’s raw components.
What You’ll Learn
In this tutorial, you’ll learn how operating systems manage processes, memory, and files — and how Linux, Windows, and macOS handle these tasks differently.
Why It Matters
Every time you open a program, save a file, or connect to Wi-Fi, the operating system is orchestrating dozens of operations behind the scenes. Understanding the OS helps you write better software and troubleshoot problems.
Real-World Use
When you double-click a browser, the OS allocates memory, creates a process, loads the executable from disk, sets up a network connection, and draws the window — all in under a second. Without the OS, you’d have to do all of this manually.
flowchart TD
subgraph OS Architecture
A[User Applications]
B[Shell / GUI]
C[System Calls]
D[Kernel]
E[Hardware]
end
A --> B
B --> C
C --> D
D --> E
subgraph Kernel Components
F[Process Scheduler]
G[Memory Manager]
H[File System]
I[Device Drivers]
J[Network Stack]
end
D --> F
D --> G
D --> H
D --> I
D --> J
What Does an Operating System Do?
Think of an OS as the manager of a company. The company has employees (CPU cores), desks (memory), filing cabinets (storage), and phones (network). Without a manager, everyone would fight for resources. The manager:
- Assigns tasks to employees (process scheduling)
- Gives each employee a desk (memory allocation)
- Organizes the filing cabinets (file system)
- Handles phone calls (network management)
- Keeps employees from interfering with each other (security)
Process Management
A process is a program in execution. When you open Chrome, the OS creates a new process.
Process States
A process goes through several states:
- New — the process is being created
- Ready — waiting to be assigned to a CPU
- Running — instructions are being executed
- Waiting — waiting for an event (like keyboard input)
- Terminated — finished execution
import time
import os
# Simulating process states
class Process:
def __init__(self, name, pid):
self.name = name
self.pid = pid
self.state = "New"
print(f"[{self.pid}] {name}: New")
def ready(self):
self.state = "Ready"
print(f"[{self.pid}] {name}: Ready to run")
def run(self):
self.state = "Running"
print(f"[{self.pid}] {name}: Running")
time.sleep(0.5)
self.state = "Terminated"
print(f"[{self.pid}] {name}: Terminated")
# Simulate process lifecycle
processes = [
Process("Browser", 1001),
Process("Music Player", 1002),
Process("File Explorer", 1003),
]
print("\n--- OS Scheduler Simulator ---")
for p in processes:
p.ready()
p.run()
print(f"\nActive processes on this machine: {os.cpu_count()} CPU cores available")Expected output (approximate):
[1001] Browser: New
[1002] Music Player: New
[1003] File Explorer: New
--- OS Scheduler Simulator ---
[1001] Browser: Ready to run
[1001] Browser: Running
[1001] Browser: Terminated
[1002] Music Player: Ready to run
[1002] Music Player: Running
[1002] Music Player: Terminated
[1003] File Explorer: Ready to run
[1003] File Explorer: Running
[1003] File Explorer: Terminated
Active processes on this machine: 4 CPU cores availableContext Switching
The OS can quickly switch between processes, making it seem like multiple programs run simultaneously (even on a single CPU). This is called context switching.
Think of it like a chef cooking multiple dishes. While waiting for water to boil (I/O), the chef chops vegetables for another dish. The OS does the same — when one process waits for input, it switches to another.
Scheduling Algorithms
| Algorithm | How It Works | Used In |
|---|---|---|
| First-Come, First-Served | Processes run in arrival order | Simple batch systems |
| Round Robin | Each process gets a fixed time slice | Linux, Windows |
| Priority Scheduling | Higher priority processes run first | Real-time systems |
| Multi-level Feedback | Processes move between priority queues | Modern OS (Linux) |
Memory Management
The OS manages the computer’s memory — deciding which processes get which portions and when.
Virtual Memory
Your computer might have 8 GB of RAM, but the OS can make each process think it has its own private 4 GB address space. This is virtual memory.
The OS maps virtual addresses to physical addresses using a page table. If a process tries to access memory outside its allocated range, the OS kills the process with a “segmentation fault.”
# Simulating virtual memory mapping
class VirtualMemory:
def __init__(self, total_physical_mb=1024):
self.physical_memory = {} # Physical page -> data
self.page_table = {} # Virtual page -> Physical page
self.next_physical = 0
self.total_physical = total_physical_mb // 4 # 4 KB pages
def allocate(self, process_id, size_kb):
pages_needed = (size_kb + 3) // 4 # 4 KB per page
allocated = []
for _ in range(pages_needed):
if self.next_physical >= self.total_physical:
print(f"OUT OF MEMORY! Process {process_id} allocation failed")
return False
virtual_page = len(self.page_table) // 2 # Simplified
physical_page = self.next_physical
self.page_table[virtual_page] = physical_page
self.physical_memory[physical_page] = f"Process {process_id} data"
self.next_physical += 1
allocated.append(virtual_page)
print(f"Process {process_id}: allocated {size_kb} KB ({pages_needed} pages)")
return True
def access(self, process_id, virtual_page):
if virtual_page in self.page_table:
physical = self.page_table[virtual_page]
print(f"Process {process_id}: Virtual page {virtual_page} -> Physical page {physical}")
return True
print(f"SEGFAULT! Process {process_id}: Invalid virtual page {virtual_page}")
return False
mmu = VirtualMemory()
mmu.allocate(1, 16) # Allocate 16 KB
mmu.allocate(2, 8) # Allocate 8 KB
mmu.access(1, 1) # Access valid page
mmu.access(2, 99) # Access invalid pageExpected output:
Process 1: allocated 16 KB (4 pages)
Process 2: allocated 8 KB (2 pages)
Process 1: Virtual page 1 -> Physical page 1
SEGFAULT! Process 2: Invalid virtual page 99File Systems
The file system controls how data is stored and retrieved on disk.
How Files Are Stored
When you save a file, the OS doesn’t just dump it onto the disk. It:
- Finds free space on the disk
- Splits the file into blocks
- Creates metadata (name, size, permissions, timestamps)
- Updates the directory structure
# Simulating a simple file system
class SimFS:
def __init__(self, block_size=512):
self.blocks = {} # block_number -> data
self.files = {} # filename -> [block_numbers]
self.directory = {} # filename -> metadata
self.next_block = 0
def write_file(self, name, content):
# Split content into blocks
data = content.encode('utf-8')
num_blocks = (len(data) + 511) // 512
block_nums = []
for i in range(num_blocks):
block_data = data[i*512:(i+1)*512]
self.blocks[self.next_block] = block_data
block_nums.append(self.next_block)
self.next_block += 1
self.files[name] = block_nums
self.directory[name] = {
"size": len(data),
"blocks": num_blocks
}
print(f"Written '{name}': {len(data)} bytes in {num_blocks} blocks")
def read_file(self, name):
if name not in self.files:
print(f"File '{name}' not found!")
return None
blocks = self.files[name]
data = b''
for bn in blocks:
data += self.blocks[bn]
data = data.rstrip(b'\x00') # Remove padding
print(f"Read '{name}': {len(data)} bytes")
return data.decode('utf-8')
def list_directory(self):
print("\nDirectory listing:")
for name, meta in self.directory.items():
print(f" {name}: {meta['size']} bytes, {meta['blocks']} blocks")
fs = SimFS()
fs.write_file("report.txt", "Q1 revenue increased by 15% year-over-year.")
fs.write_file("notes.txt", "Remember to update the server certificates before June 15.")
fs.read_file("report.txt")
fs.list_directory()Expected output:
Written 'report.txt': 50 bytes in 1 blocks
Written 'notes.txt': 68 bytes in 1 blocks
Read 'report.txt': 50 bytes
Directory listing:
report.txt: 50 bytes, 1 blocks
notes.txt: 68 bytes, 1 blocksLinux vs Windows vs macOS
| Feature | Linux | Windows | macOS |
|---|---|---|---|
| Kernel | Monolithic | Hybrid | Hybrid (XNU) |
| File system | ext4, XFS, Btrfs | NTFS, FAT32 | APFS, HFS+ |
| Package manager | apt, yum, pacman | winget, MSI | Homebrew, .dmg |
| Licensing | Open Source (GPL) | Proprietary | Proprietary |
| Target | Servers, dev, embedded | Desktop, enterprise | Desktop, creative |
| Shell | Bash, Zsh | PowerShell, CMD | Zsh, Bash |
Security from an OS Perspective
User permissions — Linux and macOS use Unix-style permissions (read/write/execute for owner/group/others). Windows uses ACLs (Access Control Lists). These prevent unauthorized access.
Process isolation — Each process runs in its own virtual address space. A crashing browser can’t corrupt a music player’s memory.
ASLR (Address Space Layout Randomization) — The OS randomizes where program code is loaded in memory, making it harder for attackers to exploit buffer overflows.
Secure boot — Modern OS verify the integrity of boot components using cryptographic signatures.
Common Mistakes Beginners Make
1. Confusing process and program
A program is a file on disk. A process is that program in execution. One program can have multiple processes.
2. Ignoring file permissions
Running everything as root/admin is dangerous. A typo like rm -rf / as root destroys the entire system.
3. Not understanding virtual memory
“Out of memory” errors don’t always mean RAM is full. They can mean address space is exhausted or swap is full.
4. Thinking more cores always means faster
Not all tasks can be parallelized. A single-threaded program runs on one core regardless of how many you have.
5. Forgetting about I/O bottlenecks
The CPU can process data faster than the disk can supply it. I/O, not CPU, is often the bottleneck.
Practice Questions
What is a process? A program in execution. It includes the program code, current activity (program counter), and allocated resources.
What does a context switch involve? Saving the current process’s state (registers, program counter) and loading another process’s saved state.
What’s the purpose of virtual memory? To give each process its own private address space, isolate processes from each other, and allow programs larger than physical RAM.
How does a file system organize data? It splits files into blocks, stores them on disk, and maintains metadata (name, size, location, permissions) in a directory structure.
Why is process isolation important for security? It prevents one compromised process from reading or corrupting another process’s memory.
Challenge
Run htop (Linux) or Task Manager (Windows). Observe the list of processes. Pick 5 — what does each do? How much memory and CPU does each use?
Real-World Task
Use the ps command (Linux/macOS) or Get-Process (PowerShell) to list all running processes on your computer. Group them by the user who owns them.
FAQ
Try It Yourself
Mini Project: Process Monitor Simulator
Build a Python script that:
- Creates a simulated list of processes with names, burst times, and priorities
- Implements FCFS, Round Robin, and Priority scheduling
- Compares average waiting time and turnaround time for each algorithm
Security angle: OS security features like process isolation are what keep malware from accessing other programs’ memory — the same isolation that antivirus tools like Durga Antivirus Pro rely on to run safely alongside other applications.
What’s Next
Before moving on, you should understand:
- Process management and scheduling
- Virtual memory and why it matters
- File system organization
- The difference between Linux, Windows, and macOS
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
What’s Next
Congratulations on completing this Operating Systems tutorial! Here’s where to go from here:
- Practice daily — Consistency is more important than long study sessions
- Build a project — Apply what you learned by building something real
- Explore related topics — Check out other tutorials in the same category
- Join the community — Discuss with other learners and share your progress
Remember: every expert was once a beginner. Keep coding!
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro