您的当前位置:首页正文

操作系统实验一选择一个调度算法,实现处理器调度。

来源:九壹网
 操作系统实验一报告

一.实验内容

选择一个调度算法,实现处理器调度。 二.实验目的

在采用多道程序设计的系统中,往往有若干个进程同时处于就绪状态。当就绪状态进程个数大于处理器数时,就必须依照某种策略来决定哪些进程优先占用处理器。本实验模拟在单处理器情况下处理器调度,帮助学生加深了解处理器调度的工作。 三.实验要求

设计一个按优先数调度算法实现处理器调度的进程。

寻找优先级最高节点

是否最高优先级 Y

N

继续寻找节点 优先数减一 运行时间减一

运 行 时 间 Y

上面的过程只给出了 那个寻找以及排序的大体过程,具体的过程太多画不下。。

按优先级重新排序 删除节点 是否为0 四.实验程序

这个实验的程序使用的visual studio 2008 的c++

win控制台写的,所以可能老师的电脑里面。。。。。。。。。

我把程序结果贴在后面,还有第二题我也做了 ,但只要求

写一个,那么。。

// 操作系统实验.cpp : 定义控制台应用程序的入口点。

//

#include \"stdafx.h\"

#include #include using namespace std; static int num=0; class proc {

private: string procname; proc * next; int time; int priority; char state; public:

proc(){

proc*next=new proc(); { }

~proc(){}

void setnext(proc * n) {

next=n; }

void setprocname(string s){procname=s;}

void settime(int t){time=t;}

}

proc(string pr,proc * ne,int ti,int pri,char st):procname(pr),next(ne),time(ti),priority(pri),state(st)

void setpriority(int s){priority=s;} void setstate(char s){state=s;}

proc * getnext(){return next;}

string getprocname(){return procname;} int gettime(){return time;} int getpriority(){return priority;} char getstate(){return state;} }; class dui {

private:

proc * first; public:

dui(){first=new proc();}

dui(proc*f){ first=f;}

int getfirst_time(){return first->gettime();} void show(proc*p) {

cout<<\"名字 \"<<\"下个节点的名字\"<<\" \"<<\"时间 \"<<\"优先级 \"<<\"状态\"<cout<getprocname ()<<\" \"<<((p->getnext()!=NULL)?p->getnext

()->getprocname ():\"NU\")<<\" \"<gettime ()<<\" \"<getpriority()<<\" \"<<((p->gettime ()!=0)?p->getstate():'E')<} {

proc*pp=first;

show(first);

while( first->getnext ()!=NULL) { }

cout<<\"...............................................................\"<p=p->getnext ();

void process1()

proc*pp_next=pp->getnext (); int a,b;

a=pp->getpriority()-1; b=pp->gettime()-1; pp->setpriority(a); pp->settime(b); if(b==0) { }

int prio1,prio2;

prio2=first->getnext ()->getpriority(); prio1=pp->getpriority();

show(pp); pp =first=first->getnext (); continue;

if(prio1>=prio2)

{show(pp); } else { }

if(prio1>=prio2) {

pp->setnext (first->getnext ()); first->setnext (pp);

show(pp_next); first=first->getnext (); if(first->getnext ()==NULL) { }

else prio2=first->getnext ()->getpriority();

first->setnext (pp); pp->setnext (NULL); break; {

while(prio1}

if(pp->getnext ()==NULL)

{show(pp_next); } pp=pp_next;first=pp; }

} }; int main() {

proc * A=new proc(\"p1\",NULL,2,1,'R');

}

if(first->getnext ()==NULL)

while(first->gettime()>0) {int t=first->gettime()-1;

first->settime(t);show(first); cout<<\"五\"; }

proc * B=new proc(\"p2\",NULL,3,5,'R'); proc * C=new proc(\"p3\",NULL,1,3,'R'); proc * D=new proc(\"p4\",NULL,2,4,'R'); proc * E=new proc(\"p5\",NULL,4,2,'R');

B->setnext (D); D->setnext (C); C->setnext (E); E->setnext (A); dui aaa(B); }

五.实验结果

//aaa.setfirst (B); aaa.process1 (); cin.get();

return 0 ;

六.实验总结

这个说来惭愧啊 ,因为自己的这个程序早就做好了,就是对进程啊什么的还不是很了解,因为自己不是学习认真的那一种,这个老师的那些问题把我给郁闷了好多天啊!悲剧!

以后还是要好好学习,课后不能再玩得那么狠了! 通过这个程序,我体会到了些程序前先把图给画出来是都么好的习惯啊!以后要多多用! 还有我的电脑因为不知道什么病毒,c盘重还原了一下,原来在桌面的那个报告比这个更详细,这次因为不能上传加上自己没有保存就丢失了那个报告,临时写的这个希望老师不要怪我!!

最后希望老师弄一下,最起码我们可以在机房里上传到ftp中!!!

因篇幅问题不能全部显示,请点此查看更多更全内容

Top