当前位置:文档之家› 操作系统 优先级调度算法实验报告

操作系统 优先级调度算法实验报告


【实验小结】
本实验难度不小,但关键在于对算法的理解,同时注意看好 实验题目要求以节省时间和精力。另外一定的数据结构基础也 是必需的。
head_run->runtime-=10; head_run->pro++; struct PCB *p1,*p2; printf("Time slice is %d",current); current+=10; printf(" %s starts\n",head_run->pname); printf("Time slice is %d",current); printf(" %s ends\n",head_run->pname); if(head_run->runtime<=0)
if(readydata()==0) return 0;
else runprocess(); }
}
void Init() {
head_input=new PCB; head_input->next=NULL; current=0; int numpro; printf("请输入要建立的进程数:\n\n"); scanf("%d",&numpro); printf("please input the information of the processes\n"); printf("process 进程名******运行时间******权值\n"); for(int i=0;i<numpro;i++) {
if(p1->pro<maxpro) { maxpro=p1->pro; head_run_pre=p2; pmax=p1; } p2=p1; p1=p1->next;
} head_run=pmax; head_run_pre->next=head_run->next; return 1; } void runprocess() //运行进程函数 {
{//判断进程是否运行结束
// delete(*head->run); } else { p1=head_input; p2=head_input->next; p1->next=head_run; head_run->next=p2; }
} int readyprocess() {
while(1) {
学号
专业
姓名
实验日期 2010.11.18 教师签字

实验报告
成绩
【实验名称】设计一个按优先级调度的算法 【实验目的】1、理解按优先级调度算法的内涵, 并熟练掌握该算法。
2、学会采用动态优先级调度算法模拟处理 cpu的进程调度过程。 【实验流程图】
【实验内容】
#include <stdio.h> #include <conio.h> #define N 20 struct PCB//进程控制块定义 { char pname[N]; int pro; char state; int runtime; struct PCB *next; }; struct PCB *head_input; struct PCB *head_run; struct PCB *head_run_pre; unsigned long current; //记录系统当前时间的变量
//-----定义建立就绪队列函数-------
int readydata() //建立就绪队列函数 {
if(head_input->next==NULL) {
return 0; } struct PCB *p1=head_input->next,*pmax,*p2; int maxpro=0xffff; pmax=p1; p2=head_input; //head_run_pre=head_input; while(p1!=NULL) {
//printf("please input the %d-th process's information:\n",i+1); struct PCB *p1=new PCB; scanf("%s",p1->pname); scanf("%d",&p1->runtime); scanf("%d",&p1->pro); p1->state='C'; p1->next=NULL; struct PCB *p2=head_input->next; head_input->next=p1; p1->next=p2; } } int main() { printf("*******xxxxxxxxxxxxxxx********\n\n"); Init(); printf("优先级调度算法运行结果如下:\n"); readyprocess(); return 0; }
相关主题