ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:117.63KB ,
资源ID:27045428      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/27045428.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(进程调度.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

进程调度.docx

1、进程调度1.实验目的进程调度是处理机管理的核心内容,通过本实验加深理解有关进程控制块,进程队列的概念,并体会和了解先来先服务算法、优先数优先算法、时间片轮转算法的实现。2.实验内容1掌握先来先服务的调度基本思想。2掌握优先数优先的调度基本思想。3. 掌握时间轮转算法的调度基本思想。3会对以上三种调度算法程序进行编写及调试3.设计思路 先来先服务算法通过用户输入的Secquence来作为进程队列排序的依据,优先数有限算法通过用户输入的Periority来作为进程队列排序的依据,时间轮转算法先通过进程的优先级,等一个时间片用完后,由下一个优先级的进程开始运行,依次执行,直到各个进程都执行完为止。4

2、.关键代码#include #include #include #define NULL 0typedef struct pcb /* 定义进程控制块PCB */ char name10; int Id; int Sequence; char state; int super; int ntime; int rtime; struct pcb *next;node;node *p;node *ready=NULL; /*FCFS先进先出*/*/定义函数,建立进程列表node *Create_FCFS() node *head,*p1,*p2; int n=0; head=NULL; p1=p2

3、=(node*)malloc(sizeof(node); printf(n请创建进程控制表(0表示结束):n); printf(Id Sequencen); scanf(%d %d,&p1-Id,&p1-Sequence); while(p1-Id!=0) n=n+1; if(n=1) head=p1; else p2-next=p1; p2=p1; p1=(node*)malloc(sizeof(node); scanf(%d %d,&p1-Id,&p1-Sequence); p2-next=NULL; return head;/模拟当前就绪进程队列中最先进入进程出队并输出的调度过程node

4、 *FSFC(node *head) node *p=head; printf(Id=%d,Sequence=%d,p-Id,p-Sequence); p=p-next; return(p);void Print(node *head) node *p,*q; int count=0; p=head; while(p) count+; printf(n第%d次被调度的就绪进程为:n,count); q=FSFC(p); p=q; /打印进程列表void Print_FCFS(node *head) node *p=head; printf(nThe table is(原始进程控制表为):n);

5、 while(p) printf(%d %dn,p-Id,p-Sequence); p=p-next; /*按优先级大小*/*/对进程表按优先数从大到小排序node *insert(node *head,node *a) node *p,*pre; p=head; while(p&p-super=a-super) pre=p;p=p-next; if(p=head) a-next=head;head=a; else if(p=NULL) pre-next=a;pre=a; else a-next=pre-next; pre-next=a; return head; /定义函数,建立进程链表no

6、de *Create_Priority() node *head; node *p1; int n=0; p1=(node *)malloc(sizeof(node); printf(n请创建进程控制表(0表示结束):n); printf(Id Priorityn); scanf(%d %d,&p1-Id,&p1-super); p1-next=NULL; head=NULL; while (p1-Id!=0) n=n+1; if (n=1) head=p1; else head=insert(head,p1); p1=(node*)malloc(sizeof(node); scanf(%d

7、%d,&p1-Id,&p1-super); p1-next=NULL; return(head);/模拟按优先数大小进程分级出队的过程void Print_Priority(node *head) int count=1; node *p; p=head; while(p) printf(第%d个出队进程为:%dn,p-super); printf(Id=%d,Priority=%dn,p-Id,p-super); printf(n); p=p-next; count+; /*时间轮转算法*/ void sort() /* 建立对进程进行优先级排列函数*/ node *first, *seco

8、nd; int insert=0; if(ready=NULL)|(p-super)(ready-super) /*优先级最大者,插入队首*/ p-next=ready; ready=p; else /* 进程比较优先级,插入适当的位置中*/ first=ready; second=first-next; while(second!=NULL) if(p-super)(second-super) /*若插入进程比当前进程优先数大,*/ /*插入到当前进程前面*/ p-next=second; first-next=p; second=NULL; insert=1; else /* 插入进程优先

9、数最低,则插入到队尾*/ first=first-next; second=second-next; if(insert=0) first-next=p; void Create() int i,num; printf(n请输入进程的个数:n); scanf(%d,&num); for(i=0;iname); printf(n 输入进程优先数:); scanf(%d,&p-super); printf(n 输入进程运行时间:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w; p-next=NULL; sort(); /* 调用sort函

10、数*/ int num()/*计算进程控制块个数*/ int count=0; node *q=ready; while(q!=NULL) count+; q=q-next; return count;void display(node *q) /*建立进程显示函数,用于显示当前进程*/ printf(n 进程名 状态 优先级 需要运行时间 已经运行时间 n); printf(%5s,q-name); printf(%10c,q-state); printf(%10d,q-super); printf(%10d,q-ntime); printf(%15d,q-rtime); printf(n)

11、;void check() /* 进程查看 */ node *q; printf(n 当前正在运行的进程是:%s,p-name); /*显示当前运行进程*/ display(p); q=ready; printf(n 当前就绪队列状态为:n); /*显示就绪队列状态*/ while(q!=NULL) display(q); q=q-next; void destroy() /*进程运行结束,撤消进程*/ printf(n 进程 %s 已完成.n,p-name); free(p);void running() /* 进程运行时间到,置就绪状态*/ (p-rtime)+; if(p-rtime=p

12、-ntime) destroy(); /* 调用destroy函数*/ else (p-super)-; p-state=w; sort(); /*调用sort函数*/ void Time() int Num,i=0; char ch; Create();/创建进程 Num=num();/计算就绪队列中进程个数 while(Num!=0)&(ready!=NULL) ch=getchar(); i+; printf(n进程运行次数:%d n,i); p=ready; ready=p-next; p-next=NULL; p-state=R; check(); running(); printf

13、(n 按任一键继续.); ch=getchar(); printf(nn 进程已经完成.n); ch=getchar();main() int choice; node *head; printf( 进程调度n); printf(1、先进先出算法n); printf(2、按优先级算法(从大到小)n); printf(3、时间轮转算法n); printf(0、退出); printf(n请输入您的选择:); scanf(%d,&choice); do switch(choice) case 1: head=Create_FCFS(); Print_FCFS(head); Print(head); break; case 2: head=Create_Priority(); Print_Priority(head); break; case 3: Time(); break; case 0: break; default: break; printf(n请输入您的选择:); scanf(%d,&choice); while(choice!=0); 5.运行结果5.实验总结(含心得体会)先来先服务算法实现简单,但响应不及时,适用于交互性要求不高的系统。时间轮转算法可以保证不会有进程长期得不到响应,缺点是无法照顾到一些特殊进程。优先级优先算法每次需要计算进程优先级,占用较多资源。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1