Skip to content
CY-404 · Operating Systems/Quick Revision Short Notes

Operating Systems (CY-404) - Unit 5 Short Notes

UNIT 5: OPERATING SYSTEMS - COMPREHENSIVE NOTES

Based on rigorous analysis of RGPV past papers (2022-2025), these notes prioritize exam-critical concepts using a schematic, definition-first approach.


I. FOUNDATIONS & OVERVIEW

Evolution of Operating Systems

Generation Key Technology Primary Goal Example
Batch Job Control Language (JCL) Maximize CPU utilization IBM OS/360
Multi-programming Memory management Keep CPU busy with multiple jobs
Time-sharing CPU scheduling Interactive user sessions UNIX, Multics
Parallel/Distributed Networks, multiprocessors Resource sharing, scalability Cluster OS
Real-time Deadline scheduling Guaranteed response time VxWorks, QNX
Mobile Power management, touch UI Battery life, app ecosystem Android, iOS

Impact: Each generation drove hardware development (e.g., time-sharing → terminals, multiprocessing → multi-core CPUs).

Operating System Services

User Services:

  1. Program Execution: Load & run (system calls: fork, exec).

  2. I/O Operations: Hide device specifics (system calls: read, write).

  3. File System Manipulation: Create, delete, access files.

  4. Communication: IPC (pipes, shared memory, sockets).

  5. Error Detection: Protect hardware & data.

System Services:

  1. Resource Allocation: Scheduler, memory manager.

  2. Accounting: Track resource usage (CPU time, I/O).

  3. Protection & Security: Access control, authentication.

OS Structure: Monolithic vs. Microkernel

Feature Monolithic Kernel Microkernel
Structure All OS services in kernel space Minimal kernel (IPC, memory, scheduling)
Performance Faster (system calls in-kernel) Slower (IPC for most services)
Flexibility Hard to modify, less secure Easier to extend, more secure
Example Traditional UNIX, Linux QNX, Minix, Mach

Process-Based Kernel: OS services implemented as server processes communicating via IPC. Enhances modularity & fault isolation.


II. PROCESS MANAGEMENT

Process States & PCB

Five-State Model:


New → Ready → Running → Waiting → Terminated

         ↑         ↓

         └─ Medium-term Scheduler (Swapping) ─┘

Process Control Block (PCB): OS's per-process data structure.

  • Fields: Process state, PID, program counter, CPU registers, memory management info, I/O status, accounting info.

  • Significance: Enables context switch (saving/restoring state).

CPU Scheduling Algorithms (VERY HIGH FREQUENCY)

Key Criteria:

  • CPU Utilization: % time CPU busy.

  • Throughput: # processes completed / unit time.

  • Turnaround Time: Submission → Completion.

  • Waiting Time: Time in Ready queue.

  • Response Time: First response to request.

Non-Preemptive:

  1. FCFS/FIFO: "First Come First Served". Simple, causes convoy effect.

  2. SJF (Shortest Job First): Minimizes avg. waiting time. Requires knowledge of burst time.

    • Gantt Chart Example: P1(10), P2(1), P3(2) → | P2 | P3 | P1 |

    • Avg. WT = (0 + 0 + 10)/3 = 3.33 ms.

  3. Priority Scheduling: Lower number = higher priority. Can cause starvation → solved by aging (gradually increasing priority of waiting jobs).

Preemptive:

  1. SRTF (Shortest Remaining Time First): Preemptive SJF.

  2. Round Robin (RR): Time quantum (q). Cyclically executes each ready process for ≤ q.

    • Gantt Chart: q=4, P1(10), P2(1), P3(2) → | P1 | P2 | P3 | P1 | P1 | P1 |

    • Avg. WT depends heavily on q (too small → overhead, too large → FCFS).

Multi-level Queue: Ready queue partitioned (e.g., System, Interactive, Batch). Fixed priority between queues. Multi-level Feedback Queue (MLFQ): Multiple queues with different time quanta. Processes move between queues based on behavior (e.g., CPU-bound → lower priority queue).

Threads: User-Level vs. Kernel-Level

