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
-
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.
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 requestsscanf("%d",&n);for(i=0;i<n;i++){//Enter the sequence of requestscanf("%d",&ReadyQueue[i]);}// Enter initial head positionscanf("%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 queue
ReadyQueue[100], Total head movementTotalHeadMovandinitialfor header positionnfor the size of ready queue,iis a looping variable. - Lines 6 to 13: We take input from the users that is
number of requests,sequence of requestsand initialhead 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.