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

    操作系统实验报告进程状态转换.pdf

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

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

    操作系统实验报告进程状态转换.pdf

    实验 进程状态转换及其PCB的变化、程序流程图:、使用的数据结构及说明:在本实验中,主要用到的数据结构是PCB 的结构,其中 PCB 的数据结构如下: struct PCBint P_ld;char P_Name10;char P_State10;int P_Ru ntime;int P_Requiry; struct PCB *n ext ;l -其中,P_Id,和 P_Name用来标示一个进程,而 P_State 用来标示进程的五种状态:/PCB 的 ID 号/PCB 的名称/PCB 状态/PCB 的所需要的运行时间/PCB 所需要的资源要求/PCB 块的下一个指针Create_state,Ready_state,Block_state,Run_state,Exit_state 。 P_Runtime 标示要完成一个进程所需 要的时间。 P_Requiry 标示一个进程的执行所需要的其他条件, 当其他的条件满足, 则 P_Requiry 置 1,否则置 0。Struct PCB * next用来指向同一队列中的下一个PCB 块。三、程序源代码 :#includestdlib.h #includestdio.h#includestring.h/* globle structure and viable */ struct PCB/PCB 的 ID 号/PCB 的名称int P_Id;char P_Name10;char P_State10;int P_Runtime;while(q!=NULL)int P_Requiry;struct PCB * next ; ;/PCB 状态/PCB 的所需要的运行时间/PCB 所需要的资源要求/PCB 块的下一个指针p=*head; q=p-next;/ 找到最后的元素位置struct PCB * Create_state;struct PCB * Run_state;struct PCB * Ready_state;struct PCB * Block_state;struct PCB * Exit_state;int signal4=0;int signal5=0;/ 创建状态/ 运行状态/ 就绪状态/ 阻塞状态/ 退出状态/ 标示进程/ 标示进程的完成状态的完成状态/* insert node function */void InsertQueue(struct PCB *head,struct PCB *node)struct PCB * p,*q;node-next=NULL;if(*head=NULL)/ 如果队列为空*head=node;Else/ 队列不空p=q;q=q-next;p-next=node;/ 将节点插入队列void DeleteQueue(struct PCB *head,struct PCB *node)struct PCB *p,*q; q=*head;if(*head=NULL|node=NULL) return ;if(*head=node)*head=(*head)-next; return;Elsewhile(q-next!=p&q-next!=NULL)q=q-next;q=p-next; p-next=NULL;void Display_Process(struct PCB * node)/ 撤销进程,从队列中删除元素/ 如果队列为空,返回/ 如果要删除的元素是队首元素/ 如果不是队列的首元素printf(nnthis process Id is printf(thisprocess name is printf(this process stateis printf(this process Runtime is/ 打印进程状态的元素函数: %d n,node-P_Id);: %s n,node-P_Name);: on %s n ,node-P_State);: %d n,node-P_Runtime);if(node-P_Requiry)printf(this process resource is readyelseprintf(this process resource is not ready ! n);n);void DispatchToBlock(struct PCB *node) / /* dispatch to block function*/ / 调度到阻塞状态的函数/struct PCB *p=(struct PCB *)malloc(sizeof(struct PCB);if(!node-P_Requiry) / 如果所需要的资源没有满足则,调度到阻塞状态strcpy(node-P_State,block);InsertQueue(&Block_state,node); / 插入到阻塞队列 Display_Process(node);void DispatchToReady(struct PCB *node) / dispatch to ready state / 调度到就绪状态的函数 if(node-P_Requiry) / 如果所需的资源满足,则调度strcpy(node-P_State,Ready);InsertQueue(&Ready_state,node);Display_Process(node);void DispatchBlockToReady() /dispatch the process to readyqueue/ 从阻塞状态调度到就绪状态函数struct PCB*p,*q;q=Block_state;while(q!=NULL)p=q;q=q-next;if(signal4&p-P_Id=4)/ 如果阻塞状态队列不空/如果所需要的资源满足DeleteQueue(&Block_state,p);strcpy(p-P_State,ready);InsertQueue(&Ready_state,p);printf(process4 will be in the state of ready!n);Display_Process(p);if(signal5&p-P_Id=5)DeleteQueue(&Block_state,p); strcpy(p-P_State,ready);InsertQueue(&Ready_state,p);printf(process5 will be in the state of ready!n);Display_Process(p);void Create_Process()/ 创建进程函数int i;struct PCB *p;char name10;strcpy(name,process);for(i=1;iP_Id=i;name7=i+0;name8=0; strcpy(p-P_Name,name);strcpy(p-P_State,create);p-P_Runtime=1; / 所需要的时间片为 1 p-P_Requiry=0;Display_Process(p);sleep(4);printf( n process%d will be in the state of Block, waiting the resource ready nn,i);DispatchToBlock(p); / 同时调度到阻塞队列for(i=3;iP_Id=i;name7=i+0;name8=0;strcpy(p-P_Name,name); strcpy(p-P_State,create);p-P_Requiry=1;if(i=6)p-P_Runtime=2;elsep-P_Runtime=1;Display_Process(p);sleep(4);printf( n process%d will be in the state of Ready, waiting to run nn,i);DispatchToReady(p);/ 在这里个进程 6void display(struct PCB *head)struct PCB *p,*q; p=*head;while(p!=NULL)sleep(2);/printf(nn/n);printf(nnthis process Id isprintf(this process name isprintf(this process state isprintf(this process Runtime isif(p-P_Requiry)printf(this process resource is readyelseprintf(this process resource is not ready ! n); p=p-next;: %d n,p-P_Id);: %s n,p-P_Name);: on %s n ,p-P_State);: %d n,p-P_Runtime);n);void Process_Run()/ 进程运行函数struct PCB *p,*q;p=Ready_state;q=p;while(p!=NULL)/ 就绪队列不空则继续执行/ 如果时间片执行完了,则跳出循环if(p-P_RuntimeP_State,running);Display_Process(p);p-P_Runtime=p-P_Runtime-1;sleep(4);if(p-P_Runtime0)/ 没有完成,则进入就绪队列printf(this process is not finished,will be dispatch to the ready queue!n);DeleteQueue(&Ready_state,p);strcpy(p-P_State,ready); InsertQueue(&Ready_state,p);Display_Process(p);Else / 执行完成,则跳出,并发送相应的信息printf(nnProcess%d is finished and will be in the state of exit!nn,p-P_Id);if(p-P_Id=4) signal4=1;if(p-P_Id=5) signal5=1;if(signal4|signal5)DispatchBlockToReady(); / 如果资源满足,则将进程调度到就绪队列 q=q-next;p=q;if(q=NULL) printf(nthere is no process ready!n STOP Machine!n);int main(int argc,char * argv)/ 主函数int i;char c=c; / 界面 printf( n); printf(printf( .Press s to start the process. n);scanf(%c,&c);while(1)Ding Hai bon);if(c=s)break; scanf(%c,&c);Create_Process(); / 调用创建进程函数printf(nn); printf(n Displaythe Ready queue n); sleep(5);display(&Ready_state); / 显示就绪队列里的进程printf(nn);printf(n Display the Block queuen);sleep(5); / 显示阻塞队列函数 display(&Block_state); /printf(nnnn);printf(n Now the process start to runsleep(5);Process_Run(); / 调用进程运行函数n);四、运行结果及说明:运行结果的截图: 下面的运行结果是程序执行的每一步进程调度的显示,从进程的创建到进程的执行,结束, 每一步进程调度都有显示。sthis process Id is1this process name isprocesslthis process state ison createthis process Runtime is:1this process resource is not ready !processl will be in the state of Block, waiting the resource readythis processId is:1this processname is:processlthis processstate is:on blockthis process Runtime Is : 1this process resource is not ready !this process Id is this process:2name is this process state is:process2this process Runtime this:on createprocess resourceis : 1 is not ready !this processId is: 2this processname Is: process2this processstate is: on blockthis process Runtime is : 1this process resource is not ready !this process Id is this processname Is this process state is this:process3 :onprocess Runtime iscreatethis process resource 1$:1readyprocess3 will be In thestate of Ready, waiting to runthis process Id is this processname is this process state is this:process3 :onprocess Runtime Is this processReady :1 readyresource isthis process Id is this processname is this process state is thisprocess Runtime Is this processresource is:4:process4:on create:1readyfile Edit View Tfeirninal labs Helpthis process Id isthis process name 15this process state isthis process Runtime isthis process resource is:4:process4:on Redy:1readythis process Id isthis process name isthis process state Isthis process Runtime isthis process resoiurce isprocess5 will be In the:5:processB:on Create:1readystate of Rsadywaiting to runthis process Id isthis procsssi name isthis process state Isthis process Runtime isthis process resoiurce is:5:processi on Ready:1readythis process Id isthis process name isthis process state 1&:6:processB:on createthis process Runtime is : 2 this process resource is ready五程序使用说明:1) 输入字符启动程序2)程序将自动执行,自动创建进程,运行进程和结束进程3)程序将自动显示每一步进程的执行状态。

    注意事项

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

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




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开