0% found this document useful (0 votes)
12 views19 pages

Overview of Operating Systems

Uploaded by

codingera01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views19 pages

Overview of Operating Systems

Uploaded by

codingera01
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

✅ 1.

Basics of Operating System


📌 What is an OS?
Think of an Operating System as the brain or manager of your computer.
You don’t talk directly to the hardware (like CPU, RAM, or hard disk).
Instead, you give instructions (like opening a le or playing a video), and the OS handles everything for you in the
background.

🖥 Types of OS (Batch, Time-sharing, Real-time, Distributed,


Embedded, etc.)
1. Batch OS

A Batch Operating System is a type of OS where similar jobs are grouped together and run one after the other
without user interaction.

2. Multiprogramming OS

A Multiprogramming OS is a type of operating system that allows more than one program to be in memory at the
same time and uses the CPU ef ciently by switching between them.

3. Multitasking OS

A Multitasking OS is a system where multiple tasks (programs) run at the same time — or at least, it feels like they
do!

4. Time Sharing OS

A Time Sharing OS is a type of multitasking OS where many users can use the system at the same time, and each
user gets a small time slot (time slice) to use the CPU.

5. Real-Time OS

A Real-Time Operating System is an OS that responds to inputs or events immediately — within a very short and
xed time.

6. Distributed OS

A Distributed OS is a system that connects many computers together and makes them work like a single system.

7. Embedded OS

An Embedded OS is an operating system designed to run on small devices that do one speci c task.
It runs inside a device, not on a general computer like your PC or laptop.
fi
fi
fi
fi
⚙ Functions of an OS
• Resources Allocation

• Memory Management

• Scheduling

• Security

• File Processing

🧱 Kernel vs User Space

📦 1. User Space (👩 💻 Where your programs run)

• This is where user applications run (like browsers, games, text editors).

• Cannot access hardware directly — must ask the kernel for help.

• If a program crashes here, system is safe.

🧑 💻 “Hey Kernel, can you open this le for me?”

⚙ 2. Kernel Space (🛠 Where the OS core runs)

• This is where the Operating System runs.

• Has full access to hardware (CPU, RAM, disks, etc.).

• Handles memory, processes, drivers, security, etc.

• A crash here = 💥 entire system crash.

👮 “I control the entire system, no messing around here.”

🧠 Monolithic vs Microkernel
A kernel is the core part of an operating system.
It talks directly to the hardware and controls everything — memory, processes, les, devices, etc.

🧱 1. Monolithic Kernel (One Big Block)

Everything is built into one large program running in kernel space.

✅ Features:
fi
fi
• All OS services (memory, le system, drivers, etc.) run together in the kernel.

• Fast performance because no extra communication.

• If one part crashes, the whole system can crash (less safe).

💡 Example: Linux, Unix, MS-DOS

🧩 2. Microkernel (Small Core, Add Services Outside)

Only the most essential parts run in kernel space.


Other parts run in user space as separate services.

✅ Features:

• Kernel only manages CPU, memory, IPC (communication).

• Other parts (like le system, drivers) run as separate programs.

• More secure and stable, but slightly slower due to communication between parts.

💡 Example: Minix, QNX, Mach, some versions of Windows

✅ 2. Process Management

📌 Process vs Program
• A program is just the code.

• A process is the running version of that code.

📋 Process Control Block (PCB)


A PCB is a data structure used by the Operating System to keep all the information about a process.

📦 Think of the PCB like a le or ID card for each running process — it stores everything the OS needs to manage
that process.

🔄 Process States

State What It Means


🟡 New The process is just created (not yet ready to run).
fi
fi
fi
🟢 Ready Process is ready to run, waiting for CPU.
🔵 Running Process is using the CPU and actively running.
🔴 Waiting / Blocked Process is waiting for something (e.g., le input, user input).
⚫ Terminated / Exit Process has nished execution or was killed.

Process Flow:

New → Ready → Running → Terminated



Waiting → Ready → Running

🔁 Context Switching
Context Switching is the process where the CPU switches from one process to another.

🧠 It saves the current process’s information and loads another process’s info — so the CPU can continue from where it
left off.

📊 Process Scheduling Algorithms


Only one process can run at a time, so the scheduler decides which process runs next using scheduling algorithms:

• FCFS

