设计并实现一个模拟进程状态转换及其相应PCB组织结构变化的程序.pdf
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
设计并实现一个模拟进程状态转换及其相应PCB组织结构变化的程序.pdf 本实验的目的是通过设计并实现一个模拟进程状态转换及其相应PCB组织结构变化的程序,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容和组织的变化,理解进程与其PCB间的一一对应关系。 实验要求: 1. 设计并实现一个模拟进程状态转换及其相应PCB组织结构变化的程序。 2. 独立设计、编写、调试程序。 3. 程序界面应能反映出在模拟条件下,进程之间状态转换及其对应的PCB组织的变化。 进程状态模型可以自行选择,如三状态、五状态、七状态等。编写代码时要规范,要适当地加入注释。鼓励在实验中加入新的观点或想法,并加以实现。认真进行预习,完成预习报告。实验完成后,要认真总结,完成实验报告。 程序流程图: 1. 开始初始化等待和阻塞队列。 2. 等待队列为空?是结束否。 3. 等待队列首个进程进入运行队列,显示所有队列信息。 4. 是否阻塞?否,运行进程消耗一个时间片。 5. 运行进程否,运行进程进入等待队列。 6. 是,正在执行进程进入阻塞队列。 7. 运行队列清空等待队列进程数小于4?是阻塞队列首个进程进入等待队列。 程序源代码: #include<iostream> #include<queue> #include<windows.h> using namespace std; struct process{ int id; int hp; process(){} process(int a,int b){id=a;hp=b;} }; queue<process> re,bl,ru; int main(){ void show(queue<process> re,queue<process> ru,queue<process> bl); process p1(1,2),p2(2,1),p3(3,1),p4(4,3),p5(5,2),p6(6,1); re.push(p1); re.push(p2); re.push(p3); bl.push(p4); bl.push(p5); bl.push(p6); process x; char ch; int n; cout<<"初始化中."<<endl; Sleep(2000); cout<<"."<<endl; Sleep(2000); cout<<"."<<endl<<endl; show(re,ru,bl); cout<<endl<<"开始执行!"<<endl<<endl; while(!re.empty()){ x=re.front(); re.pop(); ru.push(x); x=ru.front(); show(re,ru,bl); cout<<endl<<"是否阻塞?(y/n)"<<endl; ch=getchar(); getchar(); if(ch=='y'){ x=ru.front(); ru.pop(); bl.push(x); }else if(ch=='n'){ x.hp--; ru.front().hp=x.hp; if(x.hp!=0){ x=ru.front(); ru.pop(); re.push(x); }else ru.pop(); }else cout<<"输入有误"<<endl; n=re.size(); while(n<4){ if(bl.empty())break; x=bl.front(); bl.pop(); re.push(x); n++; } } return 0; } void show(queue<process> re,queue<process> ru,queue<process> bl){ cout<<"运行任务:"; process y; if(ru.empty())cout<<"空"<<endl; else{ y=ru.front(); ru.pop(); cout<<y.id<<"("<<y.hp<<")"<<endl; } cout<<"队列中的任务:"; if(!re.empty()){ while(!re.empty()){ y=re.front(); re.pop(); cout<<y.id<<"("<<y.hp<<") "; } }else cout<<"空"; cout<<endl<<"阻塞中的任务:"; if(!bl.empty()){ while(!bl.empty()){ y=bl.front(); bl.pop(); cout<<y.id<<"("<<y.hp<<") "; } }else cout<<"空"; cout<<endl; } 实验总结: 通过本实验,学生可以理解进程的概念、进程之间的状态转换及其所带来的PCB内容和组织的变化,理解进程与其PCB间的一一对应关系。同时,学生也可以获得编写模拟进程状态转换程序的经验,并且学会使用队列数据结构和结构体来实现进程管理。
- 粉丝: 64
- 资源: 5万+
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助