1 / 23
文档名称:

使用动态优先权的进程调度算法的模拟实验.doc

格式:doc   大小:2,117KB   页数:23页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

使用动态优先权的进程调度算法的模拟实验.doc

上传人:布罗奇迹 2022/8/1 文件大小:2.07 MB

下载得到文件列表

使用动态优先权的进程调度算法的模拟实验.doc

相关文档

文档介绍

文档介绍:使用动态优先权的进程调度算法的模拟实验
使用动态优先权的进程调度算法的模拟实验

通过动态优先权算法的模拟加深对进程概念和进程调度过程的理解。

(1)用C语言实现对N个进程采用动态优先权优先算法的ead=temp1;
continue;
}
temp2=head; //temp2为比较结点的直接前驱结点
temp3=temp2->next; //temp3为比较的结点
while(temp3!=NULL && temp3->priority>=temp1->priority) //实现查找的功能
{
temp2=temp3;
temp3=temp2->next;
}
temp2->next=temp1;
temp1->next=temp3;
}
return head;
}
PCB *InsertQueue(PCB *head,PCB *run) //在就绪队列中插入一个结点
{
PCB *temp1,*temp2; //temp1和temp2分别为比较结点的前驱和比较结点
if(head==NULL) //如果就绪队列为空
{
head=run;
head->next=NULL;
}
else if(head->priority < run->priority) //如果插入结点中所保存的数比头结点所保存的数要大,则直接把该结点插入到头结点之前
{
run->next=head;
head=run;
}
else
{
temp1=head; //temp1为比较结点的直接前驱结点
temp2=temp1->next; //temp2为比较的结点
while(temp2!=NULL && temp2->priority>=run->priority) //实现查找的功能
{
temp1=temp2;
temp2=temp1->next;
}
temp1->next=run;
run->next=temp2;
}
return head;
}
main()
{
int num; //num为进程的个数
int alltime=0; //用来保存所有进程需要占用的CPU时间
PCB *head; //head为就绪队列的头指针
PCB *run=NULL; //run为执行进程结点的指针
PCB *block=NULL; //block为阻塞进程的结点
PCB *temp;
printf("请输入进程的个数:");
scanf("%d",&num);
head=CreatQueue(num);
getchar();
temp=head;
while(temp!=NULL)
{
alltime+=temp->alltime;
temp=temp->next;
}
while(alltime > 0)
{
if(head!=NULL)
{
run=head; //把就绪队列中的第一个进程取出来执行
head=head->next; //就绪队列的头指针指向下一个结点
strcpy(run->state,"run"); //状态改为执行
run->next=NULL;
/*显示状态*/
printf("RUNNING PROG:%d\n",run->id); //显示执行进程
printf("READY_QUEUE:"); //显示就绪进程
temp=head;
while(temp!=NULL)
{
printf("->%d",temp->id);
temp=temp->next;
}
printf("\n");
printf("BLOCK_QUEUE:"); //显示阻塞进程
if(bl