操作系统之进程调度
2012-02-07 14:40
204 查看
编写并调试一个模拟的进程调度程序,采用“最高优先数优先”调度算法对五个进程进行调度。
运行结果:
#include <iostream> #include <algorithm> #include <vector> using namespace std; class process { private: char name; int ntime; int utime; bool state; public: int prio; process() { } void init() { utime=0; state=true; cout<<"请分别输入进程的名字,优先级,所需时间"<<endl; cin>>name>>prio>>ntime; // cout<<endl; } bool run() { utime=utime+1; prio=prio-1; cout<<name<<"\t"<<prio<<"\t"<<utime<<"\t"<<endl; if(ntime==utime) state=false; return state; } void wait() { prio=prio+1; } void prn() { cout<<name<<"的状态:优先级是 "<<prio <<". 所需时间是 "<<ntime<<"."<<endl; } }; int cmp(const process & a,const process & b) { if(a.prio<b.prio) return 1; else return 0; } int main() { vector <process> vp; process p[5]; for(int i=0;i<5;i++) { p[i].init(); vp.push_back(p[i]); } for(i=0;i<5;i++) p[i].prn(); cout<<"进程名\t优先级\t已用时间\t"<<endl; while(!vp.empty()) { sort(vp.begin(),vp.end(),cmp); for(i=0;i<vp.size()-1;i++) { vp[i].wait(); } if(!vp.back().run()) vp.pop_back(); } return 1; }
运行结果:
相关文章推荐
- 操作系统——进程调度模拟程序
- 【操作系统】进程调度及其算法
- 操作系统用C语言模拟基于时间片进程调度程序
- 操作系统中进程调度策略有哪几种
- QNX驱动开发——操作系统之进程调度和进程通信
- 读书笔记-现代操作系统-2进程与线程-2.4调度
- 操作系统:进程调度算法详解之FCFS和SPF篇
- 操作系统进程调度算法(Java 实现)
- 【操作系统】进程调度算法
- 操作系统进程调度(FCFS)算法
- 读书笔记-现代操作系统-7多媒体操作系统-7.5多媒体进程调度
- 操作系统内存,磁盘调度,进程调度算法
- Java模拟操作系统进程调度算法—先来先服务、短作业优先、高响比优先
- 操作系统-进程调度之模拟SJF
- 0512操作系统之进程调度
- 操作系统---实验三 进程调度模拟程序
- 操作系统进程调度算法 先到先服务 短作业 优先级 时间片轮转
- 进程调度1 读操作系统概念第六版
- 操作系统中常用到的进程调度算法
- Linux内核分析——操作系统进程调度