0% found this document useful (0 votes)
5 views4 pages

Os 10

This document contains implementations of two disk scheduling algorithms: FCFS (First Come, First Serve) and SCAN. The FCFS algorithm calculates total head movement based on the order of requests, while the SCAN algorithm sorts requests based on their position relative to the current head position and computes the total seek time and average seek time. Both algorithms are implemented in C programming language with user input for current position and request order.

Uploaded by

vinitpatil022004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Os 10

This document contains implementations of two disk scheduling algorithms: FCFS (First Come, First Serve) and SCAN. The FCFS algorithm calculates total head movement based on the order of requests, while the SCAN algorithm sorts requests based on their position relative to the current head position and computes the total seek time and average seek time. Both algorithms are implemented in C programming language with user input for current position and request order.

Uploaded by

vinitpatil022004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

EXPERIMENT NO.

10
FCFS (First Come, first serve) disk scheduling algorithm

#include<math.h>

#include<stdio.h>

#include<stdlib.h>

int main()

int i,n,req[50],mov=0,cp;

printf("enter the current position\n");

scanf("%d",&cp);

printf("enter the number of requests\n");

scanf("%d",&n);

printf("enter the request order\n");

for(i=0;i<n;i++)

scanf("%d",&req[i]);

mov=mov+abs(cp-req[0]); // abs is used to calculate the absolute value

printf("%d -> %d",cp,req[0]);

for(i=1;i<n;i++)

mov=mov+abs(req[i]-req[i-1]);

printf(" -> %d",req[i]);

printf("\n");

printf("total head movement = %d\n",mov);

}
SCAN disk scheduling algorithm:

#include<stdio.h>
int main()
{
int queue[20],n,head,i,j,k,seek=0,max,diff,temp,queue1[20],queue2[20],
temp1=0,temp2=0;
float avg;
printf("Enter the max range of disk\n");
scanf("%d",&max);
printf("Enter the initial head position\n");
scanf("%d",&head);
printf("Enter the size of queue request\n");
scanf("%d",&n);
printf("Enter the queue of disk positions to be read\n");
for(i=1;i<=n;i++)
{
scanf("%d",&temp);
if(temp>=head)
{
queue1[temp1]=temp;
temp1++;
}
else
{
queue2[temp2]=temp;
temp2++;
}
}
for(i=0;i<temp1-1;i++)
{
for(j=i+1;j<temp1;j++)
{
if(queue1[i]>queue1[j])
{
temp=queue1[i];
queue1[i]=queue1[j];
queue1[j]=temp;
}
}
}
for(i=0;i<temp2-1;i++)
{
for(j=i+1;j<temp2;j++)
{
if(queue2[i]<queue2[j])
{
temp=queue2[i];
queue2[i]=queue2[j];
queue2[j]=temp;
}
}
}
for(i=1,j=0;j<temp1;i++,j++)
queue[i]=queue1[j];
queue[i]=max;
for(i=temp1+2,j=0;j<temp2;i++,j++)
queue[i]=queue2[j];
queue[i]=0;
queue[0]=head;
for(j=0;j<=n+1;j++)
{
diff=abs(queue[j+1]-queue[j]);
seek+=diff;
printf("Disk head moves from %d to %d with
seek %d\n",queue[j],queue[j+1],diff);
}
printf("Total seek time is %d\n",seek);
avg=seek/(float)n;
printf("Average seek time is %f\n",avg);
return 0;
}

You might also like