Header Ads Widget

Python-Program of SSTF (Short seek time first )Disk scheduling Algorithms in operating system (OS).

   What is SSTF disk scheduling:-

                                                        Shortest seek time first (SSTF) algorithm selects the disk I/O request which requires the least disk arm movement from its current position regardless of the direction. It reduces the total seek time as compared to FCFS.

Example:-: Given the following queue -- 95, 180, 34, 119, 11, 123, 62, 64 with the Read-write head initially at the track 50 and the tail track being at 199.




Advantage:-
  1. seek time reduces as compared to the FCFS
  2. Less waiting time and response time 
  3. Increase throughput.
Disadvantage:-
  1. starvation occurred


  Python     C      C++  


import sys

n = int(input("Enter the number of Requests\n"))
RQ =list(map(int,input().split()))
print("Enter the Requests sequence")

initial = int(input("Enter initial head position\n"))

# logic for sstf disk scheduling

count = 0
TotalHeadMoment = 0

# loop will execute until all processes are completed
while count != n:
    mini = sys.maxsize
    d = index = 0
    for i in range(n):
        d = abs(RQ[i] - initial)
        if mini > d:
            mini = d
            index = i

    TotalHeadMoment += mini
    initial = RQ[index]
    RQ[index] = sys.maxsize
    count += 1

print("Total head movement is", TotalHeadMoment)




Output:-


Enter the number of Request
8
Enter Request Sequence
95 180 34 119 11 123 62 64
Enter initial head Position
50
Total head movement is 236



Must Visit:-

Post a Comment

0 Comments