欢迎来到得力文库 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
得力文库 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    东北大学操作系统实验之Linux及进程状态.doc

    • 资源ID:78762805       资源大小:235KB        全文页数:11页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    东北大学操作系统实验之Linux及进程状态.doc

    操作系统实验报告一 实验一 进程状态转换及其PCB的变化一、实验目的:自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容 、组织的变化,理解进程与其PCB间的一一对应关系。二、实验内容及要求:(1)、 设计并实现一个模拟进程状态转换及其相应PCB内容、组织结构变化的程序。(2)、 独立编写、调试程序。进程的数目、进程的状态模型(三状态、五状态、七状态或其它)以及PCB的组织形式可自行选择。(3)、 合理设计与进程PCB相对应的数据结构。PCB的内容要涵盖进程的基本信息、控制信息、资源需求及现场信息。(4)、 设计出可视性较好的界面,应能反映出进程状态的变化引起的对应PCB内容、组织结构的变化。(5)、 代码书写要规范,要适当地加入注释。(6)、 鼓励在实验中加入新的观点或想法,并加以实现。(7)、 认真进行预习,完成预习报告。 (8)、 实验完成后,要认真总结,完成实验报告。五状态模型: 三、 主要数据结构:struct Run_type /运行态进程char name;int state;int needtime;int priority;struct Ready_type /就绪态进程char name;int needtime;int priority;struct Blocked_type /阻塞态进程char name;int needtime;int priority;四、 程序源代码:#include<stdio.h>#include<stdlib.h>#include<string.h>int i=0; int j=0;struct Run_typechar name;int state;int needtime;int priority;struct Ready_typechar name;int needtime;int priority;struct Blocked_typechar name;int needtime;int priority;struct Run_type Cpu;struct Ready_type Ready10;struct Blocked_type Blocked10;void Creat()/创建一个新的进程int k=0;label1:printf(" input new process name(input a letter): n");scanf("%s",&(Readyi.name);getchar();for(k=0;k<i;k+)if(Readyi.name=Readyk.name|Readyi.name=Readyk.name+32|Readyi.name=Readyk.name-32)printf("the process is already exist!");goto label1;printf("input needtime (input a int number):n");label3:scanf("%d",&(Readyi.needtime);getchar();if(Readyi.needtime<1|Readyi.needtime>100)printf("please input the true needtime(1-100)n");goto label3;printf(" input the priority(1-10): n");label2:scanf("%d",&(Readyi.priority);getchar();if(Readyi.priority<1|Readyi.priority>10)printf("please 1-10!n");goto label2;i+;void Dispath()/P135 int t;char v;int k;int j;if(Cpu.state=0)if(Readyi-1.needtime=0)printf("* there is no process ready!n");exit(0);elsefor(k=0;k<i-1;k+)for(j=0;j<i-k-1;j+)if(Readyj.priority>Readyj+1.priority)t=Readyj.priority;Readyj.priority=Readyj+1.priority;Readyj+1.priority=t;t=Readyj.needtime;Readyj.needtime=Readyj+1.needtime;Readyj+1.needtime=t;v=Readyj.name;Readyj.name=Readyj+1.name;Readyj+1.name=v;-i;Cpu.name=Readyi.name;Cpu.needtime=Readyi.needtime;Cpu.priority=Readyi.priority;Cpu.state=1;printf("*%5c is send to cpu! n",Cpu.name);Cpu.needtime-;if(Cpu.needtime=0)printf("*%5c is finished n",Cpu.name);Cpu.state=0;else Readyi.name=Cpu.name;Readyi.needtime=Cpu.needtime;Readyi.priority=Cpu.priority;for(k=0;k<i;k+)for(j=0;j<i-k;j+)if(Readyj.priority>Readyj+1.priority)t=Readyj.priority;Readyj.priority=Readyj+1.priority;Readyj+1.priority=t;t=Readyj.needtime;Readyj.needtime=Readyj+1.needtime;Readyj+1.needtime=t;v=Readyj.name;Readyj.name=Readyj+1.name;Readyj+1.name=v;Cpu.name=Readyi.name;Cpu.needtime=Readyi.needtime;Cpu.priority=Readyi.priority;Cpu.state=1;printf("*%5c is send to cpu! n",Cpu.name);Cpu.needtime-;if(Cpu.needtime=0)printf("*%5c is finished n",Cpu.name);Cpu.state=0;void Timeout()if(Cpu.state=0)printf("* there is no process in cpu(please select Dispath!n");exit(0);elseReadyi.name=Cpu.name;Readyi.needtime=Cpu.needtime;Readyi.priority=Cpu.priority;printf("%c is timeout n",Cpu.name);Cpu.name=0;Cpu.needtime=0;Cpu.priority=0;Cpu.state=0;i+;void Eventwait()if(Cpu.state!=0)Blockedj.name=Cpu.name;Blockedj.needtime=Cpu.needtime;Blockedj.priority=Cpu.priority;printf("* %c is Blocked !n",Cpu.name);j+;Cpu.name=Blockedj.name;Cpu.needtime=Blockedj.needtime;Cpu.priority=Blockedj.priority;Cpu.state=0;elseprintf("* There is no process in cpu!");void Eventoccurs(char a)int k=0;int m=0;int n=0;int p=0;if(Blocked0.needtime=0)printf("* there is no process blocked!n");exit(0);elsefor(k;k<j;k+)if(Blockedk.name=a)Readyi.name=Blockedk.name;Readyi.needtime=Blockedk.needtime;Readyi.priority=Blockedk.priority;p=1;m=j-k;for(n;n<m;n+)Blockedk.name=Blockedk+1.name;Blockedk.needtime=Blockedk+1.needtime;Blockedk.priority=Blockedk+1.priority;k+;j-;i+;if(p=1)printf("* %c is ready!n",a);elseprintf("* %c is not found! n",a);void main()Cpu.state=0;int Cputime=0;int x=6;while(x!=0)printf("n1:input new process 2:Dispathn");printf("3:Timeout 4:Eventwaitn");printf("5:Eventoccurs(select whose eventoccur ) 0:exitn");label4:scanf("%d",&x);getchar();printf("n=n");if(x=0|x=1|x=2|x=3|x=4|x=5)switch(x)case 1:Creat();break;case 2:Dispath();break;case 3:Timeout();break;case 4:Eventwait();break;case 5:char a;scanf("%c",&a);getchar(); Eventoccurs(a);break;default:printf("please select from 0 to 5n");printf("- Cputime:%3d -n",Cputime);printf("| ProceNsname NeedTime Priority |n");if(Cpu.state!=0)/显示Cpu中的程序printf("| Cpu:%16c",Cpu.name);printf("%20d",Cpu.needtime);printf("%18d |n",Cpu.priority);elseprintf("| * Cpu is free |n");int y=0;if(i=0)/显示Ready队列中的数据printf("| *There is no process ready. |n");elsefor(y;y<i;y+)/显示Ready中的程序printf("| Ready%d:",y);printf("%15c",Readyy.name);printf("%20d",Readyy.needtime);printf("%18d |n",Readyy.priority);int z=0;if(j=0) /显示Blocked队列中的程序printf("| *There is no process blocked. |n");elsefor(z;z<j;z+)printf("| Blocked%d:",z);printf("%13c",Blockedz.name);printf("%20d",Blockedz.needtime);printf("%18d |n",Blockedz.priority); Cputime+; if(Cpu.state!=0) Cpu.needtime=Cpu.needtime-1;printf("-n");elseprintf("please input 0-5n");goto label4;五、 运行结果:1. 创建a,b两个进程2、 调度进程(由于b优先级高,所以b先进入运行态)3、 当b时间片到了,b变为就绪态4、 再次调度(由于b优先级高,故还是b变成运行态)5、 正在运行的b阻塞6、 当b等待的事件发生,b重新进入就绪态六、 程序使用说明:编译程序后若无错就执行程序,初始如下:其中:1表示创建新进程,随后输入进程名,所需时间,优先级 2表示系统调度进程,首先调度最高优先级 3表示时间片已到,运行中的进程将编程就绪态 4表示进程所需的事件尚未发生,进程将被阻塞 5表示进程等待的事件已发生,进程从阻塞态变为就绪态 0退出程序

    注意事项

    本文(东北大学操作系统实验之Linux及进程状态.doc)为本站会员(飞****2)主动上传,得力文库 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知得力文库 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于得利文库 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

    © 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

    黑龙江省互联网违法和不良信息举报
    举报电话:0468-3380021 邮箱:hgswwxb@163.com  

    收起
    展开