• SJF (preemptive & non-preemptive)

• Round Robin

• Priority Scheduling

🔢 1. FCFS (First Come First Serve)

📌 The process that comes rst will run rst.

✅ Key Points:

• Simple and easy to understand

• Non-preemptive (once a process starts, it can't be stopped)

• Like a queue at a ticket counter 🎟

🔍 Example:

Order: P1 → P2 → P3
Waiting Time: P1 = 0, P2 = 4, P3 = 7

🧠 2. SJF (Shortest Job First)


fi
fi
fi
fi
📌 The process with the shortest burst time runs rst.

✌ Two Types:

• Non-Preemptive: Once a process starts, it won’t be interrupted.

• Preemptive (SRTF): If a shorter process comes, it preempts the running one.

✅ Key Points:

• Minimizes average waiting time

• May cause starvation (long jobs wait forever)

🔍 Example (Non-Preemptive):

Process Arrival Burst

P1 0 8

P2 1 4
P3 2 2

Order: P1 → P3 → P2
(But in Preemptive SJF, P3 might preempt P1 as soon as it arrives)

🔁 3. Round Robin (RR)

📌 Every process gets a xed time slot (time quantum) in rotating order.

✅ Key Points:

• Preemptive

• Fair for all processes

• Good for time-sharing systems

💡 Time Quantum Example: 4 ms

🔍 Example:

Process Arrival Burst

P1 0 5

P2 1 4

P3 2 7

Order:
P1 (0–4) → P2 (4–8) → P3 (8–12) → P1 (12–13) → P3 (13–16) → ...

⭐ 4. Priority Scheduling
fi
fi
📌 CPU is given to the process with the highest priority.

• Can be Preemptive or Non-preemptive

• Lower number = higher priority (usually)

✅ Key Points:

• Good for important tasks

• Can cause starvation (low-priority processes may never run)

🔍 Example:

Process Arrival Burst Priority

P1 0 5 2

P2 1 3 1

P3 2 4 3

Order: P2 → P1 → P3 (because of priority)

✅ 3. Threads and Concurrency

🧵 Process vs Thread
• A process is an independent program running in its own memory space.
🧳 Think of a process like a traveling suitcase — it carries its own clothes (memory), tickets (resources), and
has its own journey.

• A thread is a smaller unit inside a process.


Multiple threads share the same memory and resources of the process.
🧶 Think of threads like people inside the same suitcase — they share the same stuff but do different tasks.

🧵 Types of Threads

User-Level Threads (ULT)

• Threads managed by user, not by the OS.

• OS doesn’t know these threads exist.

• Managed by a thread library in user space.

• Fast to create and switch.

• If one thread blocks (e.g., for I/O), the whole process blocks.
1⃣
📦 Analogy:
A school class run by students themselves — the teacher (OS) doesn’t know what’s happening inside.

Kernel-Level Threads (KLT)

• Threads managed directly by the OS kernel.

• OS knows about each thread.

• More control, better for multi-core CPUs.

• Slower than ULT because switching needs kernel help.

• If one thread blocks, others can still run.

🧑 🏫 Analogy:
A school class run by the teacher (OS), who controls each student (thread).

💻 Multithreading
Multithreading means running multiple threads at the same time within a single process.

💡 Real-Life Example:
When using a browser:

• One thread loads the page 🌐

• One plays a video 🎥

• One listens for mouse clicks 🖱

All run together — that’s multithreading!

⚔ Multithreading vs Multiprocessing

Feature Multithreading Multiprocessing

Units Threads (same process) Processes (independent)

Memory Shared memory Separate memory

Speed Faster (lightweight) Slower (heavy)

Crash One thread can affect others Separate crash protection

🔁 Context Switch Between Threads vs Processes


2⃣
Feature Thread Context Switch Process Context Switch

⏱ Speed Faster (lighter) Slower (heavier)

📂 Memory Shared memory (same process) Separate memory spaces

🔐 Security/Isolation Less secure (can interfere) More secure (isolated)

💾 Overhead Low High

🧠 Use Case Within one app Between different apps

✅ 4. Synchronization

🔄 What is Synchronization?
Synchronization means controlling access to shared resources when multiple threads or processes try to use them at
the same time.

💡 Real-Life Example:
Imagine 2 people trying to write in the same notebook at the same time 📝 — it’ll create a mess.

✅ Synchronization is like giving the notebook to only one person at a time — keeping things safe and organized.

⚠ Race Condition
A Race Condition happens when two or more threads/processes access shared data at the same time, and the nal
result depends on the order of execution — leading to unexpected or buggy behavior.

❗ Critical Section Problem


Occurs when multiple processes/threads try to access and modify shared data at the same time — may lead to
incorrect results.

🔧 Solutions to Synchronization Problems

◦ Mutex

Mutex (Mutual Exclusion) is a lock that ensures only one thread accesses the critical section at a time.

◦ Semaphore

A Semaphore is a counter used to control access to a shared resource by multiple threads or processes.
fi
💡 Simple Analogy:
Imagine a parking lot with 3 slots 🚗 🚗 🚗

• Only 3 cars can park at a time.

• A 4th car must wait.

Details:

• Each parking slot = 1 unit of the semaphore

• Semaphore count = 3

• When a car enters → count goes down

• When a car leaves → count goes up

◦ Spinlocks

A Spinlock is a lock where a thread "spins" (keeps checking in a loop) until it gets the resource.

💡 Analogy:
A person standing outside a locked bathroom 🚪 — instead of waiting elsewhere, he keeps trying the handle until it
opens 🔁

◦ Monitors

A Monitor is a high-level synchronization tool that automatically handles locking and coordination.

💡 Analogy:
A room (monitor) with a doorman who:

• Lets only one person in

• Makes others wait

• Wakes up the next when free

📚 Classic Problems

🍎 1. Producer-Consumer Problem

🧠 What is it?
A Producer creates data, and a Consumer uses it.
They share a buffer and must coordinate to avoid con ict.

💡 Example:

• 🍳 Chef (Producer) makes dishes


fl
• 🍽 Waiter (Consumer) serves them

• They use a shared counter (buffer)

✅ Rules:

• Chef can’t place food if the counter is full

• Waiter can’t pick food if the counter is empty

🛠 Solution:

• Use Semaphore or Mutex for locking

• Use two semaphores:

◦ empty → tracks empty spaces

◦ full → tracks lled spaces

🍴 2. Dining Philosophers Problem

🧠 What is it?
5 philosophers sit at a table, each needs 2 forks (left & right) to eat.
But each fork is shared between neighbors.

💡 Example:

• Philosophers = Threads

• Forks = Shared Resources (Locks)

❌ Problem:
If all pick up their left fork, no one gets a right → Deadlock!

⚠ Challenges:

• Deadlock

• Starvation (some may never eat)

🛠 Solutions:

• Pick both forks at once (use a mutex)

• Limit number of philosophers eating at once

• Odd-even strategy: odd pick left rst, even pick right

📖 3. Readers-Writers Problem
fi
fi
🧠 What is it?
A shared database accessed by:

• Readers → only read (can read together)

• Writers → write/update (need full access)

❌ Problem:
If both access at the same time → data corruption

💡 Example:

• Students reading the same book = ✅

• But if one is writing notes inside it, others must wait ❌

🛠 Goals:

• Allow multiple readers at the same time

• Only one writer at a time

• No starvation for reader or writer

✅ 5. Deadlock
🔒 What is Deadlock?
A deadlock happens when two or more processes are stuck waiting for each other to release resources — and none
of them can move forward.

🧠 Real-Life Example:

• Person A has a pen and needs a paper.

• Person B has a paper and needs a pen.

Coffman's Conditions (Deadlock Conditions)

These four conditions must all be true at the same time for a deadlock to occur:

1. Mutual Exclusion

• Only one process can use a resource at a time.

• If another process requests that resource, it must wait.


🧠 Example: Only one process can use a printer at a time.
2. Hold and Wait

• A process is holding at least one resource and is waiting to acquire more.


🧠 Example: Process A has the scanner and waits for the printer used by Process B.

3. No Preemption

• A resource cannot be forcibly taken from a process.


🧠 Example: You can’t take the printer from Process B until it's done.

4. Circular Wait

• A cycle of processes exists where each waits for a resource held by the next.
🧠 Example: A → B → C → A

🛡 Deadlock Handling Strategies

1. Deadlock Prevention

🔄 Stop at least one Coffman's condition from happening.


Goal: Design the system so deadlock can never happen.

2. Deadlock Avoidance (Banker’s Algorithm)

🔍 Allow resource allocation only if it's safe.


Goal: Check each request and approve only if the system stays in a safe state.

🏦 Banker’s Algorithm:

• Each process declares its max resource need in advance.

• The system checks if it can safely grant the request.

3. Deadlock Detection

🛑 Let deadlock happen, but detect it afterward.


Goal: Run checks periodically to detect deadlocks.
📌 Detection Methods:

• Wait-for Graph: If there's a cycle, there's a deadlock.

• Matrix-based methods like Banker’s logic.

4. Deadlock Recovery

🔁 After detection, take action to x it.


Goal: Break the cycle so processes can continue.
fi
✅ 6. Memory Management
📚 Key Concepts
• Memory Management allows memory to be shared among multiple processes.

• Overlays: Only load required instructions/data.

• Swapping: Swap out processes that have used their time slice.

🧮 Allocation Techniques

a) Single Partition Allocation

