Program to simulate FCFS Disk Scheduling

Share

The most basic disk scheduling algorithm is FCFS. This algorithm handles requests in the order they appear in the disk queue, as the name would imply. Although there is no hunger and all requests are handled in order, the algorithm does not generally offer the fastest service.

#include <stdio.h>
#include <stdlib.h>
int main(){
    int RQ[100], i, n, TotalHeadMoment = 0, initial;
    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);
    for (i = 0; i < n; i++){
        TotalHeadMoment = TotalHeadMoment + abs(RQ[i] - initial);
        initial = RQ[i];
    }
    printf("Total head moment is %d \n", TotalHeadMoment);
    return 0;
}

OUTPUT

Learn about: Operating System

Source code on GitHub: https://github.com/CodewithSudeep/operating-system-c-program

Share
Sudeep Mishra

Sudeep Mishra

Healing

%d bloggers like this: