FCFS DISK SCHEDULING ALGORITHM
The simplest form of disk scheduling is the First Come First Serve (FCFS) Algorithm. This algorithm is intrinsically fair, but it generally does not provide the fastest service queue data structure, where the data element which is added to the queue first, it is the one who issues the first queue. This is used in batch system. It is easy to understand and implement programmatic, using a queue data structure where a new process enters through the tail of queue and the scheduler selects process from the head of queue.
Program:
#include<stdio.h>
#include<conio.h>
int main()
{
int t[20],n,i,j,tohm[20],tot=0;
clrscr();
printf("Enter the head positon:");
scanf("%d",&t[0]);
printf("Enter the no.of tracks:");
scanf("%d",&n);
printf("Enter the tracks to be traversed:");
for(i=1;i<=n;i++)
scanf("%d",&t[i]);
for(i=0;i<=n;i++)
{
tohm[i]=t[i+1]-t[i];
if(tohm[i]<0)
tohm[i]=tohm[i]*(-1);
}
for(i=0;i<n;i++)
tot+=tohm[i];
printf("Tracks traversed\tDifference between tracks\n");
for(i=0;i<n;i++)
printf("\t%d\t\t\t%d\n",t[i],tohm[i]);
printf("\t%d\t\t\t0\n",t[i],0);
printf("\ total header movements:%d",tot);
getch();
return 0;
}
No comments:
Post a Comment