Aspect User-Level Threads Kernel-Level Threads
Managed by User-space thread library OS kernel
Implementation In user process (1:1, M:1, M:N models) Kernel creates & schedules
Context Switch Fast (no mode switch) Slower (requires kernel mode)
Blocking Entire process blocks on syscall Only blocking thread blocks
Scheduling User-controlled (cooperative) Kernel-controlled (preemptive)
Example POSIX Pthreads (M:N), Java green threads Windows, Linux (1:1)

Exam Tip: M:1 model (many user threads to 1 kernel thread) is not used in modern general-purpose OS due to blocking issue.

Synchronization: Semaphores & Monitors

Critical Section Problem: Code segment accessing shared resource. Requirements: Mutual Exclusion, Progress, Bounded Wait.

Semaphore: Integer variable with atomic wait() (P) and signal() (V).

  • Binary Semaphore (0/1): Mutual exclusion.

  • Counting Semaphore: Counting resources.


// Binary semaphore for mutual exclusion

semaphore mutex = 1;

wait(mutex);

// Critical Section

signal(mutex);

Monitor: High-level construct. Only one process active in monitor at a time. Uses condition variables (wait(), signal()) for blocking.

  • Example: Dining Philosophers solution using monitor avoids deadlock by limiting concurrent philosophers to 4.

Classical Problems:

  1. Bounded-Buffer (Producer-Consumer): Use two semaphores (empty, full) and one mutex.

  2. Readers-Writers: Prioritize readers (no writers) or writers (no readers).

  3. Dining Philosophers: Solution requires preventing circular wait (e.g., odd/even pick-up order).


III. DEADLOCKS

Necessary Conditions (MUST ALL HOLD)

  1. Mutual Exclusion: Resource non-sharable (e.g., printer).

  2. Hold and Wait: Process holds resource while waiting for another.

  3. No Preemption: Resource released only voluntarily.

  4. Circular Wait: Cycle of processes waiting for each other's resources.

    
    P0 → R0 → P1 → R1 → P2 → R2 → P0
    
    

Handling Methods

Method Strategy Pros Cons
Prevention Negate one condition Guarantees no deadlock Low device utilization
Avoidance Banker's Algorithm Safe state only Requires max claims a priori
Detection & Recovery Allow, then detect High utilization Recovery overhead (terminate/preempt)
Ignorance Assume rare (UNIX) Simple Risk of system hang

Banker's Algorithm (Avoidance):

  • Safety Algorithm: Finds if system is in safe state (exists safe sequence).

    1. Work = Available, Finish[i]=false.

    2. Find i such that Finish[i]=false and Need[i] ≤ Work.

    3. Work = Work + Allocation[i], Finish[i]=true, repeat.

    4. If all Finish[i]=true → SAFE.

  • Resource-Request Algorithm: Checks if request ≤ Need & Available. If yes, pretend allocate & run safety check.

Example: Given Available=(1,5,2,0), Need matrix from Max - Allocation. Safe sequence found? Yes → P0, P3, P4, P1, P2.


IV. MEMORY MANAGEMENT

Contiguous Allocation

  • Fragmentation:

    • Internal: Wasted space within allocated partition (e.g., fixed partition).

    • External: Wasted space between partitions (small holes).

  • Placement Strategies:

    | Algorithm | How it works | Pros | Cons | | :--- | :--- | :--- | :--- | | First-fit | Allocates first hole ≥ size | Fast | Fragmentation | | Best-fit | Allocates smallest hole ≥ size | Minimizes leftover | Slow, causes many small holes | | Worst-fit | Allocates largest hole | Produces large leftover | Slow, high fragmentation |

Paging

  • Mechanism: Divide physical memory into frames, logical memory into pages. Page table maps page# → frame#.

  • Address Translation: Logical Address = Page# + Offset → Physical Address = Frame# + Offset.

  • TLB (Translation Lookaside Buffer): Fast associative cache for page table entries. Hit ratio critical for performance.

  • Protection: Valid/Invalid bit in page table.

  • Sharing: Same physical frame mapped by multiple page tables.

