UNIT 5: OPERATING SYSTEMS - COMPREHENSIVE NOTES
Based on analysis of RGPV past examination papers (Jun 2025, Jun 2024, Jun 2023, Nov 2023, Dec 2024, Nov 2022, Jun 2022).
1.0 INTRODUCTION & OPERATING SYSTEM OVERVIEW
1.1 Evolution of Operating Systems
-
Batch Processing: Jobs grouped by similar requirements; no user interaction during execution.
-
Multiprogramming: Multiple jobs in memory; CPU switches to another when one waits (I/O). Increases CPU utilization.
-
Time-Sharing: CPU switches rapidly among users (time slices); interactive computing.
-
Parallel OS: Manages multiple CPUs/cores within a single system (SMP).
-
Distributed OS: Collection of independent computers appearing as a single system.
-
Network OS: Provides file/print sharing over a network; users aware of individual machines.
-
Real-Time OS (RTOS): Hard (strict deadlines) or soft (occasional missed deadline) real-time constraints.
-
Mobile OS: Optimized for battery, touch, limited resources (e.g., Android, iOS).
[!TIP] Evolution trend: From no user interaction (batch) to full user interaction (time-sharing) to resource sharing across networks (distributed).
1.2 Functions of an Operating System
-
Process Management: Create/delete processes, scheduling, synchronization, deadlock handling.
-
Memory Management: Allocate/deallocate memory, track usage, handle paging/segmentation.
-
Storage Management: File system management, disk space allocation, free space tracking.
-
I/O System Management: Device drivers, buffering, caching, device independence.
-
Protection & Security: Access control, authentication, security policies.
-
Network Management: Remote resource access, communication protocols.
-
Command Interpreter (Shell): Interface for user commands.
1.3 Characteristics of an Operating System
-
Convenience: Makes system easy to use.
-
Efficiency: Maximizes resource utilization (CPU, I/O, memory).
-
Ability to Evolve: Can adapt to new hardware/software (modular design).
-
Security & Protection: Prevents unauthorized access.
-
Fault Tolerance: Continues operation after hardware/software failures.
-
Portability: Can run on different hardware platforms.
1.4 Services Provided to Users and Applications
| Service | Description |
|---|---|
| Program Execution | Load, run, terminate programs. |
| I/O Operations | Abstract device details; user-level I/O via system calls. |
| File System Manipulation | Create/delete/read/write files/directories. |
| Communications | Inter-process communication (shared memory, message passing). |
| Resource Allocation | Allocate resources (CPU, memory, I/O) among competing processes. |
| Error Detection | Detect hardware/software errors (e.g., memory parity, disk errors). |
| Accounting | Track resource usage per user/process (for billing/statistics). |
| Protection & Security | Prevent interference, unauthorized access. |
1.5 Operating System Structure & Design
-
Layered Approach: OS divided into layers (0: hardware, top: user interface). Each layer uses only lower layers. Advantage: Easier to debug/verify. Disadvantage: Performance overhead due to strict layering.
-
Microkernels: Minimal kernel (only essential functions: IPC, memory management, scheduling). Other services (file system, drivers) run in user space as servers. Advantage: More reliable, portable, secure. Disadvantage: Performance hit due to IPC.
-
Modules (Loadable Kernel Modules): Core kernel + loadable modules (e.g., device drivers). Flexibility without monolithic bloat.
-
Monolithic Kernel: All OS services in kernel space (e.g., traditional UNIX). Advantage: High performance. Disadvantage: Less secure, harder to maintain.
-
Process-Based Kernel Structure: Kernel itself structured as a set of processes (e.g., early Mach). Advantage: Modularity, fault isolation. Disadvantage: Context switch overhead between kernel processes.
1.6 Utility Programs
Common OS utilities:
-
File Management: Copy, move, delete, rename (
cp,mv,rm). -
System Status: Display memory/disk usage (
top,df,ps). -
Text Processing: Editors (
vi,nano), formatters. -
Disk Utilities: Check disk (
chkdsk), defragment. -
Security: Password managers, antivirus.
-
Backup & Recovery: Archive tools (
tar).
2.0 PROCESS MANAGEMENT
2.1 The Process Concept
-
Process vs. Program: Program is passive code; Process is an active execution instance (code + data + resources + PCB).
-
Process States:
-
New: Being created.
-
Ready: Waiting for CPU.
-
Running: Executing on CPU.
-
Waiting/Blocked: Waiting for I/O/event.
-
Terminated: Execution finished.
graph LR New --> Ready; Ready --> Running; Running --> Waiting; Waiting --> Ready; Running --> Terminated; -
-
Process Control Block (PCB): Kernel data structure storing process state.
-
Fields: Process ID, program counter, CPU registers, memory management info, scheduling info, I/O status, accounting info.
-
Significance: PCB is the "process" from OS perspective; context switch = PCB switch.
-
2.2 Process Scheduling
-
Scheduling Queues:
-
Job Queue: All processes in system.
-
Ready Queue: Processes in main memory, ready to run.
-
Device Queues: Processes waiting for I/O devices.
-
-
Schedulers:
-
Long-Term (Job Scheduler): Selects processes from job pool to admit to main memory (controls degree of multiprogramming).
-
Short-Term (CPU Scheduler): Selects ready process to run on CPU (fast, executes frequently).
-
Medium-Term (Swapper): Removes processes from memory (swapping) to reduce multiprogramming level.
-
-
Context Switch: Saving state of running process (into its PCB) and loading state of next process (from its PCB). Overhead: Pure CPU switch time (no useful work).
2.3 CPU Scheduling Algorithms
-
Performance Criteria:
-
CPU Utilization: % time CPU busy.
-
Throughput: # processes completed per unit time.
-
Turnaround Time: Total time from submission to completion (Completion - Arrival).
-
Waiting Time: Total time spent in ready queue (Turnaround - Burst).
-
Response Time: Time from request to first response (for time-sharing).
-
| Algorithm | Description | Preemptive? | Starvation? | Notes |
|---|---|---|---|---|
| FCFS/FIFO | Processes in arrival order. | No | Yes (long jobs) | Convoy effect; simple but poor avg. waiting. |
| SJF/SRTF | Shortest CPU burst first. | SRTF: Yes | Yes (long jobs) | Optimal for avg. waiting time. Requires future burst knowledge. |
| Priority Scheduling | Higher priority runs first. | Yes/No | Yes (low priority) | Priority can be static/dynamic (aging to prevent starvation). |
| Round Robin (RR) | Ready queue as circular queue; fixed time quantum (q). | Yes | No | Fair share; avg. waiting time depends on q. Too large → FCFS; too small → overhead. |
| Multilevel Queue (MLQ) | Multiple ready queues with different priorities/algorithms. | Yes | Possible | Fixed process assignment to queues (e.g., system, interactive, batch). |
| Multilevel Feedback Queue (MLFQ) | Multiple queues with different time quanta; processes move between queues based on behavior. | Yes | No | Balances response time for interactive and throughput for batch. |
Gantt Chart Construction & Calculation Example (SJF Non-Preemptive):
Processes: P1(6), P2(8), P3(7), P4(3) [All arrive at t=0]
Order: P4(3), P1(6), P3(7), P2(8)
Gantt: | P4 | P1 | P3 | P2 |
0 3 9 16 24
-
Waiting Time (WT): P4=0, P1=3, P3=9, P2=16 → Avg WT = (0+3+9+16)/4 = 7
-
Turnaround Time (TAT): P4=3, P1=9, P3=16, P2=24 → Avg TAT = (3+9+16+24)/4 = 13
2.4 Threads
-
Motivation: Traditional process has one thread of control. Threads allow concurrency within a process.
-
Responsiveness: One thread can run while another waits.
-
Resource Sharing: Threads share process resources (code, data, files).
-
Economy: Create/switch threads cheaper than processes.
-
Scalability: Parallelism on multiprocessors.
-
-
User-Level vs. Kernel-Level Threads:
| Feature | User-Level Threads | Kernel-Level Threads |
|---|---|---|
| Management | By user-space thread library. | By OS kernel. |
| Creation/Switch | Fast (no system call). | Slow (system call). |
| Scheduling | User-controlled; kernel unaware. | Kernel schedules each thread. |
| Blocking | Whole process blocks if one thread blocks (system call). | Other threads can run. |
| Multiprocessor | Kernel schedules process on one CPU; user threads cannot run in parallel. | Kernel can schedule threads on multiple CPUs. |
| Examples | POSIX Pthreads (user), Java threads (user). | Windows NT/2000, Linux (CLONE). |
[!TIP] Key difference: Blocking behavior. User threads: one blocking system call blocks entire process. Kernel threads: only blocking thread affected.
2.5 Concurrency
-
Real Concurrency: Multiple processors/cores executing instructions simultaneously.
-
Virtual Concurrency: Single processor rapidly switching between processes/threads, appearing simultaneous.
2.6 System Calls for Process Management (POSIX/Linux)
-
fork(): Creates child process (duplicate of parent). Returns 0 to child, child's PID to parent. -
exec()family (execl,execv, etc.): Replaces current process image with new program. -
wait()/waitpid(): Parent waits for child termination; retrieves exit status. -
exit(): Terminates process; returns status to parent. -
kill(): Sends signal to process (can terminate). -
getpid(),getppid(): Get process/parent IDs.
3.0 PROCESS SYNCHRONIZATION & DEADLOCK
3.1 The Critical-Section Problem
-
Problem: Multiple processes share data/ resources; only one should execute critical section at a time.
-
Requirements:
-
Mutual Exclusion: Only one process in CS at a time.
-
Progress: If no process in CS and others want to enter, decision cannot be postponed indefinitely.
-
Bounded Wait: No process starves; finite wait after request.
-
-
Solutions:
-
Peterson's Algorithm (2 processes): Uses two shared arrays (
flag[],turn). Relies on alternating turns. -
Test-and-Set (Hardware): Atomic instruction
TSL(Test and Set Lock) on a boolean variable. -
Semaphores: Integer variable
Swith two atomic operations:-
wait(S)/P(S): Decrement S; if S < 0, block. -
signal(S)/V(S): Increment S; if S ≤ 0, wake a blocked process. -
Binary Semaphore (Mutex): S = 0 or 1; for mutual exclusion.
-
Counting Semaphore: S ≥ 0; for resource counting.
-
-
Monitors: High-level construct; only one process active in monitor at a time.
- Condition Variables:
wait(c),signal(c)(orc.wait(),c.signal()).waitreleases monitor lock and blocks;signaltransfers lock to waiting process (or sets flag).
- Condition Variables:
-
-
Classic Problems:
-
Producer-Consumer: Bounded buffer. Use semaphores:
empty(count of empty slots),full(count of full slots),mutex(binary for buffer access). -
Reader-Writer: Readers can concurrent; writers exclusive. Use
readcountandwrtsemaphore (or priority solutions). -
Dining Philosophers: 5 philosophers, 5 forks. Solution: Use a semaphore
roomallowing max 4 philosophers to sit, or hierarchical ordering of forks.
-
3.2 Deadlock
-
Definition: A set of processes are deadlocked if each is waiting for an event that can only be caused by another process in the set.
-
System Model: Processes request/release resources (instances of resource types). Resources can be preemptable (CPU) or non-preemptable (printer).
-
Necessary Conditions (All must hold simultaneously):
-
Mutual Exclusion: At least one resource is non-shareable.
-
Hold and Wait: Process holds at least one resource and waits for another.
-
No Preemption: Resources cannot be forcibly taken away.
-
Circular Wait: Circular chain of processes, each waiting for resource held by next.
-
-
Handling Methods:
-
Prevention: Design system to ensure at least one condition never holds.
-
Mutual Exclusion: Not always possible (printers).
-
Hold and Wait: Require processes to request all resources at start (low utilization) or request resources only when holding none.
-
No Preemption: Preempt all resources if a process requests one it cannot get (only for easily saved/restored resources like CPU).
-
Circular Wait: Impose total ordering on resource types; request in increasing order.
-
-
Avoidance: Dynamically check if request leads to unsafe state. Requires maximum claim known in advance.
-
Banker's Algorithm (Multiple Instances):
-
Data Structures:
Available(vector),Max(n x m matrix),Allocation(n x m),Need = Max - Allocation. -
Safety Algorithm: Find a sequence where each process's
Need≤Available+ sum ofAllocationof previous processes. If sequence exists → safe state. -
Resource-Request Algorithm: Check
Request ≤ NeedandRequest ≤ Available. If yes, pretend allocate and run safety check. If safe → grant; else → wait.
-
-
Resource Allocation Graph (RAG) Algorithm (Single Instance): Request edge → claim edge. If graph has no cycle → safe.
-
-
Detection & Recovery:
-
Detection: Periodic check for cycles in Wait-for Graph (RAG reduced by removing all resource instances). For single instance resources, cycle = deadlock.
-
Recovery:
-
Process Termination: Terminate one or more deadlocked processes (choose victim based on priority, resources held, etc.).
-
Resource Preemption: Select victim process, preempt its resources (rollback to safe state), possibly causing starvation.
-
-
-
3.3 Interprocess Communication (IPC)
-
Shared Memory: Processes share a region of memory.
-
Advantage: Fast (no kernel involvement for data transfer).
-
Issues: Requires synchronization (semaphores/monitors); memory protection.
-
-
Message Passing: Processes communicate via
send()andreceive()messages.-
Synchronous (Blocking):
sendblocks until message received;receiveblocks until message available. -
Asynchronous (Non-blocking):
sendreturns immediately;receivemay return immediately or with error. -
Buffering: Zero capacity (sender blocks), bounded capacity (queue), unbounded capacity (sender never blocks).
-
4.0 MEMORY MANAGEMENT
4.1 Background & Basic Concepts
-
Logical (Virtual) vs. Physical Address Space: Logical generated by CPU; physical seen by memory unit. MMU (Memory Management Unit) translates logical → physical.
-
Binding: When address mapping is fixed.
-
Compile Time: Absolute code; must know load address.
-
Load Time: Relocatable code; loader modifies addresses.
-
Execution Time (Dynamic): MMU translates on the fly; allows process to move in memory.
-
-
Dynamic Loading: Load routine only when called (saves memory). OS support not required.
-
Dynamic Linking & Loading: Linking postponed until execution. Stub in code points to linker; first call loads actual module. Shared Libraries (DLLs, .so) use this.
-
Overlays: Only keep in memory the code/data needed at a given time. Manual by programmer; useful for very large programs in limited memory (no OS support needed).
4.2 Contiguous Memory Allocation
-
Single Partition: OS in low memory; user process in high memory (or vice versa). Protection via relocation registers (base, limit).
-
Multiple Partitions (Fixed/ Variable): Memory divided into partitions of varying sizes.
-
Allocation Strategies (for variable partitions):
| Strategy | How it works | Pros | Cons | | :--- | :--- | :--- | :--- | | First-Fit | Allocate first hole ≥ size. | Fast (search from start). | External fragmentation; may leave small holes at start. | | Best-Fit | Allocate smallest hole ≥ size. | Minimizes leftover space. | Slow (full search); causes many small unusable holes. | | Worst-Fit | Allocate largest hole. | Leaves largest leftover (maybe useful). | Slow; can cause large holes to be used quickly. |
-
Fragmentation:
-
Internal Fragmentation: Allocated partition larger than needed (e.g., fixed partitions, paging).
-
External Fragmentation: Total memory enough, but not contiguous (variable partitions). Solved by compaction (expensive; requires dynamic relocation).
-
4.3 Paging
-
Principle: Divide physical memory into fixed-size frames (power of 2, e.g., 4KB). Divide logical memory into same-size pages. Non-contiguous allocation.
-
Address Translation: Logical address =
[page number][page offset]. Page number → Page Table entry (frame number). Frame number + offset → physical address. -
Page Table: Stored in memory. Page Table Base Register (PTBR) points to it. Translation requires two memory accesses → slow. Solved by TLB (Translation Look-aside Buffer): Associative, fast cache of page table entries.
-
Protection: Valid/Invalid bit in PTE (invalid → page fault). Protection bits (R/W/X) in PTE.
-
Paged Segmentation: Combine segmentation (logical view) with paging (physical implementation). E.g., Intel Pentium: segment selector → segment descriptor → linear address → paged to physical.
4.4 Segmentation
-
Principle: Memory management based on user's view (segments: code, data, stack, heap). Variable length.
-
Address Translation: Logical address =
[segment number][offset]. Segment number → Segment Table entry (base, limit). Base + offset → physical address. -
Segment Table: Stored in memory;
STBRpoints to it. Two memory accesses → slow; use TLB for segments. -
Advantages over Paging:
-
More logical to programmer (modules as segments).
-
Easier to share/reallocate segments (protection at segment level).
-
No internal fragmentation (variable size).
-
-
Segmentation with Paging: (e.g., Pentium) Segment table gives linear address space; paging maps linear to physical. Combines benefits.
4.5 Virtual Memory & Demand Paging
-
Concept: Load only parts of process needed into memory. Logical address space can be much larger than physical.
-
Benefits:
-
Efficient memory use (only needed pages in memory).
-
Increased multiprogramming level.
-
No I/O needed to load entire process (faster start).
-
Allows more processes than fit in memory.
-
-
Demand Paging: Page is brought into memory only when a page fault occurs.
-
Page Fault: Access to page not in memory → trap to OS → OS finds free frame (or evicts victim) → reads page from disk (swap space) → updates page table → restarts instruction.
-
Locality of Reference: Processes tend to access a small set of pages repeatedly (temporal/spatial locality). Justifies demand paging.
-
Working Set Model: Set of pages a process has used recently. If working set not in memory → thrashing (spending more time paging than executing).
-
-
Page Replacement Algorithms: When no free frame, select victim page to replace.
| Algorithm | Description | Optimal? | Belady's Anomaly? | | :--- | :--- | :--- | :--- | | FIFO | Replace oldest page (queue). | No | Yes | | Optimal (OPT) | Replace page whose next use is farthest. | Yes (min page faults) | No | | LRU (Least Recently Used) | Replace least recently used page. | Near-optimal | No | | LFU (Least Frequently Used) | Replace least frequently used. | No | No | | NRU (Not Recently Used) | Classify pages by R/M bits; pick random from lowest non-empty class. | Approximation | No |
-
Page Fault Calculation Example (LRU, 4 frames):
Reference string:
1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5Frames: [ ][ ][ ][ ] → PF=1 (load 1) [1][ ][ ][ ] → PF=2 (load 2) [1][2][ ][ ] → PF=3 (load 3) [1][2][3][ ] → PF=4 (load 4) [1][2][3][4] → hit (1) [1][2][3][4] → hit (2) [2][3][4][5] → PF=5 (replace 1, LRU) [2][3][5][1] → PF=6 (replace 4) [2][5][1][2] → hit (2) [5][1][2][3] → PF=7 (replace 5? Actually: [2][5][1][2] → access 3, LRU is 5? Let's compute properly)Total Page Faults = 7 (for this string).
-
-
Belady's Anomaly: For some algorithms (FIFO), increasing number of frames increases page faults for a given reference string.
-
Example (FIFO, reference: 1,2,3,4,1,2,5,1,2,3,4,5):
-
3 frames: Faults = 9
-
4 frames: Faults = 10 (anomaly!)
-
-
-
Allocation of Frames:
-
Fixed Allocation: Each process gets fixed number of frames (e.g., equal, proportional to size). Simple but may not adapt.
-
Variable Allocation: Number of frames varies (based on working set, page fault rate). More complex.
-
Global vs. Local Replacement:
-
Global: Process can replace any frame in system (higher throughput, but can cause thrashing in some).
-
Local: Process replaces only its own frames (isolated, but may not optimize globally).
-
-
4.6 Memory Management in Specific OS
-
UNIX (e.g., BSD):
-
Uses paging with copy-on-write for
fork()(shared pages marked read-only; on write, copy). -
Page Replacement: Modified clock algorithm (second-chance approximation of LRU). Uses
refandmodbits. -
Working Set: Not strictly implemented; uses
v_flagsand aging.
-
-
Windows (e.g., Windows 10/11):
-
Uses demand paging with working set per process.
-
Page Replacement: Modified clock algorithm (similar to UNIX). Uses
referenceanddirtybits. -
Virtual Address Space: 2GB user / 2GB kernel (32-bit); 128TB user / 128TB kernel (64-bit).
-
Page File:
pagefile.syson system drive.
-
5.0 INPUT/OUTPUT (I/O) SYSTEMS
5.1 I/O Hardware
-
Components: I/O device (printer, disk) ↔ Device Controller (with buffer/registers) ↔ I/O Ports (memory-mapped or isolated) ↔ Bus (PCI, USB) ↔ CPU.
-
I/O Techniques:
| Technique | How it works | Pros | Cons | | :--- | :--- | :--- | :--- | | Programmed I/O | CPU executes loop to read/write device register. | Simple. | CPU busy-waits; wasteful. | | Interrupt-Driven I/O | CPU issues I/O command; device controller signals interrupt when ready. CPU handles interrupt (saves context, runs ISR, restores). | CPU free to do other work. | Interrupt overhead per byte/word. | | DMA (Direct Memory Access) | DMA controller transfers data between device and memory without CPU intervention (after setup). CPU interrupted only at end of block. | Efficient for large blocks; minimal CPU overhead. | Complex controller; bus contention. |
5.2 I/O Software & Kernel Subsystem
-
Logical Structure of I/O Function:
-
Device Independence: User programs use generic names (
/dev/sda,LPT1); OS maps to physical devices. -
Naming: Uniform naming (files for devices in UNIX:
/dev/tty). -
Buffering: Copy data to/from temporary memory (kernel buffer) to match device speed or copy semantics.
-
Caching: Keep copies of data in faster memory (e.g., disk cache in RAM).
-
Spooling: Overlap I/O of multiple jobs (e.g., print spooler: jobs queued to disk, printer reads from disk).
-
Error Handling: Device errors reported to OS; may retry or notify user.
-
-
Kernel I/O Subsystem Services:
-
Scheduling: Queue I/O requests (e.g., disk scheduling).
-
Buffering: Manage buffers in memory.
-
Caching: Maintain cache of data.
-
Spooling: Manage spool areas.
-
Device Allocation: Allocate exclusive devices (e.g., tape drive); manage open file tables.
-
Error Handling: Detect and correct errors (soft errors → retry; hard → report).
-
Protection: Prevent unauthorized I/O (e.g., I/O privilege instructions).
-
5.3 I/O Operations & Buffering
-
Synchronous (Blocking) I/O:
read()call blocks process until I/O completes. Simple to program. -
Asynchronous (Non-blocking) I/O:
read()returns immediately; process continues; notified later (signal/callback) when I/O done. Overlaps I/O and computation. -
I/O Buffering:
-
Purpose: Match speed mismatch, copy data, support block/stream semantics.
-
Single Buffer: OS allocates one buffer in kernel space. Process blocked until buffer filled/emptied.
-
Double Buffering (Double Buffering): Two buffers; while one fills, process uses other. Allows pseudo-parallelism.
-
Circular Buffer: Multiple buffers in ring; producer/consumer pointers. Used for streams (audio, video).
-
5.4 I/O Management in Specific OS
-
UNIX:
-
Device Files: All I/O devices appear as files in
/dev.open(),read(),write()on device files. -
Kernel Structure: Device drivers in kernel; character (unbuffered, byte stream) vs block (buffered, block-oriented) devices.
ioctl()for device-specific commands.
-
-
Windows:
-
I/O Manager: Kernel component; provides uniform interface.
-
Device Drivers: Loadable kernel modules (WDM, WDF). Layered: highest level (file system) → intermediate (class driver) → lowest level (hardware-specific).
-
Asynchronous I/O Completion: Uses I/O Request Packet (IRP). Completion via I/O Completion Ports (efficient thread pool model).
-
5.5 System Calls for I/O & File Management
-
open(path, flags): Open file/device; returns file descriptor (fd). -
close(fd): Close descriptor. -
read(fd, buf, nbytes): Read nbytes to buf from fd. -
write(fd, buf, nbytes): Write nbytes from buf to fd. -
lseek(fd, offset, whence): Reposition file offset (seek). -
stat(path, &buf): Get file metadata (size, times, permissions). -
ioctl(fd, request, argp): Device-specific control operations. -
dup(fd): Duplicate file descriptor. -
fcntl(fd, cmd, arg): File descriptor control (set flags, locks).
6.0 FILE SYSTEMS
6.1 File Concepts
-
File Attributes: Name, Identifier (inode number), Type, Location, Size, Protection (rwx), Time/date (create, modify, access).
-
File Operations: Create, Delete, Read, Write, Reposition (seek), Truncate.
-
File Types: Ordinary (regular), Directory (special), Special (block/character device).
-
File Structure: Byte sequence (UNIX), record sequence (fixed/variable), tree (directories).
6.2 Directory Structures
| Structure | Diagram/Description | Pros | Cons |
|---|---|---|---|
| Single-Level | All files in one directory. | Simple. | Name collision; no grouping. |
| Two-Level | Master directory with user directories (per user). | No name collision across users. | No subdirectories; limited grouping. |
| Tree-Structured | Hierarchical (root, directories, subdirectories). | Natural grouping; search by path. | Path traversal needed. |
| Acyclic Graph | Directed acyclic graph; links (shortcuts) to files in other directories. Sharing: Multiple directory entries point to same inode. | Flexible sharing; no duplication. | Cycles possible (need garbage collection); deletion complexity (link count). |
| General Graph | Cycles allowed (hard/soft links). | Maximum flexibility. | Complex traversal; cycles need detection. |
[!TIP] UNIX uses Acyclic Graph with hard links (multiple directory entries to same inode) and soft links (special file containing path to target).
6.3 File System Organization & Allocation Methods
-
Contiguous Allocation: File occupies contiguous set of blocks.
-
Advantage: Simple; sequential access fast; direct access (seek + read).
-
Disadvantage: External fragmentation; difficult to grow files.
-
-
Linked Allocation: Each block has pointer to next.
-
Singly Linked: No external fragmentation; files can grow. Disadvantages: Slow random access (traverse list); space for pointers; reliability (lost pointer → lost file).
-
Clustering: Group blocks into clusters (e.g., 4KB) to reduce pointer overhead.
-
File Allocation Table (FAT): Disk-wide table; each file is linked list of cluster numbers in FAT. Advantage: Fast traversal (FAT cached); Disadvantage: FAT can be large; fragmentation.
-
-
Indexed Allocation: All pointers gathered into index block.
-
Single Index: Index block holds all pointers (e.g., for small files). Disadvantage: Large index block for large files.
-
Multi-level Index: (e.g., UNIX inode): Direct pointers, single indirect, double indirect, triple indirect.
-
Linked Index: Index blocks linked (e.g., NTFS
$INDEX_ALLOCATION). -
Example (UNIX inode): 12 direct pointers (96KB with 4KB blocks), 1 single indirect (16MB), 1 double indirect (4GB), 1 triple indirect (4TB).
-
-
Free Space Management:
-
Bit Vector (Bitmap): 1 bit per block (1=free, 0=allocated). Compact; easy to find contiguous free space.
-
Linked List: Free blocks linked together; often group blocks into chunks.
-
Grouping: First free block contains addresses of many free blocks.
-
Counting: Keep runs of free blocks (like FAT for free space).
-
6.4 File System Implementation
-
File System Structure (Layers):
-
Logical File System: File control blocks (inodes), directory structure, protection.
-
File System Module: File open/close, read/write, allocation, free space.
-
Basic File System: Block allocation, buffers, device drivers.
-
I/O Control: Device drivers, interrupt handling.
-
-
Virtual File Systems (VFS): Purpose: Provide uniform interface to multiple file system types (ext4, NTFS, NFS). Interface:
vnode(virtual inode) with function pointers (v_op). vnode represents a file/directory; operations (lookup,read,write) dispatch to specific FS's methods. -
Directory Implementation:
-
Linear List: Simple; search linear. Used for small directories.
-
Hash Table: Fast lookup; collision handling; used for large directories.
-
6.5 File System Mounting & Protection
-
Mounting: Attach a file system (e.g., partition on disk) to a directory (mount point) in existing file system tree. Remote mounting (NFS) over network.
-
File Protection:
-
Access Types: Read, Write, Execute, Delete, Append.
-
Access Control:
-
ACL (Access Control List): Per-file list of users/groups with permissions.
-
Capabilities: Tokens granting specific access rights (held by process).
-
-
Password Protection: File encrypted with password (rare).
-
6.6 File Systems in Specific OS
-
UNIX (ext2/ext3/ext4):
-
inode: Fixed-size metadata structure (pointers, size, timestamps, link count, block count).
-
Directory: Simple list of
(inode number, filename). -
VFS:
inodeanddentrycaches. -
Journaling (ext3/ext4): Metadata journaling (ext3) or full journaling (ext4) for consistency after crash.
-
-
Windows (NTFS):
-
MFT (Master File Table): Central database; each file is a record (like inode but more flexible). Attributes stored as
$DATA,$STANDARD_INFORMATION, etc. -
Security Descriptor: Per-file ACL.
-
Journaling: LogFile records metadata changes.
-
Features: Compression, encryption (EFS), sparse files, hard/soft links.
-
-
Comparison:
| Feature | UNIX (ext4) | Windows (NTFS) | | :--- | :--- | :--- | | Metadata Structure | Fixed-size inode. | Variable-size MFT records. | | Security | UNIX permissions (uid/gid) + ACLs. | Rich ACLs (permissions, inheritance). | | Journaling | Full (ext4) or metadata (ext3). | Full (metadata + data optional). | | Max File Size | 16TB (4KB blocks). | 16EB (theoretical). | | Max Volume Size | 1EB (theoretical). | 256TB (practical). | | Compression/Encryption| e2fsprogs tools; not native. | Native (NTFS compression/EFS). |
7.0 SECONDARY STORAGE & DISK MANAGEMENT
7.1 Disk Structure & Performance
-
Disk Geometry: Platters → Tracks (concentric circles) → Sectors (blocks, typically 512B-4KB) → Cylinder (same track on all platters).
-
Performance Parameters:
-
Seek Time: Time to move head to correct track (dominant; 2-30ms).
-
Rotational Latency: Time for sector to rotate under head (½ rotation on avg: 3000RPM → 10ms/rev → 5ms avg).
-
Transfer Time: Time to read/write sector (sector size / rotation rate).
-
Access Time: Seek Time + Rotational Latency.
-
Bandwidth: Total bytes transferred per second.
-
7.2 Disk Scheduling Algorithms
-
Goal: Minimize total head movement (seek time).
-
Algorithms (for queue of cylinder requests):
| Algorithm | Description | Example (head=143, prev=125, queue: 86,147,91,177,94,150,102,175,130) | | :--- | :--- | :--- | | FCFS | Serve in arrival order. | 143→86→147→91→177→94→150→102→175→130 → Total = 1295 | | SSTF | Select closest request to head. | 143→147→150→130→125? (prev)→102→94→91→86→177 → Total ≈ 300-400 (varies). | | SCAN (Elevator)| Head moves in one direction to end, then reverses. | 143→147→150→175→177→(end)→130→102→94→91→86 → Total = 326 | | C-SCAN (Circular SCAN)| Head moves in one direction to end, then jumps to start (no service on return). | 143→147→150→175→177→(jump to 0)→86→91→94→102→130 → Total = 326 (same as SCAN here). | | LOOK / C-LOOK | Like SCAN/C-SCAN but only go as far as last request. | 143→147→150→175→177→(reverse)→130→102→94→91→86 → Total = 326 (same). |
- Comparison: SSTF may cause starvation; SCAN/C-SCAN fairer but longer avg. seek than SSTF. C-SCAN has more uniform wait time.
7.3 Disk Management
-
Disk Formatting:
-
Physical Formatting (Low-level): Divide disk into sectors/tracks (done by manufacturer).
-
Logical Formatting: Create file system (write boot block, free space, directories).
-
-
Boot Block: First sector (MBR) contains boot loader; loads OS kernel.
-
Bad Blocks Management: Mark during formatting; OS avoids (e.g.,
badblocksin Linux). Some disks have spare sectors for remapping. -
Disk Space Allocation: Same as file allocation methods (contiguous, linked, indexed). File system uses one of these.
-
Tape Organization:
-
Tracks: Parallel tracks on tape.
-
Blocks: Records grouped into blocks (fixed/variable).
-
Tape Drives: Sequential access only (rewind, fast forward). Advantages: Cheap per GB, portable, archival. Disadvantages: Slow random access; no direct seek.
-
8.0 ADVANCED & SPECIALIZED OPERATING SYSTEMS
8.1 Network Operating Systems vs. Traditional OS
| Feature | Network OS (e.g., Windows Server) | Traditional Standalone OS (e.g., Windows 10) |
|---|---|---|
| Primary Goal | Resource sharing over network. | Single machine resource management. |
| User Awareness | Users aware of network; access remote resources explicitly. | Transparent; network access via file sharing. |
| Communication | Built-in protocols (SMB, NFS). | May have networking stack but not primary. |
| Security | User authentication across network; access control to remote resources. | Local user accounts; remote access via additional services. |
| Examples | Windows Server, Linux with NFS/Samba. | Windows 10, macOS, Ubuntu Desktop. |
8.2 Distributed OS vs. Multiprocessor OS
| Aspect | Distributed OS (e.g., Amoeba, Plan 9) | Multiprocessor OS (SMP, e.g., Linux SMP) |
|---|---|---|
| Architecture | Loosely coupled; independent nodes with network. | Tightly coupled; shared memory, single OS image. |
| Goals | Resource sharing, computation speedup, reliability, communication. | Increased throughput, economy, reliability. |
| Processor Scheduling | Job/process may run on any node; migration possible. | Scheduler distributes threads/processes across CPUs. |
| Memory | Each node has private memory; distributed shared memory (DSM) optional. | Single shared physical memory (UMA/NUMA). |
| Synchronization | Complex (no shared memory); message passing or distributed locks. | Simpler (semaphores, monitors in shared memory). |
| Fault Tolerance | High (nodes can fail independently); graceful degradation. | Lower (single OS image; hardware failure may crash system). |
| Examples | Plan 9, Inferno, distributed kernels (Mach). | Linux SMP, Windows NT multiprocessor, macOS XNU. |
[!TIP] Key Difference: Memory organization. Distributed: no global shared memory (by default). Multiprocessor: global shared memory (physically distributed in NUMA, but single address space).