资源简介
本实验通过编写C#语言的代码实现先来先服务(FCFS),最短作业优先(SJF)、响应比高者优先(HRN)的调度算法。最后在界面上显示出进程在调度过程中的情况。另附上C++的进程调度实验,算法不相同同。

代码片段和文件信息
#include
#include
#include
#include
#include
using namespace std;
#define P_NUM 5 //进程数
#define P_TIME 50//时间片长度
#define MIN -9999 //最小优先级
enum state{
ready //就绪
execute //执行
block //阻塞
finish //完成
};
struct pcb{ //进程控制块结构
char name[4]; //进程名
int priority; //优先级
int cputime; //占用CPU时间
int needtime; //还需要执行的时间
int count;
int round;
state process; //进程状态
pcb * next;
};
pcb * get_process()//获取进程信息
{
pcb *q;
pcb *t;
pcb *p;//进程链表头指针
int i=0;
cout<<“input “< while (i q=(struct pcb *)malloc(sizeof(pcb));
cin>>q->name;
cin>>q->needtime;
q->cputime = 0;
q->priority = P_TIME - q->needtime;//计算优先级
q->round = 0;
q->count = 0;
q->process = ready;
q->next = NULL;
if (i==0) //第一个pcb
{
p = q;
t = q;
}
else
{
t->next = q;
t = q;
}
i++;
} //while
return p;
}
void display(pcb *p){
cout<<“NAME“<<“ “<<“CPUTIME“<<“ “<<“NEEDTIME“
<<“ “<<“PRIORITY“<<“ “<<“STATE“< while(p){
cout<name;
cout<<“ “;
cout<cputime;
cout<<“ “;
cout<needtime;
cout<<“ “;
cout<priority;
cout<<“ “;
switch(p->process){
case ready:cout<<“ready“< case execute:cout<<“execute“< case block:cout<<“block“< case finish:cout<<“finish“< }
p=p->next;
}
}
int process_finish(pcb *q){//判断进程是否均已执行完毕
int bl=1;
while(bl&&q)
{
bl = bl&&(q->needtime==0);
q = q->next;
}
return bl;
}
void cpuexe(pcb *q){
pcb* t=q;
int tp= MIN;
while(q){ //寻找优先级最大的进程
if (q->process!=finish){
q->process=ready;
if(q->needtime==0){
q->process=finish;
}
}
if(tppriority&&q->process!=finish){
tp=q->priority;
t=q;
}
q=q->next;
}
if(t->needtime!=0){ //执行进程t
t->priority-=3;
t->needtime--;
t->process=execute;
t->cputime++;
}
}
void priority_cal()//优先级调度
{
pcb * p;
system(“cls“);//清屏clrscr();
p = get_process(); //获取进程链表
system(“cls“);
int cpu=0;
system(“cls“); //clrscr();
while(!process_finish(p)){
cpu++;
cout<<“cputime:“< cpuexe(p);
display(p);
Sleep(2000);
system(“cls“);
}
cout<<“All processes have finishedpress any key to exit“< getch();
}
void display_menu()//显示菜单
{
cout<<“CHOOSE THE ALGORITHM:“<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 20480 2010-01-06 22:43 Scheduling\bin\Debug\Scheduling.exe
文件 19968 2010-01-06 22:43 Scheduling\bin\Debug\Scheduling.pdb
文件 5632 2005-11-11 22:25 Scheduling\bin\Debug\Scheduling.vshost.exe
文件 20480 2010-01-06 22:43 Scheduling\obj\Debug\Scheduling.exe
文件 19968 2010-01-06 22:43 Scheduling\obj\Debug\Scheduling.pdb
文件 381 2010-01-06 22:49 Scheduling\obj\Scheduling.csproj.FileListAbsolute.txt
文件 10662 2010-01-06 22:39 Scheduling\Program.cs
文件 1191 2009-12-14 10:00 Scheduling\Properties\AssemblyInfo.cs
文件 1954 2009-12-14 10:00 Scheduling\Scheduling.csproj
文件 919 2009-12-14 10:00 Scheduling.sln
目录 0 2009-12-14 10:00 Scheduling\obj\Debug\TempPE
目录 0 2009-12-14 10:14 Scheduling\bin\Debug
目录 0 2010-01-06 22:43 Scheduling\obj\Debug
目录 0 2009-12-14 10:00 Scheduling\bin
目录 0 2009-12-14 10:06 Scheduling\obj
目录 0 2009-12-14 10:00 Scheduling\Properties
目录 0 2010-01-06 22:39 Scheduling
文件 5234 2009-12-14 11:46 schudule.cpp
----------- --------- ---------- ----- ----
106869 18
- 上一篇:C语言 马踏棋盘 完整代码及实验报告
- 下一篇:三维布尔运算算法
相关资源
- 国际象棋的qt源代码
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- Qt5串口通信-windows
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- 新编Windows API参考大全.doc
- windows hook 框架(detours )
- c#与西门子1500通讯
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
评论
共有 条评论