欢迎来到天天文库
浏览记录
ID:56783639
大小:949.00 KB
页数:14页
时间:2020-07-11
《南昌大学操作系统实验报告材料.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、大学实验报告---(3)进程调度算法的实现学生:皓然学号:5501215001专业班级:本硕151实验类型:□验证□综合■设计□创新实验日期:2017.5.31实验成绩:一、实验目的通过实验加强对进程调度算法的理解和掌握。二、实验容编写程序实现进程调度算法,具体可以编写程序实现优先度高者调度算法或先来先服务算法。三、实验要求1、需写出设计说明;2、设计实现代码及说明3、运行结果;四、主要实验步骤优先度高者调度算法实验代码:#include#include#include#include2、h>#include#defineruntime2#defineoverflow-2#definenull0enumsta{run,wait,finished};//枚举类型sta,标志三种状态time_tt;//systemclockstructblock{inttime_used;intprior;};//定义结构体,使用时间,优先级typedefstructpro{charname[20];enumstastatus;inttime_required;intarrive_time;structblockswitch_block;3、structpro*next;}*pcb;//定义pcb块pcbready;voidmenu();voidinsertpcb(pcbnewp)//插入至就绪队列{pcbp;p=(pcb)malloc(sizeof(structpro));if(!p)exit(overflow);p=ready;if(p->next==null){newp->next=ready->next;ready->next=newp;}else{while(newp->switch_block.priornext->switch_block.prior&&p->next!4、=null)p=p->next;newp->next=p->next;p->next=newp;}}voidcreat_pcb()//创建一个进程{pcbnewp;newp=(pcb)malloc(sizeof(structpro));if(!newp)exit(overflow);newp->status=wait;time(&t);newp->arrive_time=t;printf("processname:");scanf("%s",newp->name);printf("priority:");scanf("%d",&newp->switch_5、block.prior);printf("arrivetime:");scanf("%d",&newp->arrive_time);printf("cputime_required:");scanf("%d",&newp->time_required);newp->switch_block.time_used=0;insertpcb(newp);menu();}voidprintpcb()//打印现状{pcbp;if(ready->next){printf("namestatuspriorityserver_timearrive_timecputime_6、used");for(p=ready->next;p!=null;p=p->next){printf("%s",p->name);switch(p->status){casewait:printf("wait");break;caserun:printf("run");break;casefinished:printf("finished");break;}printf("%7d",p->switch_block.prior);printf("%15d",p->time_required);printf("%20d",p->arrive_time);7、printf("%13d",p->switch_block.time_used);putchar('');}}elseprintf("queueisempty!");}voidswitchprocess()//将存中的进程切换至外存{chartemp[20];pcbp,q;if(ready->next){printf("inputprocessname:");scanf("%s",temp);for(p=ready;p!=null&&strcmp(temp,p->next->name)!=0;p=p->next);if(p!=null){q=p-8、>next;p->next=q->next;printf("remove%ssu
2、h>#include#defineruntime2#defineoverflow-2#definenull0enumsta{run,wait,finished};//枚举类型sta,标志三种状态time_tt;//systemclockstructblock{inttime_used;intprior;};//定义结构体,使用时间,优先级typedefstructpro{charname[20];enumstastatus;inttime_required;intarrive_time;structblockswitch_block;
3、structpro*next;}*pcb;//定义pcb块pcbready;voidmenu();voidinsertpcb(pcbnewp)//插入至就绪队列{pcbp;p=(pcb)malloc(sizeof(structpro));if(!p)exit(overflow);p=ready;if(p->next==null){newp->next=ready->next;ready->next=newp;}else{while(newp->switch_block.priornext->switch_block.prior&&p->next!
4、=null)p=p->next;newp->next=p->next;p->next=newp;}}voidcreat_pcb()//创建一个进程{pcbnewp;newp=(pcb)malloc(sizeof(structpro));if(!newp)exit(overflow);newp->status=wait;time(&t);newp->arrive_time=t;printf("processname:");scanf("%s",newp->name);printf("priority:");scanf("%d",&newp->switch_
5、block.prior);printf("arrivetime:");scanf("%d",&newp->arrive_time);printf("cputime_required:");scanf("%d",&newp->time_required);newp->switch_block.time_used=0;insertpcb(newp);menu();}voidprintpcb()//打印现状{pcbp;if(ready->next){printf("namestatuspriorityserver_timearrive_timecputime_
6、used");for(p=ready->next;p!=null;p=p->next){printf("%s",p->name);switch(p->status){casewait:printf("wait");break;caserun:printf("run");break;casefinished:printf("finished");break;}printf("%7d",p->switch_block.prior);printf("%15d",p->time_required);printf("%20d",p->arrive_time);
7、printf("%13d",p->switch_block.time_used);putchar('');}}elseprintf("queueisempty!");}voidswitchprocess()//将存中的进程切换至外存{chartemp[20];pcbp,q;if(ready->next){printf("inputprocessname:");scanf("%s",temp);for(p=ready;p!=null&&strcmp(temp,p->next->name)!=0;p=p->next);if(p!=null){q=p-
8、>next;p->next=q->next;printf("remove%ssu
此文档下载收益归作者所有