FCFS c语言磁盘调度代码
时间: 2023-10-01 15:08:24 浏览: 96
以下是一个简单的 FCFS 磁盘调度算法的 C 语言实现代码:
```
#include <stdio.h>
#include <stdlib.h>
int FCFS(int queue[], int head, int size) {
int time = 0, i, distance = 0;
for(i = 0; i < size; i++) {
distance += abs(head - queue[i]);
head = queue[i];
}
time = distance;
return time;
}
int main() {
int queue[20], head, size, i;
printf("Enter the size of queue: ");
scanf("%d", &size);
printf("Enter the queue: ");
for(i = 0; i < size; i++) {
scanf("%d", &queue[i]);
}
printf("Enter the initial head position: ");
scanf("%d", &head);
int time = FCFS(queue, head, size);
printf("\nTotal Seek Time: %d", time);
return 0;
}
```
这段代码中,我们实现了一个 FCFS 磁盘调度算法,输入磁道请求队列和磁头的初始位置,输出总的寻道时间。在 `FCFS` 函数中,我们遍历整个磁道请求队列,计算每个磁道请求与磁头的距离之和,最后返回总的寻道时间。
阅读全文
相关推荐


