Segmentation

  • Mechanism: Memory viewed as collection of segments (code, data, stack). Each has segment# & offset.

  • Segment Table: Base address & limit for each segment.

  • Advantages over Paging:

    1. User's View: Matches programmer's logical modules.

    2. Protection: Per-segment (read/write/execute).

    3. Sharing: Share entire segment (e.g., library).

    4. Independent Growth: Stack & heap can grow independently.

Paged Segmentation: Segment table points to page tables. Combines benefits (e.g., Intel x86).

Virtual Memory & Demand Paging

Demand Paging: Load pages only when needed (on page fault). Brings pages from disk (swap space) to memory.

  • Benefits: Larger virtual memory, efficient memory use (only needed pages), protection.

Page Replacement Algorithms (VERY HIGH FREQUENCY) Goal: Minimize page faults.

Algorithm Principle Belady's Anomaly? Implementation
FIFO Replace oldest page YES Simple queue
Optimal (OPT) Replace page not used for longest time NO Theoretical (future knowledge)
LRU Replace least recently used NO Approx. with counter/stack

Belady's Anomaly: FIFO can have more page faults with more frames.

Example: Ref string 1,2,3,4,1,2,5,1,2,3,4,5. 3 frames: 9 faults. 4 frames: 10 faults.

Thrashing: CPU spends more time paging than executing.

  • Cause: Under-allocation of frames → high page fault rate.

  • Detection: Working-Set Model (set of pages used in recent time window Δ) or Page Fault Frequency (PFF).

  • Elimination: Working-set strategy (adjust frames per process), PFF (adjust based on fault rate).


V. FILE SYSTEMS

Directory Structures

Structure Description Pros Cons
Single-level All files in one directory Simple Name collision, no grouping
Two-level User directory + master directory No name collision, per-user isolation No subdirectories
Tree-structured Hierarchical (directories contain subdirs) Flexible, familiar Path traversal
Acyclic Graph Shared files/directories (links) Sharing, no cycles Need reference counts for deletion
General Graph Cycles possible (symbolic links) Maximum flexibility Need garbage collection

Disk Space Allocation Methods (VERY HIGH FREQUENCY)

Method Mechanism Advantages Disadvantages
Contiguous File in contiguous blocks Fast sequential I/O, simple External fragmentation, file growth hard
Linked Each block points to next No external frag, file growth easy Slow random access, space for pointers
FAT (File Allocation Table) Array of next-block pointers in memory Fast traversal (FAT cached), no external frag FAT can be large, fragmentation
Indexed All pointers in an index block Fast random access, no external frag Small files waste index block space
Multi-level Indexed (UNIX) Direct, single, double, triple indirect blocks Supports huge files Multiple disk accesses for large files

UNIX File System (UFS/FFS):

  • Inode: Fixed-size metadata structure (permissions, size, timestamps, 15 pointers: 12 direct, 1 single indirect, 1 double, 1 triple).

  • Directory: Maps filename → inode#.

  • Data Blocks: Actual file content.

Windows NTFS:

  • Master File Table (MFT): Relational database. Each file is a record with attributes (filename, data, security descriptor).

  • Directories: B+ trees for fast lookup.

  • Features: Journaling, security descriptors (ACLs), alternate data streams.

UNIX vs. Windows File System Comparison:

