Wednesday 28 November 2012

FIFO Disk sheduling algorithm

//FIFO-Disk sheduling implementation
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

int request[100],cylinders,st;
int total=0,i,temp,n=0;

void main()
{
 clrscr();
 printf("\nEnter no. of cylinders in disk:");
 scanf("%d",&cylinders);
 printf("Enter starting cylinder:");
 scanf("%d",&st);
 printf("\nEnter the cylinders requested (-999 to break): \n");
 while(1)
 {
  scanf("%d",&temp);
  if (temp==-999) break;
  request[n]=temp;
  n++;
 }
 printf("\nThe requests are : \n");
 for(i=0;i<n;i++)
 printf(" %d" ,request[i]);
 printf("\n\n The traversal is shown below : \n\n%d",st);
 for(i=0;i<n;i++)
 {
  printf("-->%d",request[i]);
  total=total+abs(request[i]-st);     //abs provide difference in +ive always
  st=request[i];
 }
 printf("\n\nNo. of cylinders traversed : %d",total);
 getch();
}
//program written by Mars. 28/11/2011. OS lab.

No comments:

Post a Comment

You are welcome, your comment helps me to make this blog more better.