计算机操作系统——先到先服务算法(C#)
什么是先到先服务
如果早就绪的进程排在就绪队列的前面,迟就绪的进程排在就绪队列的后面,那么先来先服务(FCFS: first come first service)总是把当前处于就绪队列之首的那个进程调度到运行状态。也就说,它只考虑进程进入就绪队列的先后,而不考虑它的下一个CPU周期的长短及其他因素。FCFS算法简单易行,是一种非抢占式策略,但性能却不大好。
周转时间以及带权周转时间
周转时间=作业完成时刻—作业到达时刻;
带权周转时间=周转时间/服务时间;
平均周转时间=作业周转总时间/作业个数;
平均带权周转时间=带权周转总时间/作业个数;
流程图
源代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 先来先服务
{
class FCFS
{
int n;//进程数
string []name=new string[100];//进程名
int []Arrival=new int [100]; //到达时间
int[] Go = new int[100]; //运行时间
int[] Start = new int[100]; //开始时间
int[] End = new int[100]; //结束时间
int []Timer=new int[100]; //周转时间
float[] DTimer = new float[100];//带权周转时间