计算机操作系统FIFO先进先出进程调度算法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace优先级进程调度算法
{
public class progress
{
public string jincheng;
public int youxianji;
public int ntime;
public progress(string jincheng, int youxianji, int ntime) {
this.jincheng = jincheng;
this.youxianji = youxianji;
this.ntime = ntime;
}
}
public class diaodu
{
static public int pertime = 10;
public static void Main()
{
diaodu dia = new diaodu();
progress[] pro;
Console.WriteLine("请输入进程的个数:");
int num = Convert.ToInt32(Console.ReadLine());
pro = new progress[num];
for (int i = 0; i != num; i++)
{
Console.Write("请输入进程名:");
string name = Console.ReadLine();
Console.Write("请输入进程优先级:");
int pri = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入进程运行时间:");
int tim = Convert.ToInt32(Console.ReadLine());
pro[i] = new progress(name, pri, tim);
}
dia.print(pro);
}
public void print(progress[] pro)
{
while (true)
{
int k = 0;
int max = pro[0].youxianji;
for (int i = 0; i != pro.Length; i++)
{
if (pro[i].youxianji >= max)
{
max = pro[i].youxianji;
k = i;
}
}
pro[k].youxianji--;
if (pro[k].ntime != 0)
{
Console.Write("就绪的进程为:");
for (int i = 0; i != pro.Length; i++)
if (pro[i].ntime != 0 && i != k)
Console.Write(pro[i].jincheng + '\t');
Console.WriteLine();
}
if (pro[k].ntime >= pertime)
{
if (pro[k].ntime == pertime)
Console.WriteLine("当前运行的进程:{0}运行时间为:{1},进程到达的时间为:{2} 运行结束", pro[k].jincheng, pertime, k + 1);
else
Console.WriteLine("当前运行的进程:{0}运行时间为:{1},进程到达的时间为:{2}", pro[k].jincheng, pertime, k + 1);
pro[k].ntime -= pertime;
}
else if (pro[k].ntime > 0)
{
Console.WriteLine("当前运行的进程:{0}运行时间为:{1},进程到达的时间为:{2} 运行结束", pro[k].jincheng, pro[k].ntime, k + 1);
pro[k].ntime = 0;
}
bool flag = false;
for (int j = 0; j != pro.Length; j++)
{
if (pro[j].ntime != 0)
{
flag = true;
break;
}
}
if (flag == false)
break;
}
}
}
}