操作系统进程调度先来先服务FCFS
2017-04-16 18:11
246 查看
一,实验的流程图
二,实验代码
注:本代码主要来自豆丁,加入本人的部分修改。。 //本FCFS是用不带都结点的链表完成。当然也可以用其他数据结构 #include<stdio.h> #include<stdlib.h> typedef struct PCB //定义进程控制块 { char ID[3]; //进程号 char name[10]; //进程名 char state; //运行状态 int arrivetime; //进程到达时间 int servicetime; //进程服务时间 int starttime; //进程开始时间 int finishtime; //进程完成时间 float turnaroundtime; //进程周转时间 float weightedturnaroundtime; //进程带权周转时间 struct PCB *next; //指向下一个进程的指针 }pcb; int time; //计时器 int n; //进程个数 pcb *head=NULL,*p,*q; //进程的指针 void run_fcfs(pcb *p1) { time=p1->arrivetime>time?p1->arrivetime:time; p1->starttime=time; printf("\n现在时间是%d,开始云行作业%s\n",time,p1->name); time+=p1->servicetime; p1->state='T'; p1->finishtime=time; p1->turnaroundtime=p1->finishtime-p1->arrivetime; p1->weightedturnaroundtime=p1->turnaroundtime/p1->servicetime; printf("ID 到达时间 开始时间 服务时间 完成时间 周转时间 带权周转时间\n"); printf("%s%6d%10d%10d%8d%10.1f%10.2f\n",p1->ID,p1->arrivetime,p1->starttime,p1->servicetime,p1->finishtime, p1->turnaroundtime,p1->weightedturnaroundtime); } void find_fcfs() //寻找未完成的pcb { int i,j; p=head; for(i=0;i<n;i++) { if(p->state=='F') { q=p; //用q指针把未完成的pcb"摘"下来 run_fcfs(q); } p=p->next; } } void found_fcfs() //获得进程信息并创建进程 { int num; printf("\n进程个数为:"); scanf("%d",&n); for(num=0;num<n;num++) { p=(pcb*)malloc(sizeof(pcb)); printf("请依次输入:\nID 进程名 到达时间 服务时间\n"); scanf("%s\t%s\t%d\t%d",&p->ID,&p->name,&p->arrivetime,&p->servicetime); if(head==NULL) { head=p;q=p;time=p->arrivetime; } if(p->arrivetime<time) time=p->arrivetime; q->next=p; p->starttime=0; p->finishtime=0; p->turnaroundtime=0; p->weightedturnaroundtime=0; p->next=NULL; p->state='F'; q=p; } } void main() { printf("先来先服务模拟算法:"); found_fcfs(); p=head; find_fcfs(); }
**
三,用于测验的结果:
**相关文章推荐
- 《操作系统》 先来先服务FCFS和短作业优先SJF进程调度算法相关计算及实验
- 操作系统进程调度算法图解(FCFS、轮转、SPN、SRT、HRRN、反馈)
- 操作系统进程调度算法 先到先服务 短作业 优先级 时间片轮转
- 操作系统:进程调度算法详解之FCFS和SPF篇
- 操作系统:进程调度算法详解之FCFS和SPF篇
- Java模拟操作系统进程调度算法—先来先服务、短作业优先、高响比优先
- 操作系统进程调度算法图解(FCFS、轮转、SPN、SRT、HRRN、反馈)
- 操作系统FCFS,SJF进程调度(C++)
- Java模拟操作系统进程调度算法—先来先服务、短作业优先、高响比优先
- 操作系统---先来先服务、短进程调度
- 操作系统进程调度算法图解(FCFS、轮转、SPN、SRT、HRRN、反馈)
- 先来先服务FCFS和短作业优先SJF进程调度算法
- 操作系统进程调度(FCFS)算法
- 操作系统进程调度算法 先到先服务 短作业 优先级 时间片轮转
- 操作系统 进程调度之轮换调度(RR调度)
- 操作系统进程调度算法(Java 实现)
- 浅谈操作系统是如何工作的及简单的进程调度的linux实现
- 几个常用的操作系统进程调度算法
- 操作系统---进程调度
- 操作系统——使用动态优先权的进程调度算法的模拟