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

开通VIP
 

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

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

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(进程管理模拟实验.doc)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

进程管理模拟实验.doc

1、 进程管理   一、目的与要求 1.目的     进程是操作系统最重要的概念之一,是了解操作系统实质的关键。本课题实习的目的是,加深对进程概念及进程管理各部分内容的理解;熟悉进程管理中主要数据结构的设计及进程调度算法、进程控制机构、同步机构、通讯机构的实施。   2.要求    要求设计一个允许n个进程并发运行的进程管理模拟系统。该系统包括以下内容:(1)简单的进程控制 (2)同步及通讯机构 (3)中断机构 (4)进程调度。其进程调度算法可任意选择。每个进程用一个PCB表示,其内容可根据具体情况设置。各进程之间有一定的同步关系。系统在运行过程中应能显示或打印各进程的状态及有关参数

2、的变化情况,以便观察诸进程的运行过程及系统的管理过程。     二、范例 1.题目        支持多个进程并发运行的简单进程管理模拟系统       本系统的同步机构采用信号量上的P、V操作的机制;控制机构包括阻塞和唤醒操作;时间片中断处理程序模拟时间片中断;进程调度程序负责为各进程分配处理机。系统中涉及了3个并发进程。它们之间的关系是:3个进程需要互斥使用临界资源S2,进程1和进程2又需互斥使用临界资源S1.本系统在运行过程中随机打印出各进程的状态变换过程,系统的调度过程及公共变量的变化情况。   2.算法与N~S图     系统为进程设置了5种运行状态:e—执行态;r

3、—高就绪态;t—低就绪态(执行进程因时间片到限而转入);w—等待态;c—完成态。各进程的初始状态均设置为r.     系统分时执行各进程,并规定3个进程的执行概率均为33%。通过产生随机数x来模拟时间片。当进程process1访问随机数x时,若x>=0.33;当进程process2访问x时,若x<0.33或x>=0.66;当进程process3访问x时,若x<0.66,则分别认为各进程的执行时间片到限,产生“时间片中断”而转入低就绪态t。     进程调度算法采用剥夺式最高优先数法。各进程的优先数通过键盘输入予以静态设置。调度程序每次总是选择优先数最小(优先权最高)的就绪进程投入执行。先从

4、r状态进程中选择,再从t状态进程中选择。当现行进程唤醒某个等待进程,且被唤醒进程的优先数小于现行进程时,则剥夺现行进程的执行权。     各进程在使用临界资源S1和S2时,通过调用信号量sem1和sem2上的P、V操作来实现同步。阻塞和唤醒操作负责完成从进程的执行态到等待态以及从等待态到就绪态的转换。     系统启动后,在完成必要的系统初始化后便执行进程调度程序。当执行进程因“时间片中断”,或被排斥使用临界资源,或唤醒某个进程时,立即进行进程调度。当3个进程都处于完成状态后,系统退出运行。   N-S图在此显示不出。        3.数据结构  (1)每个进程有一个进程控

5、制块PCB,内容包括:        id    进程标识数,id=0,1,2;        status     进程状可为e,r,t,w,c;        priority  进程优先数;        nextwr  等待链指针,指示在同一信号量上等待的下一个进程的标识数。   (2)信号量semaphore,对应于临界资源S1和S2分别有sem1和sem2,均为互斥信号量,内容包括:         value     信号量,初值为1;         firstwr     等待链首指针,指示在同一信号量上等待的下一个进程的标识数。    (3)现场保留区,在P

6、CB中模拟,用inum,addr分别模拟通用寄存器和PC的内容。 ( 4) 进程通信机构,在PCB中模拟,用mess变量模拟用于接收其它进程所发送消息的信箱。 此外,系统中还用到下列主要全程变量:       exe   执行进程指针,其值为进程标识数;        i      用来模拟一个通用寄存器;      addr    用来模拟程序计数器;      s1,s2   两个公共变量,用作共享临界资源。 4.程序及运行结果  program processc(input,output); const MAXPRI=100;       NIL=-1;   TY

7、PE       message=^messagetp;       procb=record            id:integer;            status:char;            nextwr:integer;            priority:integer;            mess:message;             inum:integer;             addr:char;            end;       messagetp=record            num:integer;

8、            next:message;            pro:integer;       end;       semaphorel=record            value:integer;            firstwr:integer;                end; var       pcb:array[1..3] of procb;       sem:array[1..2] of semaphorel;       addr:char;       i,seed,exe:integer;       style:i

9、nteger;     procedure send (sender, receiver, snum:integer); Var q,p:message; begin       new(p);       p^.num:=snum;       p^.next:=NIL;       p^.pro:=sender;       writeln('send message to process  ',receiver);       writeln('process ',sender,' already run   ',snum,'   times');       q

10、pcb[receiver].mess;       if(q=NIL) then pcb[receiver].mess:=p         else begin               while(q^.next<>NIL) do                     q:=q^.next;              q^.next:=p;              end end;   procedure   receive(receiver:integer);       var p:message; begin       p:=pcb[receive

11、r].mess;       if (p<>NIL) then                      while(p<>NIL) do                          begin                             writeln;                             writeln('receive massage form process ',p^.pro);                             writeln('process  ',p^.pro,' is already run ',p^.nu

12、m,'  time');                             writeln;                             p:=p^.next;                          end;       pcb[receiver].mess:=NIL; end;   PROCEDURE init;           VAR              j:integer;           begin                for j:=1 to 3 do                    begin   

