操作系统模拟实验:单处理机系统的进程调度实验报告.doc

上传人:苏美尔 文档编号:5730242 上传时间:2020-07-25 格式:DOC 页数:6 大小:22.50KB
返回 下载 相关 举报
操作系统模拟实验:单处理机系统的进程调度实验报告.doc_第1页
第1页 / 共6页
操作系统模拟实验:单处理机系统的进程调度实验报告.doc_第2页
第2页 / 共6页
操作系统模拟实验:单处理机系统的进程调度实验报告.doc_第3页
第3页 / 共6页
操作系统模拟实验:单处理机系统的进程调度实验报告.doc_第4页
第4页 / 共6页
操作系统模拟实验:单处理机系统的进程调度实验报告.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《操作系统模拟实验:单处理机系统的进程调度实验报告.doc》由会员分享,可在线阅读,更多相关《操作系统模拟实验:单处理机系统的进程调度实验报告.doc(6页珍藏版)》请在三一文库上搜索。

1、数学与计算机学院 单处理机系统的进程调度 实验报告年级 07 学号 2007429023 姓名 王阳 成绩 专业 信计 实验地点 主楼402 指导教师 王硕 实验项目 单处理机系统的进程调度 实验日期 实验报告要求: 一、 实验目的 1、加深对进程概念的理解,明确进程和程序的区别。2、深入了解系统如何组织进程、创建进程。3、进一步认识如何实现处理机调度。二、实验原理 三、实验要求 1、采用时间片轮转调度算法实现进程调度。2、确定进程控制块的内容,进程控制块的组织方式。3、完成进程创建原语和进程调度原语。4、编写主函数对所做工作进行测试。四、实验结果(程序)及分析#include #define

2、 N 10 /系统中所允许的最大进程数量#define SLOT 5 /时间片大小/进程状态枚举typedef enum Running, /运行状态Aready, /就绪状态Blocking /阻塞状态 ProStatus;/进程控制块typedef struct int name; /进程标识符ProStatus status; /进程状态int ax,bx,cx,dx; /通用寄存器int pc; /程序计数器寄存器int psw; /程序状态字寄存器int next; /指向下一个进程的指针 PCB;/就绪队列指针typedef struct int head; /头指针int tai

3、l; /尾指针 Ready; /模拟寄存器int PSW,AX,BX,CX,DX,PC,TIME;/PCB的静态链表PCB pcbAreaN; /模拟PCB区域的数组int run; /运行状态程序的指针Ready ready; /就绪队列指针 int pfree; /空闲队列的指针/初始化运行状态进程指针void InitRun()run=-1;/初始化就绪状态队列void InitReady()ready.head=ready.tail=-1;/初始化空闲队列void InitFree()int temp;for(temp=0;tempN-1;temp+)pcbAreatemp.next=

4、temp+1;pcbAreatemp.next=-1;pfree=0;/就绪队列出队int PopReady() /返回结点在PCB区域数组的编号int temp;if(ready.head=-1)printf(就绪队列为空,不能出队。n);return -1;temp=ready.head;ready.head=pcbAreatemp.next;if(ready.head=-1)ready.tail=-1;pcbAreatemp.next=-1;return temp;/空闲队列出队int PopFree() /返回结点在PCB区域数组的编号int temp; if(pfree=-1) pr

5、intf(空闲队列为空,不能出队。n);return -1;temp=pfree;pfree=pcbAreatemp.next;pcbAreatemp.next=-1;return temp;/就绪队列入队void PushReady(int x) /x为入队结点的编号int temp;if(ready.head=-1)ready.head=x;ready.tail=x;elsetemp=ready.tail;ready.tail=x;pcbAreaready.tail.next=-1;/创建PCBvoid CreatePCB(int x,PCB pcb) /x为要创建PCB在PCB区域数组的

6、编号pcbAreax.ax=pcb.ax;pcbAreax.bx=pcb.bx;pcbAreax.cx=pcb.cx;pcbAreax.dx=pcb.dx;pcbAreax.name=pcb.name;pcbAreax.next=-1;pcbAreax.pc=pcb.pc;pcbAreax.psw=pcb.psw;pcbAreax.status=pcb.status;/创建进程函数void Create(PCB pcb)int temp;if(pfree=-1)printf(空闲队列为空,不能创建进程。n);return;temp=PopFree();pcb.status=Aready;Cre

7、atePCB(temp,pcb);PushReady(temp);/进程调度函数void Schedule()int temp;if(ready.head=-1)printf(系统内没有进程可以调度。);return;temp=PopReady();pcbAreatemp.status=Running;TIME=SLOT; /恢复CPU现场AX=pcbAreatemp.ax;BX=pcbAreatemp.bx;CX=pcbAreatemp.cx;DX=pcbAreatemp.dx;PC=pcbAreatemp.pc;PSW=pcbAreatemp.psw;run=temp; /将选中的进程赋给

8、运行指针printf(当前运行的程序:n); /输出调度结果printf(进程号:%dn,pcbArearun.name);printf(进程状态:%dn,pcbArearun.status);printf(寄存器内容:nAXtBXtCXtDXtPCtPSWn);printf(%dt%dt%dt%dt%dt%dn,pcbArearun.ax,pcbArearun.bx,pcbArearun.cx,pcbArearun.dx,pcbArearun.pc,pcbArearun.psw);void main()int temp;PCB tmp_pcb;printf(请输入进程号,以负数为结束(进程号应保持唯一)。nn按任意键进入输入模式:);getchar();InitRun();InitReady();InitFree();printf(请开始输入进程号:n);while(1)scanf(%d,&temp);if(temp0)break;tmp_pcb.name=temp;tmp_pcb.ax=temp;tmp_pcb.bx=temp;tmp_pcb.cx=temp;tmp_pcb.dx=temp;tmp_pcb.pc=temp;tmp_pcb.psw=temp;Create(tmp_pcb);printf(n);Schedule();

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1