First Come First Serve (FCFS) Disk Scheduling

 

First Come First Serve (FCFS) Disk Scheduling

Aim

To implement the FCFS disk scheduling algorithm and compute the total head movement.


Objective

  • To understand how disk requests are serviced in arrival order

  • To calculate total seek time and head movement

  • To study performance compared with other algorithms


Theory

First Come First Serve (FCFS) is the simplest disk scheduling algorithm.
In this method, the disk head services requests in the exact order they arrive in the queue.

  • No reordering of requests

  • Works like a normal queue (FIFO)

  • Fair and easy to implement

Working Principle

  1. Start from the initial head position.

  2. Move to the first request in the queue.

  3. Then move to the next request in sequence.

  4. Continue until all requests are completed.

Seek Time Formula

Seek Time=Current TrackNext TrackSeek\ Time = |Current\ Track - Next\ Track|
Total Head Movement=Difference between consecutive tracksTotal\ Head\ Movement = \sum |Difference\ between\ consecutive\ tracks|

Algorithm

  1. Read number of disk requests n.

  2. Read the request queue.

  3. Read the initial head position.

  4. Set total head movement = 0.

  5. For each request in order:

    • Calculate distance = |current head − request|.

    • Add distance to total movement.

    • Move head to that request.

  6. Display total head movement.


Program (C Example)

#include <stdio.h> #include <stdlib.h> int main() { int n, head, total = 0; printf("Enter number of requests: "); scanf("%d", &n); int req[n]; printf("Enter the requests:\n"); for(int i = 0; i < n; i++) scanf("%d", &req[i]); printf("Enter initial head position: "); scanf("%d", &head); printf("\nStep\tFrom\tTo\tMovement\n"); printf("--------------------------------\n"); for(int i = 0; i < n; i++) { int movement = abs(head - req[i]); printf("%d\t%d\t%d\t%d\n", i+1, head, req[i], movement); total += movement; head = req[i]; } printf("--------------------------------\n"); printf("Total head movement = %d\n", total); return 0; }

Sample Input

Number of requests = 8 Request queue = 98 183 37 122 14 124 65 67 Initial head = 53

Sample Run

Step    From    To    Movement
1    53    98        45
2    98    183        85
3    183    37        146
4    37    122        85
5    122    14        108
6    14    124        110
7    124    65        59
8        65    67        2

Total Head Movement = 640 tracks



Advantages

  • Very simple to implement

  • Fair scheduling (no starvation)

  • Low overhead


Disadvantages

  • High seek time

  • Poor performance compared to SSTF, SCAN, etc.

  • Causes long waiting time for some requests



Result

The FCFS disk scheduling algorithm was implemented successfully and total head movement was calculated.

Comments

Popular posts from this blog

Operating Systems OS Lab PCCSL407 Semester 4 KTU BTech CS 2024 Scheme - Dr Binu V P

Exploring the /proc file system

FCFS First Come First Serve - CPU Scheduling