13、                      pcb[j].id:=j;                         pcb[j].status:='r';                         pcb[j].nextwr:=NLL;                         write('process',j,' priority?');                         readln(i);                         pcb[j].priority:=i;                         pcb[j].mes

14、s:=NIL;                         pcb[j].inum:=0;                         pcb[j].addr:='0';                     end;                     sem[1].value:=1;                     sem[1].firstwr:=NLL;                     sem[2].value:=1;                     sem[2].firstwr:=NLL;                     e

15、xe:=NLL            end;   FUNCTION random:real;          VAR             m:integer;          begin               if seed<0 then m:=-seed               else m:=seed;               seed:=(25173*seed+13849) mod 65536;               random:=m/32767.0          end;   FUNCTION find:integer;

16、         VAR             j,pd,w:integer;          begin               pd:=NLL;  w:=MAXPRI;               for j:=1 to 3 do                   if pcb[j].status='r' then                      if pcb[j].priority

17、d=NLL then               for j:=1 to 3 do                   if pcb[j].status='t' then                      if pcb[j].priority

18、nteger;          begin               pd:=find;               if( (pd=NLL) and (exe=NLL)) then scheduler:=NLL               else begin                         if pd<>NLL then                            begin                                 if exe=NLL then                                    be

19、gin                                         pcb[pd].status:='e';                                         exe:=pd;                                         writeln('process',exe,' is executing.');                                    end                                 else if pcb[pd].priority

20、exe].priority then                                         begin                                              pcb[exe].status:='r';                                              writeln('process',exe,' enter into ready.');                                              pcb[pd].status:='e';        

21、                                      exe:=pd;                                              writeln('process',exe,'is executing.');                                         end                            end;                         i:=pcb[exe].inum;                         addr:=pcb[exe].addr;

22、                         scheduler:=exe                   end          end;   PROCEDURE block(se:integer);           VAR              w:integer;           begin                writeln('process',exe,' is blocked');                pcb[exe].status:='w';                pcb[exe].nextwr:=NLL;  

23、              w:=sem[se].firstwr;                if (w=NLL) then                   sem[se].firstwr:=exe                else begin                          while (pcb[w].nextwr<>NLL) do                                w:=pcb[w].nextwr;                                pcb[w].nextwr:=exe          

24、           end           end;   FUNCTION p(se:integer;ad:char):boolean;          begin               sem[se].value:=sem[se].value-1;               if sem[se].value>=0 then p:=false               else begin                         block(se);                         pcb[exe].inum:=i;        

25、                 pcb[exe].addr:=ad;                         exe:=NLL;                         p:=true                     end          end;   PROCEDURE wakeup(se:integer);           VAR              w:integer;           begin                w:=sem[se].firstwr;                if w<>NLL the

26、n                   begin                        sem[se].firstwr:=pcb[w].nextwr;                        pcb[w].status:='r';                        writeln('process',w,' is waken up')                   end           end;   FUNCTION v(se:integer;ad:char):boolean;          begin              

27、 sem[se].value:=sem[se].value+1;               if sem[se].value>0 then v:=false               else begin                         wakeup(se);                         pcb[exe].inum:=i;                         pcb[exe].addr:=ad;                         v:=true                     end          e

28、nd;   FUNCTION timeint(ad:char):boolean;         var x:real;         begin              x:=random;              if((x<0.33) and (exe=1)) then timeint:=false              else if((x<0.66) and (exe=2)) then timeint:=false              else if((x<1.00) and (exe=3)) then timeint:=false         

29、     else begin                       pcb[exe].inum:=i;                       pcb[exe].addr:=ad;                       pcb[exe].status:='t';                       writeln('Times silce interrupt.');                       writeln('process',exe,' enter into ready.');                       exe:=NL

30、L;                       timeint:=true                   end          end;   procedure eexit(n:integer); begin     pcb[n].status:='c';     writeln('process',n,' is completed !');     exe:=NLL; end;   procedure process1(var s1,s2:integer); label a1,b1,c1,d1,e1,f1,stop1,end1; begin    i

31、f(addr='a') then goto a1;    if(addr='b') then goto b1;    if(addr='c') then goto c1;    if(addr='d') then goto d1;    if(addr='e') then goto e1;    if(addr='f') then goto f1;    while(i<5) do       begin            receive(1);            writeln('process1 calls P on semaphore1.');        

32、    if(p(1,'a')) then goto stop1;       a1:  writeln('process1 is executing on its cretical section1.');            if(timeint('b')) then goto stop1;       b1:            s1:=s1+1;            writeln('s1=',s1);            writeln('process1 calls V on semaphore1 and quit cretical setion1.');  

