Osexp 8 A
Osexp 8 A
Experiment No : 8 Date :
Disk Scheduling Algorithm
Aim : a) To implement FCFS disk scheduling algorithm.
Theory:
FCFS (First-Come, First-Served)
FCFS is the simplest disk scheduling algorithm. Requests are addressed in the order they
arrive in a queue, without consideration for the disk head’s current position or the distance to
the requested track. It is fair because every request is served in a first-in, first-out manner, but
this can lead to high seek times when requests are scattered across the disk (a phenomenon
known as the "convoy effect").
In cases where requests arrive randomly and frequently, FCFS can cause the disk head to
move large distances unnecessarily, increasing overall response time. Despite this, FCFS is
easy to implement and doesn’t require complex calculations.
Advantages:
• Simple to understand and implement.
• Fair, as each request is serviced in the order it arrives.
• Suitable for low-load systems with minimal random access.
Disadvantages:
• High average seek time when requests are scattered.
• Convoy effect, where the disk head moves inefficiently due to unoptimized scheduling.
• Poor performance in systems with a high number of random requests.
Example:
Assume the disk head is initially at track 50 and there are requests at [40, 10, 90, 60]. Using
FCFS, the disk head would move in this sequence:
• 50 → 40 (seek time = 10)
• 40 → 10 (seek time = 30)
• 10 → 90 (seek time = 80)
• 90 → 60 (seek time = 30)
Total seek time = 10 + 30 + 80 + 30 = 150
Algorithm:
1. Start with the initial disk head position.
2. Serve requests in the order they arrived in the queue.
3. For each request, move the disk head to the requested track and calculate seek time
(absolute difference between current and target track).
4. Repeat until all requests are served.
Aaditya M. Salgaonkar 22B-CO-001 Batch A|
Code:
#include <bits/stdc++.h>
#define N 50
using namespace std;
int FCFS(int headPosition, int totalRequests, int requests[])
{
int seekTime = 0, currentPosition = headPosition;
cout<<currentPosition<<"->";
return seekTime;
}
return 0;
}
Output:
Conclusion:
FCFS disk scheduling algorithm code was studied and implemented in C++ and the seek
sequence was displayed and total seek time was printed at the end.