🖥️ Operating Systems (105305)¶
⬅️ Back to Semester-3 | 🏠 Home
💡 Why this subject? Everything you run — your IDE, browser, every app — is managed by the OS. Understanding this explains why your laptop slows down, freezes, or crashes.
📌 Unit 1: Introduction¶
- OS: software that manages hardware and provides services to applications (acts as a middleman between user/apps and hardware).
- OS Structures:
- Monolithic: everything (file system, drivers, scheduler) in one big kernel — fast but hard to maintain.
- Layered: organized into layers, each only talking to the one below.
- Microkernel: only core functions in kernel, rest run as separate services — more stable, but slower (more communication overhead).
- System Call: how a user program requests a service from the OS kernel (e.g., reading a file).
- Virtual Machine: software that emulates a complete computer, allowing multiple OS instances on one physical machine.
🧠 Quick Recall: Linux = monolithic-ish kernel; Windows NT-based = hybrid kernel; microkernels = used where reliability is critical (e.g., QNX in cars/medical devices).
📌 Unit 2: Processes, Threads & Scheduling¶
- Process: a running program (with its own memory space). Thread: a lightweight unit of execution within a process (shares memory with sibling threads).
- Process states: New → Ready → Running → Waiting → Terminated.
- PCB (Process Control Block): the data structure storing everything the OS needs to know about a process (registers, state, memory info) — enables context switching.
CPU Scheduling Algorithms¶
| Algorithm | Idea | Pros/Cons |
|---|---|---|
| FCFS | First Come First Serve | Simple, but can cause long wait (convoy effect) |
| SJF | Shortest Job First | Minimizes average wait time, but needs to know burst time in advance |
| RR (Round Robin) | Each process gets a fixed time slice, then cycles | Fair, good for time-sharing systems |
| Priority Scheduling | Highest priority runs first | Can cause starvation of low-priority processes |
- Scheduling criteria: CPU utilization, Throughput, Turnaround Time, Waiting Time, Response Time.
📝 Example: Your OS task manager showing 100+ "processes" but you only opened 5 apps — many are background threads/services being scheduled by these algorithms.
📌 Unit 3: Inter-Process Communication (IPC)¶
- Critical Section: a piece of code where shared resources are accessed — must avoid simultaneous access (Race Condition).
- Mutual Exclusion: only one process can be in the critical section at a time.
- Semaphore: a counter-based tool to control access to shared resources.
- Binary semaphore (mutex-like, 0/1) vs Counting semaphore (allows N processes).
- Producer-Consumer Problem: classic IPC problem — producer adds items to a buffer, consumer removes them; must avoid buffer overflow/underflow using semaphores.
- Dining Philosopher Problem: classic deadlock-illustration problem — philosophers (processes) need 2 forks (resources) to eat, showing how naive resource-grabbing can deadlock everyone.
- Monitors: a higher-level synchronization construct (built into languages like Java via
synchronized) — easier and safer than raw semaphores.
📝 Example: Java's synchronized keyword (from your OOP subject!) is exactly mutual exclusion in action — only one thread can execute a synchronized method on an object at a time.
📌 Unit 4: Deadlocks¶
- Deadlock: a set of processes are all stuck, each waiting for a resource held by another.
- 4 Necessary Conditions (all must hold for deadlock — remember as MHNC):
- Mutual Exclusion — resource held by only one process at a time
- Hold and Wait — process holds a resource while waiting for another
- No Preemption — resource can't be forcibly taken away
- Circular Wait — a cycle of processes each waiting on the next
- Deadlock Prevention: break one of the 4 conditions.
- Deadlock Avoidance — Banker's Algorithm: OS checks if granting a resource request keeps the system in a "safe state" before allowing it.
- Deadlock Detection & Recovery: let deadlocks happen, detect via resource-allocation graph cycles, then recover (kill a process / preempt resources).
🧠 Quick Recall: Remove any one of the 4 conditions → deadlock becomes impossible. Most systems target "Circular Wait" (e.g., by ordering resource requests).
📌 Unit 5: Memory Management¶
- Logical vs Physical Address: logical = address generated by CPU; physical = actual location in RAM (mapped by MMU).
- Contiguous Allocation: fixed/variable partitions — causes fragmentation (internal = wasted space inside a partition; external = wasted scattered free space between partitions).
- Paging: divides memory into fixed-size pages (process) and frames (RAM) — eliminates external fragmentation.
- Segmentation: divides memory by logical units (code, stack, data) of variable size — matches how programmers think, but can have external fragmentation.
- Virtual Memory: lets a process use more memory than physically available RAM by using disk as overflow.
- Page Fault: requested page isn't in RAM, must be fetched from disk.
- Page Replacement Algorithms: decide which page to evict when memory is full:
- FIFO: evict oldest loaded page.
- LRU (Least Recently Used): evict page unused for longest time — best practical approximation of optimal.
- Optimal: evict the page that won't be used for longest time (theoretical best, can't implement in practice — needs future knowledge).
📝 Example: Your browser with 50 tabs open "feels slow" when RAM runs out — the OS keeps swapping pages in/out of disk (this swapping is called thrashing when excessive).
📌 Unit 6: File & Disk Management¶
- File Access methods: Sequential (read in order) vs Direct/Random (jump anywhere).
- Allocation methods:
- Contiguous: file stored in one continuous block — fast but fragmentation-prone.
- Linked: each block points to next — no fragmentation but slow random access.
- Indexed: an index block stores pointers to all data blocks — good balance (used by most modern file systems).
- Disk Scheduling (decide order to service disk I/O requests):
- FCFS: serve in arrival order.
- SSTF (Shortest Seek Time First): serve nearest request first.
- SCAN: disk arm sweeps in one direction, servicing requests, like an elevator.
- C-SCAN: like SCAN but jumps back to start after reaching the end (more uniform wait time).
- I/O Hardware: Device Controllers manage devices; DMA (Direct Memory Access) lets devices transfer data to/from memory without constantly bothering the CPU.
🧠 Quick Recall: SCAN/C-SCAN behave like an elevator — it doesn't reverse direction for every single request, it sweeps through floors (disk tracks).
🔬 Lab Highlights (OS Lab)¶
- FCFS, SJF, Priority, Round Robin scheduling
- Banker's Algorithm
- Disk scheduling algorithm
- Dining Philosopher Problem
- Producer-Consumer Problem
- LRU Page Replacement algorithm
✅ Quick Revision Table¶
| Topic | One-line memory hook |
|---|---|
| PCB | Stores everything needed for context switching |
| Round Robin | Fair time-slice scheduling, good for time-sharing |
| Semaphore | Counter-based tool for mutual exclusion |
| Deadlock (MHNC) | Mutual Exclusion + Hold&Wait + No Preemption + Circular Wait |
| Banker's Algorithm | Checks "safe state" before granting resources |
| Paging | Fixed-size blocks, removes external fragmentation |
| LRU | Evict the page unused for the longest time |
| C-SCAN | Disk arm sweeps like an elevator, one direction then reset |