33、          if(v(1,'c')) then goto stop1;       c1:  writeln('process1 calls P on semaphore2.');            if(p(2,'d')) then goto stop1;       d1:  writeln('process1 is execting cretical section2.');            if(timeint('e')) then goto stop1;       e1:            s2:=s2+1;            writeln

34、's2=',s2);            writeln('process1 calls V on semaphore2 and quit cretical section2.');            if(v(2,'f')) then goto stop1;       f1:  writeln('process 1 cyclen count=',i+1);            i:=i+1; send(1,2,i);send(1,3,i);readln;       end; stop1:  if(i<5) then goto end1;        eexit(

35、1); end1: end;   procedure process2(var s1,s2:integer); label a2,b2,c2,d2,e2,f2,stop2,end2; begin    if(addr='a') then goto a2;    if(addr='b') then goto b2;    if(addr='c') then goto c2;    if(addr='d') then goto d2;    if(addr='e') then goto e2;    if(addr='f') then goto f2;     while

36、i<5) do       begin            receive(2);            writeln('process2 calls P on semaphore2.');            if(p(2,'a')) then goto stop2;       a2:  writeln('process2 is executing on its cretical section2.');            if(timeint('b')) then goto stop2;       b2:            s2:=s2+1;     

37、       writeln('s2=',s2);            writeln('process2 calls V on semaphore2 and quit cretical setion2.');            if(v(2,'c')) then goto stop2;       c2:  writeln('process2 calls P on semaphore1.');            if(p(1,'d')) then goto stop2;       d2:  writeln('process2 is execting cretical s

38、ection1.');            if(timeint('e')) then goto stop2;       e2:            s1:=s1+1;            writeln('s1=',s1);            writeln('process2 calls V on semaphore1 and quit cretical section1.');            if(v(1,'f')) then goto stop2;       f2:  writeln('process 2 cyclen count=',i+1);

39、           i:=i+1;send(2,1,i);send(2,3,i);readln;       end; stop2:  if(i<5) then goto end2;        eexit(2); end2: end;   procedure process3(var s1,s2:integer); label a3,b3,c3,stop3,end3; begin    if(addr='a') then goto a3;    if(addr='b') then goto b3;    if(addr='c') then goto c3;   

40、 while(i<5) do       begin            receive(3);            writeln('process3 calls P on semaphore2.');            if(p(2,'a')) then goto stop3;       a3:  writeln('process3 is executing on its cretical section2.');            if(timeint('b')) then goto stop3;       b3:            s2:=s2+1;

41、            writeln('s2=',s2);            writeln('process3 calls V on semaphore2 and quit cretical setion2.');            if(v(2,'c')) then goto stop3;       c3:  writeln('process 3 cyclen count=',i+1);            i:=i+1;send(3,1,i);send(3,2,i);readln;       end; stop3:  if(i<5) then goto en

42、d3;        eexit(3); end3: end;   procedure main; var k:integer;     s1,s2:integer; label 100; begin     writeln('                     C . O . S   Example  one');     writeln;     init;     s1:=0;s2:=0;     writeln('s1=',s1,',s2=',s2);     writeln('process1,process2,process3 are all i

43、n ready!'); 100:k:=scheduler;     if(k<>NLL)  then       case k of            1: begin process1(s1,s2);                     goto 100;               end;            2: begin process2(s1,s2);                     goto 100;               end;            3: begin process3(s1,s2);              

44、       goto 100;               end;           else writeln('process identifer error.');       end;    writeln;writeln;    writeln('s1=',s1,',s2=',s2);    writeln;    writeln('               COMPLETED!');    readln; end;   begin     main end.   程序运行结果如下:                      C . O . S

45、   Example  one   process1 priority? 1 process2 priority? 2 process3 priority? 3 s1=0,s2=0 process1,process2,process3 are all in ready! process1 is executing. process1 calls P on semaphore1. process1 is executing on its cretical section1. s1=1 process1 calls V on semaphore1 and quit creti

46、cal setion1. process1 calls P on semaphore2. process1 is execting cretical section2. s2=1 process1 calls V on semaphore2 and quit cretical section2. process 1 cyclen count=1 send message to process  2 process 1 already run   1   times send message to process  3 process 1 already run   1   t

47、imes process1 calls P on semaphore1. process1 is executing on its cretical section1. s1=2 process1 calls V on semaphore1 and quit cretical setion1. process1 calls P on semaphore2. process1 is execting cretical section2. s2=2 process1 calls V on semaphore2 and quit cretical section2. process

48、 1 cyclen count=2 send message to process  2 process 1 already run   2   times send message to process  3 process 1 already run   2   times process1 calls P on semaphore1. process1 is executing on its cretical section1. s1=3 process1 calls V on semaphore1 and quit cretical setion1. process1

49、 calls P on semaphore2. process1 is execting cretical section2. Times silce interrupt. process1 enter into ready. process2 is executing.   receive massage form process 1 process  1 is already run 1  time                      ·                  ·           · process1 enter into ready.

50、process2 is executing. process2 is executing on its cretical section2. s2=4 process2 calls V on semaphore2 and quit cretical setion2. process3 is waken up process2 calls P on semaphore1. process2 is blocked process3 is executing. process3 is executing on its cretical section2. s2=5 process

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服