• Memory divided into 2 parts: one for OS, one for users.

b) Multiple Partition Allocation

• Fixed Partition: Memory divided into xed-size blocks.

• Variable Partition: Memory divided into variable-size blocks.

Variable Partition Fit Types:

1. First Fit: Assign the rst suitable hole.

2. Best Fit: Assign the smallest hole that ts.

3. Worst Fit: Assign the largest available hole.

🧭 Logical vs Physical Address

📍 Logical Address (Virtual Address)

• Generated by CPU when process runs.

• Used inside the program.


💡 Example: Address 1200 = logical.

📦 Physical Address

• Actual address in RAM.

• Managed by MMU.
💡 Example: Logical 1200 → Physical 81200
fi
fi
fi
📘 Paging vs Segmentation

✅ Paging (Fixed-Size Memory Management)

🧠 Paging breaks memory into equal-sized blocks.

Key Points:

• Logical memory → Pages

• Physical memory → Frames

• OS uses Page Table to map pages to frames.

• Avoids external fragmentation.

🧾 Example: 20 KB program + 4 KB page = 5 pages

✅ Segmentation (Logical Division)

🧠 Memory divided by program structure: Code, Data, Stack

Key Points:

• Variable-size segments

• Each has a name, base, and length

• Managed using Segment Table

