Q5Operating System
Question
(a) Discuss the Disk Scheduling Algorithms with examples. (b) Explain the directory structures used in file systems.
Answer
A deep technical exposition on mechanical Hard Disk Scheduling algorithms (FCFS, SSTF, SCAN, C-SCAN), and a thorough breakdown of hierarchical File System Directory structures.
Unlike solid-state SSDs, traditional Hard Disk Drives (HDDs) are massive, violently spinning magnetic platters accessed by a physical, mechanical Read/Write head mounted on an arm. The absolute slowest operation in a computer is physically moving this mechanical arm (Seek Time). If 10 processes simultaneously request data from random tracks on the disk, the OS cannot execute the requests blindly. It must utilize Disk Scheduling algorithms to mathematically optimize the mechanical movement of the arm to prevent hardware degradation.
1. FCFS (First-Come, First-Served)
The requests are executed in the exact chronological order they arrived. - Example: Queue = 98, 183, 37, 122, 14. Head starts at 53. - Execution: Head moves 53 -> 98 -> 183 -> 37 -> 122 -> 14. - Demerit: The mechanical arm violently swings back and forth across the entire disk, resulting in catastrophic Seek Time and mechanical wear.
2. SSTF (Shortest Seek Time First)
The OS mathematically calculates the physical distance from the current head position to all pending requests, and aggressively moves to the absolute closest one. - Merit: Drastically reduces total mechanical movement compared to FCFS. - Demerit (Starvation): If the head is in the middle, and a continuous stream of requests arrives in the middle, requests at the extreme edges of the disk will mathematically starve and never be read.
3. SCAN (The Elevator Algorithm)
The mechanical arm behaves exactly like a building elevator. It starts at one end, sweeps all the way to the absolute physical edge of the disk (Track 0), servicing requests strictly as it passes them. Once it hits the edge, it violently reverses direction and sweeps to the other edge (Track 199). - Merit: Completely eradicates Starvation. Provides mathematically bounded wait times.
4. C-SCAN (Circular SCAN)
A highly aggressive optimization of SCAN. The head sweeps from Track 0 to Track 199, servicing requests. However, when it hits 199, it does NOT service requests on the reverse trip. It violently snaps back to Track 0 without reading anything, and starts sweeping up again. - Merit: Provides mathematically perfect, absolutely uniform wait times for all cylinders.
The OS must mathematically map human-readable file names (like data.txt) to absolute physical disk block addresses. This translation matrix is the Directory.
- 1. Single-Level Directory: All files for all users are dumped into one massive, flat directory. It is mathematically impossible to have two files with the exact same name. Useless for modern systems.
- 2. Two-Level Directory: The OS creates a Master File Directory (MFD), and assigns each User their own User File Directory (UFD). User A can have
data.txtand User B can havedata.txtwithout catastrophic collision. - 3. Tree-Structured (Hierarchical) Directory: The absolute global standard (Windows, Linux, macOS). It mathematically allows users to create infinite sub-directories inside directories. It utilizes Absolute Pathnames (
/root/user/data.txt) and Relative Pathnames (./data.txt), allowing massive, deeply nested organizational architectures. - 4. Acyclic-Graph Directory: A highly advanced evolution of the Tree structure. It mathematically allows a single physical file to exist in multiple directories simultaneously utilizing Hard Links and Symbolic Links (Shortcuts). It violently prevents catastrophic infinite loops by strictly forbidding cycle formations during directory traversal.