Tuesday, 15 November 2016

SSTF :Shortest Seek Time First implement in C Program

SSTF :Shortest Seek Time First implement in C Program 

In SSTF (Shortest Seek Time First), requests having shortest seek time are executed first. So, the seek time of every request is calculated in advance in queue and then they are scheduled according to their calculated seek time. As a result, the request near the disk arm will get executed first. SSTF is certainly an improvement over FCFS as it decreases the average response time and increases the throughput of system.

Program:
#include<stdio.h>
void sort(int a[],int n){
int temp,i,j;
for(i=0;i<n;i++){
 for(j=0;j<n-1;j++)
 {
  if(a[j]>a[j+1])
   {temp=a[j];
    a[j]=a[j+1];
    a[j+1]=temp;
   }
 }
}
}
int main()
{
 int i,head,t=0,seek=0,a[20],f,l,n,j;
 printf("\nEnter number of process :");
 scanf("%d",&n);
 printf("\nEnter Range of process :");
 scanf("%d%d",&f,&l);
 printf("\nEnter %d peocess :\n",n);
 for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  printf("\nEnter head position :");
  scanf("%d",&head);
  a[i+1]=head;
  a[i+2]=f;
  a[i]=l;
  n=n+3;
  sort(a,n);
  for(i=1;i<n-1;i++)
  {
   if(a[i]==head)
   {
    for(j=i-1;j>=0;j--)
    {
       t=head-a[j];
       seek=seek+t;
       head=a[j];
    }
    for(j=i+1;a[j]<l;j++)
    {
      t=a[j]-head;
       seek=seek+t;
       head=a[j];
    }
    printf("seek time is %d ",seek);
    return 1;
 
   }
 
 
 
  }



  return 0;


}

Question:



OUTPUT:



FCFS : Disk Scheduling Algorithms in c



Disk Scheduling Algorithm

1. FCFS is the simplest of all the Disk Scheduling Algorithms. In FCFS, the requests are addressed in the order they arrive in the disk queue.
Programe:

#include<stdio.h>
int main()
{
  int head,seek=0,a[100],n,i,t=0;
  printf("\nEnter how many queue you want: ");
  scanf("%d",&n);
  printf("Enter %d  queue : \n",n);
  for(i=0;i<n;i++)
  scanf("%d",&a[i]);
  printf("\nEnter head position: ");
  scanf("%d",&head);
  for(i=0;i<n;i++){
    if(head>a[i])
    {
    t=head-a[i];
    seek+=t;
    head=a[i];
    }
  else if(head<a[i])
    {
    t=a[i]-head;
    seek+=t;
    head=a[i];
    }

  }

  printf("\nSeek time is : %d\n",seek);


}

OUTPUT:


Like on Facebook click here