Header Ads Widget

C-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 compaired to the FCFS
  2. Less waiting time and response time 
  3. Increase throughput.
Disadvantage:-
  1. starvation occurred


  C      C++      Python  


#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
// logic for sstf disk scheduling
/* loop will execute until all process is completed*/
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(RQ[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
TotalHeadMoment=TotalHeadMoment+min;
initial=RQ[index];
// 1000 is for max
// you can use any number
RQ[index]=1000;
count++;
}
printf("Total head movement is %d",TotalHeadMoment);
return 0;
}


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:-

Key Points;-

Hackerrank:-


C-tutorial:-

See more:-



Post a Comment

2 Comments

  1. Sir very amazing programming code

    ReplyDelete
  2. Thanks for sharing. Can improve the time complexity to logarithmic. See https://jzleetcode.github.io/posts/elevator-shortest-path/#shortest-seek-time-first-ssts-disk-seek-algorithm

    ReplyDelete