《操作系统实验报告实验--实验五 模拟SPOOLING系统.docx》由会员分享,可在线阅读,更多相关《操作系统实验报告实验--实验五 模拟SPOOLING系统.docx(12页珍藏版)》请在第壹文秘上搜索。
1、操作系统实验报告实验五模拟SPOOLING系统一实验名称SPOOLING系统的模拟实现二、实验目标假脱机(SPOOLING)技术是广泛应用于各种计算机系统的一种行之有效的输入输出手段。这种技术使用比较简单的方法,缓和了高速处理机与低速输入输出设备速度不匹配的矛盾,提高了设备的利用率。为了更好地掌握这种技术。本实验要求学生独立地用高级语言编写一个SPOOLING程序来模拟假脱机输入输出过程。三、实验环境要求1.PC机。2. Windows;Linux环境。3. VisualC+6.0forWindows;g+forLinuo四、实验基本原理spooling系统又叫假脱机系统,它能在主机控制下,对
2、信息的输入输出实现外部设备联机操作.该系统包含输入收存程序和输出发送等程序,还必须建立描述辅存输入井和输出井的状态转化的表格.spooling系统把待建立的作业源源不断向磁盘的输入井中传送,把正在处理的作业的结果收存到输出井上,最后从外设发送出去,这种输入收存和输出发送的功能起到了脱机处理的作用.五、数据结构设计(I)进程控制块类structpcb(intid;intstart;char*ch;intlength;intcolor;pcb()(id=length=O;COlor=LIGHTGRAY;ch=O;start=O;1)(2)进程控制块链管理类.classlink(intn,nl;in
3、tx,y;public:pcb*p;link()nl=l0;n=n1;x=y=0;p=newpcbl0;link(inti)nl=i;n=O;p=newpcbnl;)voidIinkset(int,int,int);voiddraw();intempty();voidIef();intfull();intretcolor();friendvoidsend(link&,link&,int);intsetcolo(int);friendvoidmove(link&,Iink&);voidsetchar(int);六、流程图图1Spooling系统流程图七、源代码#include,stdio.hin
4、clude,stdlib.h#include# defineMAXPCBNUM3# definePCBITEMNUM6# defineMAXIOBLKNUM10# defineIOBLKITEMNUM3# defineUSERPROCNUMMAXPCBNUM-1#defineOUTPUTPOOLSIZE100*thestateofprocess*/#defineREADY0*CANRUNINGSTATE*/#define WAITl#define WAIT21*CANNOTRUNNINGSTATE,OUTPUTPOOLISFULL;*/2*CANNOTRUNNINGSTATE;NOFREEIO
5、BLOK;*/#defineFINISH3*FINISHSTATE*/*theitemnameofarraypcb*/#defineIDO# defineSTATE1# definePOINT2# defineSTART3# defineLENGTH4# defineBUFFER5*theitemnameofarrayioblk*/# defineIOBLKDO# defineIOBLK_LEN1# defineIOBLK_START2intpcbMAXPCBNUMPCBITEMNUM,ioblkMAXIOBLKNUMIOBLKITEMNUM,poolUSERPROCNUMOUTPUTPOOL
6、SIZE,valueUSERPROCNUM,bl=0,b2=0,freeioblknum,freepoollenUSERPROCNUM,countUSERPROCNUM,totaliotimesUSERPROCNUM,iotimesUSERPROCNUM;voidinit()*initiaizing*/1inti;srand(time(NULL);for(i=o;iMaxpcbnum;i+)(pcbiID=i;pcbiSTATE=READY;pcbiPOINT=0;pcbiSTART=0;pcbiLENGTH=0;pcbiBUFFER=-l;1freeioblknum=MAXIOBLKNUM;
7、for(i=0;iUSERPROCNUM;i+)(freepool!eni=OUTPUTPOOLSIZE;printf(INPUTTHETIMESOFUSER%dsOUTPUTFILE7n,i+l);scanf(,%d,fecounti);totaliotimesi=counti;iotimesi=0;intspooling()intd,g,e,i,ovemum;staticoutputUSERPROCNUM;if(freeioblknum=MAXIOBLKNUM)(pcbOSTAE=WAITl;retum(1);)d=ioblkblIOBLKJD;g=ioblkblIOBLK_LEN;e=i
8、oblkb1IOBLK_START;iotimesd-l+;printf(,USER%dFILE%dFILE.LENGTH=%dn,d,iotimesd-l,g);if(g)for(i=O;ig;i+)printf(%d,poold-le);e=(e+l)%OUTPUTPOOLSIZE;)printf(n,);freepoollend-l+=g;if(pcbdSTATE=WAITl)pcbdSTATE=READY;)bl=(bl+l)%MAXIOBLKNUM;freeioblknum+;for(i=1;iMAXPCBNUM;i+)pcbiSTATE=READY;ovemum=0;for(i=0
9、;iUSERPROCNUM;i+)(if(iotimesi=totaliotimesi)(if(!outputi)(printf(,OUTPUTOFUSER%dISCOMPLETED!n,i+l);outputi=1;1ovemum+;)1if(overnum=USERPROCNUM)(printf(theend!n);return(0);)elsereturn(1);)intuserproc(intr)(intx;valuer-l=rand()%10;x=valuer-l;elsex=pcbrBUFFER;pcbrBUFFER=-l;1if(x)if(freepoollenr-l)poolr
10、-lpcbrPOINT=x;pcbrLENGTH+;freepoollenr-l-;pcbrPOINT=(pcbrPOINT1)%OUTPUTPOOLSIZE;)else(pcbrBUFFER=x;pcbrSTATE=WAITl;)elseif(freeioblknum)(ioblkb2IOBLKD=pcbrID;ioblkb2IOBLK.START=pcbrSTART;ioblkb2IOBLK_LEN=pcbrLENGTH;pcbrLENGTH=0;pcbrSTART=pcbrPOINT;b2=(b2+1)%MAXIOBLKNUM;freeioblknum;pcbOSTART=READY;e
11、lse(pcbrBUFFER=x;pcbrSTATE=WAIT2;)if(!valuer-l)(countr-l-;if(!countr-l)(pcbrSTATE=FINISH;if(r=0)(printf(ALLFILEHAVEBEENOUTPUTEDXnTHESYSTEMISCOMPLETEDXn);return(O);1elseprintf(ALLANSWERSOFUSER%dHAVEBEENSENDEDn,r);)return(1);voidscheduler()intx,again=1;while(again)x=rand()%100;printf(,x=random(100)is%
12、dn,x);getchar();if(x45&x90&pcbOSTATE=READY)printf(enterinhere!n);again=spooling();)voidmain()(i11it();scheduler();八、运行结果C:UsersASUSDesktop遮作DebugSPOoiJNGMexe-XINPUTTHETIMESOFUSERlsOUTPUTFILE?2INPUTTHETIMESOFUSER2,STPUTFILE?3=randon(l)is48x=random(l)is61x=random(l)is33x=random(l)is79x=random(l)is54x=randon(l)is71x三random(l)is12x=random(l)is42x=randon(l)is19搜狗拼音输入法全