《操作系统实验报告实验--实验五 模拟SPOOLING系统.docx》由会员分享,可在线阅读,更多相关《操作系统实验报告实验--实验五 模拟SPOOLING系统.docx(12页珍藏版)》请在第一文库网上搜索。
1、操作系统实验报告实验五模拟SPOO1ING系统一实验名称SPOO1ING系统的模拟实现二、实验目标假脱机(SPOO1ING)技术是广泛应用于各种计算机系统的一种行之有效的输入输出手段。这种技术使用比较简单的方法,缓和了高速处理机与低速输入输出设备速度不匹配的矛盾,提高了设备的利用率。为了更好地掌握这种技术。本实验要求学生独立地用高级语言编写一个SPOO1ING程序来模拟假脱机输入输出过程。三、实验环境要求1PC机。2. Windows;1inux环境。3. Visua1C+6.0forWindows;g+for1inuo四、实验基本原理spoo1ing系统又叫假脱机系统,它能在主机控制下,对信
2、息的输入输出实现外部设备联机操作.该系统包含输入收存程序和输出发送等程序,还必须建立描述辅存输入井和输出井的状态转化的表格.spoo1ing系统把待建立的作业源源不断向磁盘的输入井中传送,把正在处理的作业的结果收存到输出井上,最后从外设发送出去,这种输入收存和输出发送的功能起到了脱机处理的作用.五、数据结构设计(I)进程控制块类structpcb(intid;intstart;char*ch;int1ength;intco1or;pcb()(id=1ength=O;CO1or=1IGHTGRAY;ch=O;start=O;1)(2)进程控制块链管理类.c1ass1ink(intn,n1;int
3、x,y;pub1ic:pcb*p;1ink()n1=10;n=n1;x=y=0;p=newpcb10;1ink(inti)n1=i;n=O;p=newpcbn1;)voidIinkset(int,int,int);voiddraw();intempty();voidIef();intfu11();intretco1or();friendvoidsend(1ink&,1ink&,int);intsetco1o(int);friendvoidmove(1ink&,Iink&);voidsetchar(int);六、流程图图1Spoo1ing系统流程图七、源代码#inc1ude,stdio.hinc
4、1ude,std1ib.h#inc1ude# defineMAXPCBNUM3# definePCBITEMNUM6# defineMAXIOB1KNUM10# defineIOB1KITEMNUM3# defineUSERPROCNUMMAXPCBNUM-1#defineOUTPUTPOO1SIZE100*thestateofprocess*/#defineREADY0*CANRUNINGSTATE*/#defineWAIT1#defineWAIT21*CANNOTRUNNINGSTATE,OUTPUTPOO1ISFU11;*/2*CANNOTRUNNINGSTATE;NOFREEIOB1O
5、K;*/#defineFINISH3*FINISHSTATE*/*theitemnameofarraypcb*/#defineIDO# defineSTATE1# definePOINT2# defineSTART3# define1ENGTH4# defineBUFFER5*theitemnameofarrayiob1k*/# defineIOB1KDO# defineIOB1K_1EN1# defineIOB1K_START2intpcbMAXPCBNUMPCBITEMNUM,iob1kMAXIOB1KNUMIOB1KITEMNUM,poo1USERPROCNUMOUTPUTPOO1SIZ
6、E,va1ueUSERPROCNUM,b1=0,b2=0,freeiob1knum,freepoo11enUSERPROCNUM,countUSERPROCNUM,tota1iotimesUSERPROCNUM,iotimesUSERPROCNUM;voidinit()*initiaizing*/1inti;srand(time(NU11);for(i=o;iMaxpcbnum;i+)(pcbiID=i;pcbiSTATE=READY;pcbiPOINT=0;pcbiSTART=0;pcbi1ENGTH=0;pcbiBUFFER=-1;1freeiob1knum=MAXIOB1KNUM;for
7、(i=0;iUSERPROCNUM;i+)(freepoo1!eni=OUTPUTPOO1SIZE;printf(INPUTTHETIMESOFUSER%dsOUTPUTFI1E7n,i+1);scanf(,%d,fecounti);tota1iotimesi=counti;iotimesi=0;intspoo1ing()intd,g,e,i,ovemum;staticoutputUSERPROCNUM;if(freeiob1knum=MAXIOB1KNUM)(pcbOSTAE=WAIT1;retum(1);)d=iob1kb1IOB1KJD;g=iob1kb1IOB1K_1EN;e=iob1
8、kb1IOB1K_START;iotimesd-1+;printf(,USER%dFI1E%dFI1E.1ENGTH=%dn,d,iotimesd-1,g);if(g)for(i=O;ig;i+)printf(%d,poo1d-1e);e=(e+1)%OUTPUTPOO1SIZE;)printf(n,);freepoo11end-1+=g;if(pcbdSTATE=WAIT1)pcbdSTATE=READY;)b1=(b1+1)%MAXIOB1KNUM;freeiob1knum+;for(i=1;iMAXPCBNUM;i+)pcbiSTATE=READY;ovemum=0;for(i=0;iU
9、SERPROCNUM;i+)(if(iotimesi=tota1iotimesi)(if(!outputi)(printf(,OUTPUTOFUSER%dISCOMP1ETED!n,i+1);outputi=1;1ovemum+;)1if(overnum=USERPROCNUM)(printf(theend!n);return(0);)e1sereturn(1);)intuserproc(intr)(intx;va1uer-1=rand()%10;x=va1uer-1;e1sex=pcbrBUFFER;pcbrBUFFER=-1;1if(x)if(freepoo11enr-1)poo1r-1p
10、cbrPOINT=x;pcbr1ENGTH+;freepoo11enr-1-;pcbrPOINT=(pcbrPOINT1)%OUTPUTPOO1SIZE;)e1se(pcbrBUFFER=x;pcbrSTATE=WAIT1;)e1seif(freeiob1knum)(iob1kb2IOB1KD=pcbrID;iob1kb2IOB1K.START=pcbrSTART;iob1kb2IOB1K_1EN=pcbr1ENGTH;pcbr1ENGTH=0;pcbrSTART=pcbrPOINT;b2=(b2+1)%MAXIOB1KNUM;freeiob1knum;pcbOSTART=READY;e1se
11、(pcbrBUFFER=x;pcbrSTATE=WAIT2;)if(!va1uer-1)(countr-1-;if(!countr-1)(pcbrSTATE=FINISH;if(r=0)(printf(A11FI1EHAVEBEENOUTPUTEDXnTHESYSTEMISCOMP1ETEDXn);return(O);1e1seprintf(A11ANSWERSOFUSER%dHAVEBEENSENDEDn,r);)return(1);voidschedu1er()intx,again=1;whi1e(again)x=rand()%100;printf(,x=random(100)is%dn,
12、x);getchar();if(x45&x90&pcbOSTATE=READY)printf(enterinhere!n);again=spoo1ing();)voidmain()(iit();schedu1er();八、运行结果C:UsersASUSDesktop遮作DebugSPOoiJNGMexe-XINPUTTHETIMESOFUSER1sOUTPUTFI1E?2INPUTTHETIMESOFUSER2,STPUTFI1E?3=randon(1)is48x=random(1)is61x=random(1)is33x=random(1)is79x=random(1)is54x=randon(1)is71xrandom(1)is12x=random(1)is42x=randon(1)is19搜狗拼音输入法全