Disk Scheduling-1
Disk Scheduling-1
Disk Scheduling-1
FCFS
Aim
Write a C program to implement FCFS Disk scheduling algorithm.
Algorithm
Step1: Start
Step2: Declare all the necessary variables,Enter the number of
requests,sequence of request and initial head position.
Step 3:Let ReadyQueue represents an array storing indexes of tracks that have
been requested in ascending order of their time of arrival. ‘initial’ is the position of
disk head.
Step4:Let us one by one take the tracks in default order and calculate the
absolute distance of the track from the head.
Step5:Increment the total seek count with this distance.
Step6:Currently serviced track position now becomes the new head position.
Step 7:Go to step 4 until all tracks in request array have not been serviced.
Step 8:Stop the program
Program
#include<stdio.h>
#include<stdlib.h>
int main()
{
int ReadyQueue[100],i,n,TotalHeadMov=0,initial;
printf("Enter the number of requests:");
scanf("%d",&n);
printf("Enter the sequence of request");
for(i=0;i<n;i++)
{
scanf("%d",&ReadyQueue[i]);
}
printf("Enter initial head position");
scanf("%d",&initial);
for(i=0;i<n;i++)
{
TotalHeadMov=TotalHeadMov+abs(ReadyQueue[i]-initial);
initial=ReadyQueue[i];
}
printf("Total Head Movement=%d",TotalHeadMov);
}
SCAN
Aim
Write a C program to implement SCAN Disk scheduling algorithm.
Algorithm
Step1: Start
Step2: Declare all the necessary variables,Enter the number of
requests,sequence of request and initial head position.
Step 3:Let ReadyQueue represents an array storing indexes of tracks that have
been requested in ascending order of their time of arrival. ‘initial’ is the position of
disk head.
Step 4:Sort the request array .
Step 5:Enter the Head movement Direction for high1 and for low 0
Step 6:If Head movement Direction is high then go to step 7 else go to step8
Step 7: Find the total head movement up to the tail end of the disk then move
backward to the first value in the sorted array and return the final total head
movement.
Step8: Find the total head movement up to begin (0) and then move to forward
direction up to the last value in the sorted array and return the final total head
movement.
Step 9:Stop the program
Program
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
}
}
int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
}
}
// if movement is towards low value
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
initial =0;
for(i=index;i<n;i++)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}
C-SCAN
Aim
Write a C program to implement C-SCAN Disk scheduling algorithm.
Algorithm
Step1: Start
Step2: Declare all the necessary variables,Enter the number of
requests,sequence of request and initial head position.
Step 3:Let ReadyQueue represents an array storing indexes of tracks that have
been requested in ascending order of their time of arrival. ‘initial’ is the position of
disk head.
Step 4:Sort the request array .
Step 5:Enter the Head movement Direction for high1 and for low 0
Step 6:If Head movement Direction is high then go to step 7 else go to step8
Step 7: Find the total head movement up to the tail end of the disk then move tail
end to begin and find the remaining head movement in the forward direction up
to remaining values in the sorted array and return the final total head
movement.
Step8: Find the total head movement up to beginning (0)then move to tail end
and move in backward direction up to remaining values in the sorted array and
return the final total head movement.
Step 9:Stop the program
Program
#include<stdio.h>
#include<stdlib.h>
int main()
{
int RQ[100],i,j,n,TotalHeadMoment=0,initial,size,move;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&RQ[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
printf("Enter total disk size\n");
scanf("%d",&size);
printf("Enter the head movement direction for high 1 and for low 0\n");
scanf("%d",&move);
}
}
int index;
for(i=0;i<n;i++)
{
if(initial<RQ[i])
{
index=i;
break;
}
}
}
}
// if movement is towards low value
else
{
for(i=index-1;i>=0;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
// last movement for min size
TotalHeadMoment=TotalHeadMoment+abs(RQ[i+1]-0);
/*movement min to max disk */
TotalHeadMoment=TotalHeadMoment+abs(size-1-0);
initial =size-1;
for(i=n-1;i>=index;i--)
{
TotalHeadMoment=TotalHeadMoment+abs(RQ[i]-initial);
initial=RQ[i];
}
}