• Easier for programmers

🧾 Example: Code (8 KB), Data (5 KB), Stack (2 KB) = 3 segments

🗂 Page Table
A Page Table keeps track of how virtual pages map to physical memory.

💾 Virtual Memory Concepts

🧠 1. Virtual Memory

• Lets programs use more memory than physically available (RAM).

• OS uses part of the hard disk as extra memory.

Key Points:
• Each program feels like it has enough memory.

• OS maps virtual → physical addresses.

📄 2. Demand Paging

• Loads pages only when needed.

• Reduces memory usage.

❌ 3. Page Fault

• Happens when page isn’t in memory.


Key Points:

• OS loads page from disk → RAM

• Causes a small delay

🔁 4. Thrashing

The system keeps loading and removing pages again and again, and because of that, it

becomes very slow.

• Too many page faults → OS keeps loading/removing pages → system slows.

Fix: Reduce multitasking, increase RAM, improve paging algorithm.

🔄 Page Replacement Algorithms

📑 1. FIFO (First-In, First-Out)

✅ Replace oldest page.


🧠 Use a queue. Remove page at front when full.
📌 Example: [3, 2, 1] → Add 4 → Remove 3 → [2, 1, 4]
❗ Downside: Might remove frequently used pages.

🕒 2. LRU (Least Recently Used)

✅ Replace page used longest time ago.


🧠 Track last-used time for each page.
📌 Example: [A, B, C] → Add D → Remove A → [B, C, D]
✅ Good performance but needs tracking.

📈 3. Optimal
✅ Replace page not used for longest time in future.
🧠 Looks ahead to pick best.
📌 Example: Future = [A, B, C, A, D] | Memory = [A, B, C] → Replace B
(Note: Only used for comparison — not practical in real systems)

✅ 8. Disk Scheduling Algorithms


Disk scheduling decides which disk I/O request should be served next.
Goal: Minimize head movement and improve performance.

🚗 1. FCFS (First Come First Serve)

• Serve requests in the order they arrive.


