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


  C++      C      Python  

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int RQ[100],i,n,TotalHeadMoment=0,initial,count=0;
    cout<<"Enter the number of Requests\n";
    cin>>n;
    cout<<"Enter the Requests sequence\n";
    for(i=0;i<n;i++)
     cin>>RQ[i];
    cout<<"Enter initial head position\n";
    cin>>initial;
   
    // logic for sstf disk scheduling
   
        /* loop will execute until all process is completed*/
    while(count!=n)
    {
        int min=INT_MAX,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];
       
        RQ[index]=INT_MAX;
        count++;
    }
   
    cout<<"Total head movement is "<<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:-

Post a Comment

0 Comments