Feature UNIX (UFS/FFS) Windows (NTFS)
Metadata Structure Inode (fixed size) MFT record (variable, extensible)
Directory Structure Simple list (inode#) B+ Tree (fast search)
Path Separator / \
Permissions rwx for user/group/others (9 bits) ACLs (flexible, per-user/group)
Journaling Optional (ext3/4, ZFS) Mandatory (NTFS)
Hard Links Yes (multiple dir entries → same inode) Yes (NTFS)
Symbolic Links Yes (special file with path) Yes (NTFS)

VI. I/O SYSTEMS & SECONDARY STORAGE

Synchronous vs. Asynchronous I/O

Synchronous I/O Asynchronous I/O
Process State Blocked until I/O completes Continues execution, notified later
Control Flow Linear Event-driven/callback
Complexity Simpler programming Complex (need completion handling)
Example read() blocks aio_read() returns immediately

Kernel I/O Subsystem Functions (HIGH FREQUENCY)

  1. Scheduling: Queue I/O requests (see Disk Scheduling).

  2. Buffering: Store data temporarily (to cope with speed mismatch).

  3. Caching: Keep copies in fast memory (e.g., disk cache).

  4. Spooling: Overlap I/O of multiple jobs (e.g., printer spooler).

  5. Device Allocation: Manage exclusive access (e.g., open() with O_EXCL).

  6. Error Handling: Retry failed I/O, report errors.

Disk Scheduling Algorithms (VERY HIGH FREQUENCY)

Parameters:

  • Seek Time: Move head to cylinder.

  • Rotational Latency: Wait for sector to rotate under head.

  • Transfer Time: Read/write sector.

  • Access Time = Seek Time + Rotational Latency.

Algorithms (Head Movement Calculation):

Given: Head at 143, previous at 125, requests: 86, 147, 91, 177, 94, 150, 102, 175, 130.

Algorithm Order of Service Total Head Movement
FCFS 143→86→147→91→177→94→150→102→175→130 |143-86|+... = ? (Calculate)
SSTF Select closest request Minimizes seek, may starve
SCAN (Elevator) Move to one end, then reverse 143→147→150→175→177→130→102→94→91→86→0
C-SCAN Move to end, jump to start, repeat 143→147→150→175→177→199→0→86→91→94→102→130
LOOK Like SCAN but only to furthest request No travel to end if no requests
C-LOOK Like C-SCAN but only to furthest

Formula: Total movement = Σ |current - next|.


VII. OPERATING SYSTEM SECURITY & PROTECTION

Security Goals (CIA Triad)

  • Confidentiality: Prevent unauthorized disclosure.

  • Integrity: Prevent unauthorized modification.

  • Availability: Ensure service for authorized users.

Protection Mechanisms

  • Access Control Matrix: Rows = domains (users/processes), columns = objects (files), entries = rights (r,w,x).

    
       F1  F2  F3
    
    U1 r*  r   -
    
    U2 -   rw* r
    
    
  • Access Lists: Per-object list of (domain, rights).

  • Capability Lists: Per-domain list of (object, rights). "Capability" = unforgeable token.

  • Protection via Paging: Use protection bits in page table (read-only, execute-only). Ring-based protection (e.g., x86 rings 0-3).


VIII. COMPARATIVE ANALYSIS: UNIX vs. WINDOWS

Memory Management Comparison

Aspect UNIX (Linux) Windows (NT)
Paging 4KB pages, hierarchical page tables 4KB/2MB/1GB pages, multi-level PT
Segmentation Minimal (logical segmentation via paging) Segmented (code, data, stack segments)
Virtual Memory Swap partition/file, demand paging Pagefile.sys, demand paging
Frame Allocation Per-process working set Working set + modified page writer

I/O Management Comparison

Aspect UNIX (Device Files) Windows (Device Objects)
Device Model Everything is a file (/dev) Device objects in Object Manager
System Calls open/read/write/ioctl CreateFile/ReadFile/DeviceIoControl
Buffering Buffer cache (page cache) System cache (memory manager)
Driver Model Monolithic kernel modules WDM/WDK (kernel-mode drivers)

File System Comparison (VERY HIGH FREQUENCY)

Feature UNIX (ext4) Windows (NTFS)
Metadata Inode (128 bytes) MFT record (1KB default)
Directory Linear list (inode#) B+ Tree (fast, indexed)
Path Case Case-sensitive (File ≠ file) Case-preserving, case-insensitive
Links Hard links (inode refcount), Soft links Hard links, Symbolic links, Junctions
Journaling Metadata-only (ext3/4) Full (metadata + data)
Security rwx for u/g/o, setuid/gid ACLs (allow/deny, inheritance)
Max File Size 16TB (ext4) 16EB (NTFS)

IX. SYSTEM CALLS (API to OS)

Categories with Examples

Category Purpose Key System Calls
Process Control Create, manage processes fork(), exec(), wait(), exit(), getpid(), kill()
File Management File operations open(), close(), read(), write(), lseek(), stat(), ioctl()
Directory Management Directory ops mkdir(), rmdir(), link(), unlink()
Device Management Device I/O ioctl(), read(), write() (device files)
Communication IPC pipe(), shmget()/shmat(), msgsnd()/msgrcv(), semget()/semop()
Protection Change access chmod(), chown()

Key File Management Calls:

  • open(path, flags, mode): Returns file descriptor.

  • read(fd, buffer, count): Bytes from file to buffer.

  • write(fd, buffer, count): Bytes from buffer to file.

  • lseek(fd, offset, whence): Reposition file offset.

  • stat(path, &buf): Get file metadata (size, permissions).

  • ioctl(fd, request, argp): Device-specific control (e.g., terminal settings).


X. FREQUENTLY ASKED SHORT NOTES (From Past Papers)

Overlay

  • Concept: Load only necessary parts of a large program into memory. Programmer specifies overlay structure.

  • Usefulness: Allows execution of programs larger than physical memory by swapping modules in/out.

  • Modern Equivalent: Demand paging & virtual memory (automated overlaying).

Asynchronous I/O

  • Process issues I/O request and continues execution.

  • OS signals/completes via callback, signal, or polling.

  • Advantage: No blocking, better CPU utilization.

  • Disadvantage: Complex programming (concurrency issues).

Real vs. Virtual Concurrency

  • Real Concurrency: Multiple processors/cores truly executing simultaneously.

  • Virtual Concurrency: Single CPU rapidly context-switching between processes (time-sharing), appearing concurrent.

Dynamic Linking & Loading

  • Dynamic Loading: Load routine into memory only when called (reduces memory use).

  • Dynamic Linking: Link libraries at load time or runtime (shared libraries: .so, .dll).

    • Advantages: Saves disk/memory, easy updates.

    • Disadvantages: "DLL Hell", runtime overhead.

Disk Space Allocation: Indexed (Detailed)

  • Single Indexed: All pointers in one index block.

    • Example: 512-byte blocks, 4-byte pointers → 128 pointers → 64KB file max.
  • Multi-level Indexed (UNIX):

    • Direct pointers (12) → 12 blocks.

    • Single indirect → 1 block of pointers → 1024 blocks (512KB).

    • Double indirect → 1 block → 1024 pointer blocks → 1M blocks (512MB).

    • Triple indirect → huge files.

  • Linked Indexed (FAT): Chain of pointers stored in separate table in memory.

Kernel I/O Subsystem

  • Components: Device drivers, device-independent I/O software, user-level I/O libraries.

  • Functions: (See Section VI.II above).

  • Structure: Device driver registers with kernel, provides entry points. Kernel uses uniform interface (e.g., read()).


Final Exam Strategy:

  1. For 7-mark questions: Define → Explain mechanism → Give example/diagram → Compare/contrast if applicable.

  2. For calculation questions (Scheduling, Page Faults, Disk Movement): Always draw Gantt chart or table. Show step-by-step.

  3. For comparison questions: Use tables (UNIX vs Windows, User vs Kernel threads).

  4. Key Formulas to Remember:

    • Avg. Waiting Time = Σ(Waiting Time) / n

    • Avg. Turnaround Time = Σ(Turnaround Time) / n

    • Page Fault Rate = Page Faults / Total References

    • Belady's Anomaly: FIFO page faults increase with frames.

Common Pitfalls:

  • Confusing Preemptive (SRTF, RR) vs Non-Preemptive (SJF, Priority).

  • Forgetting aging solves starvation in priority scheduling.

  • Misapplying Banker's algorithm (Need = Max - Allocation).

  • Confusing Internal (within partition) vs External (between partitions) fragmentation.

  • In UNIX inode, forgetting indirect pointers count toward block count.

  • In disk scheduling, C-SCAN does not reverse direction at end (jumps to start).

\boxed{\text{Master algorithms with calculations, comparisons with tables, and definitions.}}

Go to where you left off?

Quick Add to Notes

Save questions, your own notes and screenshots into notes filed by unit. It takes a free account.

Create free account

Have an account? Log in