What is the FCFS disk scheduling algorithm?

Overview

FCFS (First-Come-First Serve) is a disk scheduling algorithm used by the memory-management unit. We know that a disk contains tracksA track is a physical division of data in a disk drive., read-write head, and request queue. We’ll calculate the total number of track movements and look at the working of FCFS:

  • In the FCFS algorithm, there is no starvation since requests are processed immediately.

  • There is a problem with performance because the RW-header doesn’t check the future requests.

Example

Lets consider a disk contain 200 tracks(0-199) and a request queue contains track number [82,170,43,140,24,16,190 ], respectively. The current position of read-write head=50. Find the total number of track movements in cylinders.

FCFS disk scheduling

Code

  • Enter the number of requests: 7
  • Enter the sequence of request:82 170 43 140 24 16 190
  • Enter initial head position:50

Implementation of FCFS Scheduling Algorithm

#include<stdio.h>
#include<stdlib.h>
int main()
{
int ReadyQueue[100],i,n,TotalHeadMov=0,initial;
//Enter the number of requests
scanf("%d",&n);
for(i=0;i<n;i++){
//Enter the sequence of request
scanf("%d",&ReadyQueue[i]);
}
// 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);
}

Enter the input below

Explanation

  • Line 5: We declare the variables that is a ready queueReadyQueue[100], Total head movementTotalHeadMovand initial for header position n for the size of ready queue, i is a looping variable.
  • Lines 6 to 13: We take input from the users that is number of requests,sequence of requests and initial head position.
  • Lines 14 to 18: It is the logic of the code where the requests are served based on FCFS, and based on change of head movement, total requests are served.
  • Line 19: We display the total head movements.

Free Resources