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
-
No reordering of requests
-
Works like a normal queue (FIFO)
-
Fair and easy to implement
Working Principle
-
Start from the initial head position.
-
Move to the first request in the queue.
-
Then move to the next request in sequence.
-
Continue until all requests are completed.
Seek Time Formula
Algorithm
-
Read number of disk requests n.
-
Read the request queue.
-
Read the initial head position.
-
Set total head movement = 0.
-
For each request in order:
-
Calculate distance = |current head − request|.
-
Add distance to total movement.
-
Move head to that request.
-
-
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
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
Post a Comment