📌 Example: [40, 10, 30, 50] → 40 → 10 → 30 → 50
❌ May cause long movements.

🎯 2. SSTF (Shortest Seek Time First)

• Serve request closest to current head.


📌 Example: Head at 30 → [10, 25, 40] → Serve 25 → 40 → 10

3. SCAN (Elevator)

• Head moves in one direction serving requests, then reverses.


📌 Example: Going right → [34, 45, 60, 90] → then reverse

🔍 4. LOOK

• Like SCAN but stops at last request, not disk end.


📌 Example: Last request is 90 → stop there

🔄 5. C-SCAN (Circular SCAN)

• Head moves one direction. When it reaches end, jumps to beginning.


📌 Ensures uniform wait time.

🔁 6. C-LOOK

• Like C-SCAN but only goes to last request, then jumps to beginning.
📌 Ef cient and balanced.

✅ 9. I/O Management
fi
I/O management deals with how the OS handles data transfer between the CPU and I/O devices (keyboard, mouse,
printer, etc.)

⚡ 1. Interrupts
An interrupt is a signal from a device to the CPU saying: “Hey, I need attention!”

🧠 Example:

• You press a key → Keyboard sends interrupt → CPU handles it → returns to previous task

✅ Advantages:

• CPU doesn’t waste time checking devices

• Improves overall ef ciency

🔄 2. DMA (Direct Memory Access)


DMA allows devices to directly send/receive data from memory without CPU involvement.

🧠 Example:

• Disk transfers a le to RAM directly — no CPU needed

✅ Bene ts:

• Frees up CPU for other tasks

• Faster I/O

🔍 3. Polling vs Interrupt-driven I/O

Method Description Pro/Con

Polling CPU keeps checking if device is ready ❌ Wastes CPU time


Interrupt-driven Device sends signal when ready ✅ Ef cient, responds only when needed

🧠 Analogy:

• Polling = You keep checking the oven

• Interrupt = Oven beeps when cake is done

🧺 4. Buffering and Spooling


fi
fi
fi
fi
📦 Buffering

Temporary storage used to hold data during transfer between CPU and devices.

• Matches speed between slow and fast devices

• Example: Video streaming preloads via buffer

🖨 Spooling

(“Simultaneous Peripheral Operations On-Line”)

• Data stored in a queue, processed later (e.g., printing)

• Multiple print jobs go into a spool

• CPU and device can work independently

✅ 10. System Calls


📌 What are System Calls?
System calls are how a program asks the OS to do something it can’t do directly.

🧠 Think of it like:
👉 "Dear OS, please open this le for me"

🖥 Why Needed?
• Programs can’t access hardware or protected memory directly

• So they ask the OS using system calls

⚙ Types of System Calls

Type What it Does Examples

Process Control Create/manage/terminate processes fork(), exec(), wait(), exit()

File Management Open, read, write, close les open(), read(), write()

Device Management Request/release device access close(), ioctl()

Info Maintenance Get system/process info getpid(), alarm(), sleep()

Communication Data exchange between processes pipe(), shmget(), msgget()

🐧 Examples in Linux:
fi
fi
Function Description

fork() Creates a new process (child)

exec() Replaces current process with new program

wait() Parent waits for child to nish

exit() Ends the process

read() Reads from le/device

write() Writes to le/device

✅ 11. Scheduling Concepts


⚔ Preemptive vs Non-preemptive Scheduling
CPU scheduling decides which process gets the CPU next from the ready queue.

Feature Preemptive Non-Preemptive

CPU can be taken? ✅ Yes – forcibly from running process ❌ No – keeps CPU until done/blocked
Example Algos Round Robin, SRTF, Preemptive Priority FCFS, SJF, Non-preemptive Priority

Fairness More fair May cause long waiting

🧠 CPU Burst vs I/O Burst

Term Meaning

CPU Burst Time spent doing CPU computations

I/O Burst Time spent waiting for I/O operations

📈 Performance Metrics

Term Meaning Formula

Throughput How many processes complete per unit time No. of processes / total time

Turnaround Time Total time from arrival → completion Completion time - Arrival time

Waiting Time Time spent waiting in the ready queue Turnaround time - Burst Time

Response Time Time from arrival → rst CPU access First run time - Arrival time
fi
fi
fi
fi

You might also like