操作系统课设-进程调度模拟设计(先来先服务、优先级法)讲解.doc
文本预览下载声明
进程调度struct Node{
int num;
string name;
double run_time;
double arrive_time;
double start_time;
double end_time;
int priority;
double turn;
double turn_weight;
Node *next;
};
其中,num表示进程序号,name表示进程名称,run_time;表示进程运行时间,arrive_time表示进程到达时间,start_time表示进程开始执行的时间,end_time表示进程执行结束的时间,priority表示进程的优先级别(用1、2、3……表示,且越大优先级越高),turn表示该进程的周转时间,即进程结束时间减去进程开始到达时间,turn_weight表示带权周转时间,即进程的周转时间除以进程的运行时间。
2.使用链表储存进程(逆序存储)
Node *PCB_create(){
Node *head;
head=new Node;
head-next=NULL;
int n;
string na;
double r;
double a;
int p;
coutendl 进程号:;
cinn;
cout 进程名:;
cinna;
cout进程运行时间:;
cinr;
cout进程到达时间:;
cina;
cout 进程优先级:;
cinp;
coutendl;
Node *tp;
tp=new Node;
tp-num=n;
tp-name=na;
tp-run_time=r;
tp-arrive_time=a;
tp-priority=p;
tp-next=head-next;
head-next=tp;
while(true){
cout 进程号:;
cinn;
if(n==-1) break;
cout 进程名:;
cinna;
cout进程运行时间:;
cinr;
cout进程到达时间:;
cina;
cout 进程优先级:;
cinp;
coutendl;
Node *tp;
tp=new Node;
tp-num=n;
tp-name=na;
tp-run_time=r;
tp-arrive_time=a;
tp-priority=p;
tp-next=head-next;
head-next=tp;
}
return head;
}
2.2先来先服务算法设计
2.2.1 FIFO进程算法
Node *FIFO(Node *head){
Node *tp=head-next;
Node *FIFO_link=new Node;
Node *temp=new Node;
temp-next=FIFO_link;
FIFO_link-num=tp-num;
FIFO_link-name=tp-name;
FIFO_link-run_time=tp-run_time;
FIFO_link-arrive_time=tp-arrive_time;
FIFO_link-end_time=tp-end_time;
FIFO_link-priority=tp-priority;
FIFO_link-next=NULL;
Node *p=FIFO_link;
tp=tp-next;
int i=0;
while(tp!=NULL) {
Node *q=new Node;
q-num=tp-num;
q-name=tp-name;
q-run_time=tp-run_time;
q-arrive_time=tp-arrive_time;
q-end_time=tp-end_time;
q-priority=tp-priority;
q-next=NULL;
tp=tp-next;
p=temp;
while( p-next!=NULL p-next-arrive_time q-arrive_time){
p=p-next;
}
q-next=p-next;
p-next=q;
}
double time=0;
Node *tp_1=temp-next;
tp_1-st
显示全部