Thursday 21 March 2013

scan disk scheduling


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int max,min,disk,mark[100],q[100],rear=0,size,head,seek;
void ins();
void dis();
void clook();
void fmaxmin();
main()
{
int i,ch;
printf("\nEnter the size of the disk (in tracks) : ");
scanf("%d",&disk);
printf("\nEnter the current position of the disk head : ");
scanf("%d",&head);
printf("\nEnter the number of requests : ");
scanf("%d",&size);
if(size!= 0)
printf("\nEnter the requests - : \n\n");
else
{
printf("No requests to be made ");
return;
}
for(i=1;rear<=size;i++)
{
ins();
mark[i] = 0;
}
fmaxmin();
q[0] = head;
printf("\n\n\t\t\t\tDISK SCHEDULING\n\n");
head = q[0];
seek = 0;
clook();
getch();
}
void ins()
{
int i;
rear++;
if(rear<=size)
{
printf("Enter the request %d to track no. : ",rear);
scanf("%d",&i);
}
if(i>disk)
{
printf("\nEnter valid track request\n\n");
rear--;
}
else
q[rear] = i;
}
void dis()
{
int i;
for(i=1;i<=size;i++)
printf("%d\t",q[i]);
}
void clook()
{
int i,j;
printf("\n\n\t\t\t\tCLOOK SCHEDULING\n\n");
printf("\nWORK QUEUE : \n");
dis();
printf("\n\n--------------------------------------------------------------------------------\n");
printf("\nThe sequence is. . .\n\n");
for(j=q[0];j<=max;j++)
{
for(i=1 ;i<=size;i++)
if(j == q[i] && mark[i] == 0)
{
mark[i] = 1;
printf("\nHead moves from %d to %d...",head,q[i]);
seek += abs(head -j);
head = q[i];
}
}
if(head>min)
{
for(j=0;j<=q[0];j++)
{
for(i=1 ;i<=size;i++)
if(j == q[i] && mark[i] == 0)
{
mark[i] = 1;
printf("\nHead moves from %d to %d...",head,q[i]);
seek += abs(head -j);
head = q[i];
}
}
}
printf("\n\nTotal number of head movements is : %d",seek);
}
void fmaxmin()
{
int i;
for(i = 1;i<=size;i++)
{
if(q[i]>max)
max = q[i];
if(q[i]<min)
min = q[i];
}
}

No comments:

Post a Comment

Have some problem with this code? or Request the code you want if you cant find it in Blog Archive.