Shortest Seek Time First (SSTF) Disk Scheduling

 

Shortest Seek Time First (SSTF) Disk Scheduling

Aim

To simulate the SSTF disk scheduling algorithm and compute the total head movement, displaying Step, From, To, Movement.


Theory

Shortest Seek Time First (SSTF) selects the disk request that is closest to the current head position.

  • Minimizes immediate seek time

  • Improves performance compared to FCFS

  • May cause starvation for far-away requests


Algorithm

  1. Read number of disk requests.

  2. Read request queue.

  3. Read initial head position.

  4. Mark all requests as unvisited.

  5. From current head:

    • Find request with minimum absolute distance

    • Move head to that request

    • Add movement to total

    • Mark request visited

  6. Repeat until all requests are serviced.


Program: SSTF Disk Scheduling (C)

#include <stdio.h> #include <stdlib.h> int main() { int n, head, total = 0; printf("Enter number of requests: "); scanf("%d", &n); int req[n], visited[n]; printf("Enter the requests:\n"); for(int i = 0; i < n; i++) { scanf("%d", &req[i]); visited[i] = 0; } printf("Enter initial head position: "); scanf("%d", &head); printf("\nStep\tFrom\tTo\tMovement\n"); printf("--------------------------------\n"); for(int step = 0; step < n; step++) { int min = 100000, index = -1; for(int i = 0; i < n; i++) { if(!visited[i]) { int dist = abs(head - req[i]); if(dist < min) { min = dist; index = i; } } } printf("%d\t%d\t%d\t%d\n", step+1, head, req[index], min); total += min; head = req[index]; visited[index] = 1; } printf("--------------------------------\n"); printf("Total head movement = %d\n", total); return 0; }

Same Example as FCFS

Input

Number of requests = 8 Queue = 98 183 37 122 14 124 65 67 Initial head = 53

Sample Run (SSTF Order Selection)

Current head = 53

Nearest sequence:

53 → 6567371498122124183


Output Table

Step From To Movement -------------------------------- 1 53 65 12 2 65 67 2 3 67 37 30 4 37 14 23 5 14 98 84 6 98 122 24 7 122 124 2 8 124 183 59 -------------------------------- Total head movement = 236

Observation

Algorithm    Total Head Movement
FCFS        640
SSTF        236

👉 SSTF significantly reduces head movement compared to FCFS.


Result

The SSTF disk scheduling algorithm was successfully simulated.
For the given example, total head movement = 236 tracks, which is lower than FCFS.

Comments

Popular posts from this blog

Operating Systems OS Lab PCCSL407 Semester 4 KTU BTech CS 2024 Scheme - Dr Binu V P

Exploring the /proc file system

FCFS First Come First Serve - CPU Scheduling