东北大学操作系统实验报告.docx
- 文档编号:884724
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:15
- 大小:18.64KB
东北大学操作系统实验报告.docx
《东北大学操作系统实验报告.docx》由会员分享,可在线阅读,更多相关《东北大学操作系统实验报告.docx(15页珍藏版)》请在冰点文库上搜索。
东北大学操作系统实验报告
公司内部档案编码:
[OPPTR-OPPT28-OPPTL98-OPPNN08]
东北大学操作系统实验报告
计算机科学与工程学院实验报告
实验课程名称
操作系统实验
实验成绩
专业
计算机科学与技术
班级
1507班
指导教师签字
学号
姓名
罗艺博
实验报告批改时间
实验项目目录
1.实验一熟悉Linux系统
2.实验二进程状态
3.实验三进程同步和通信
4.实验四进程的管道通信
5.实验五页面置换算法
实验报告正文
实验一熟悉Linux系统
一、实验目的
熟悉和掌握Linux系统基本命令,熟悉Linux编程环境,为以后的实验打下基础。
二、实验原理
基于linux系统的基础操作
三、实验内容(源码、注释、基础内容、扩展点等)
启动、退出、ls(显示目录内容)、cp(文件或目录的复制)、mv(文件、目录更名或移动)、rm(删除文件或目录)、mkdir(创建目录)、rmdir(删除空目录)、cd(改变工作目录)…
C语言编辑、编译
四、实验结果(截图)
lsmkdir:
cd:
rmdir:
实验二进程状态
一、实验目的
自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容、组织的变化,理解进程与其PCB间的一一对应关系。
二、实验原理
1.进程在内存中存在三种基本状态:
就绪态、执行态、阻塞态
2.三种状态在满足某种条件时会发生转换:
①就绪——》运行:
调度程序选择一个新的进程运行
②运行——》就绪:
运行进程用完了时间片
运行进程被中断,因为一高优先级进程处于就绪状态
③运行——》阻塞:
当一进程等待某一事件的发生时,如
请求系统服务;初始化I/O且必须等待结果;
无新工作可做;等待某一进程提供输入(IPC)
④阻塞——》就绪:
当所等待的事件发生时
三、实验内容(源码、注释、基础内容、扩展点等)
#include
#include
#include<>
#include cout<<"#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#"< cout< cout< return0; } intiniQ()< cout< for(i=0;i<5;i++)< cin>>nam; =nam; cout<<"Pleaseenterprocessesstatus."< cout<<"Statuscontainsr1(running),r2(ready)andb(blocked)."< cin>>sta; =sta; if(sta=="r1")ame<<","; } cout< cout<<"ready: "; for(i=0;i<();i++) { cout< } cout< cout<<"blocked: "; for(i=0;i<();i++) { cout< } cout< return0; } intruTOre() { if(! ()){ ());{ ()); ()); if(! ()) { ()); ()); } else cout<<"ErrorinruTObl1."< } else cout<<"ErrorinruTObl2."< showPCB(); return0; } intblTOre() { if(! ()){ ()); ()); if())< cout< Proprocess; charnam; stringsta; cout<<"Pleaseenterprocessesnames."< cin>>nam; =nam; ="r2"; (process); cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"< cout< if()) { ()); ()); } showPCB(); return0; } intruTOex() { if(! ()){ ()); if(! ()) { ()); ()); } else cout<<"ErrorinruTOex1."< } else cout<<"ErrorinruTOex2."< showPCB(); return0; } intmain() { intact;< iniQ(); while (1) { cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"< cout<<"Pleaseselecttheactiontotake."< cout<<"2: running-->ready"< cout<<"3: running-->blocked"< cout<<"4: blocked-->ready"< cout<<"5: new-->ready"< cout<<"6: running-->exit"< cin>>act; if(act==2) ruTOre(); elseif(act==3) ruTObl(); elseif(act==4) blTOre(); elseif(act==5) neTOre(); elseif(act==6) ruTOex(); else cout<<"Errorinselect."< cout<<"####################################"< cout< } return0; } 拓展点: 五状态模型 四、实验结果(截图) 创建进程: 状态running? ready: 状态running? blocked: 状态blocked? ready: 创建新进程: 情况一有进程正在运行 情况二无进程正在运行 终止进程: 实验三进程同步和通信 一、实验目的 调试、修改、运行模拟程序,通过形象化的状态显示,使学生理解进程的概念,了解同步和通信的过程,掌握进程通信和同步的机制,特别是利用缓冲区进行同步和通信的过程。 通过补充新功能,使学生能灵活运用相关知识,培养创新能力。 二、实验原理 假定.缓冲区可以容纳8个数据; 因为缓冲区是有限的,因此当其满了时生产者进程应该等待;当消费者取走一个数据后,应唤醒正在等待的生产者进程; 当缓冲区空时,消费者进程应该等待;当生产者向缓冲区放入了一个数据时,应唤醒正在等待的消费者进程。 这就是生产者和消费者之间的同步 三、实验内容(源码、注释、基础内容、扩展点等) 基础内容: 编写程序使其模拟两个进程,即生产者(producer)进程和消费者(Consumer)进程工作;生产者每次产生一个数据,送入缓冲区中;消费者每次从缓冲区中取走一个数据。 每次写入和读出数据时,都将读和写指针加一。 当指针到达缓冲区尾,重新将指针退回起点; /***************************************************************/ /*PROGRAMNAME: PRODUCER_CONSUMER*/ /*Thisprogramsimulatestwoprocesses,producerwhich*/ /*continuestoproducemessageandputitintoabuffer*/ /*[implementedbyPIPE],andconsumerwhichcontinuestoget*/ /*messagefromthebufferanduseit.*/ /*Theprogramalsodemonstratesthesynchronismbetween*/ /*processesandusesofPIPE.*/ /***************************************************************/ #include<> #include<> count>=8: toomanyprodecers;<=0: toomanyconsumers intcount=0; intcountp=0,countr=0; main() { intoutput,ret,i;ame="Producer\0"; process[CONSUMER].name="Consumer\0"; process[PRODUCER].statu=process[CONSUMER].statu=READY; process[PRODUCER].time=process[CONSUMER].time=0; output=0; printf("Nowstartingtheprogram! \n"); printf("Press'p1'torunPRODUCER1,press'p2'torunPRODUCER2.\npress'c'torunCONSUMER.\n"); n"); for(i=0;i<1000;i++) { in[0]='N'; while(in[0]=='N') { scanf("%s",in); if(in[0]! ='e'&&in[0]! ='p'&&in[0]! ='c')tatu==READY)tatu==READY)tatu==WAIT)n"); continue; } countp++; printf("countp=%d\n",countp); } } elseif(in[1]=='1')n"); continue; } countp++; printf("countp=%d\n",countp); } printf("Lookout.\n"); n"); } if(in[0]=='c'&&process[CONSUMER].statu==WAIT)n"); continue; } countr++; printf("countr=%d\n",countr); printf("Lookout! ! ! \n"); n"); } if(in[0]=='e')exit (1); prn(process,pipe,pipetb);in[0]='N'; } } runp(out,p,pipe,tb,t)/*runproducer*/ intout,pipe[],t; structpcbp[]; structpipetype*tb; { p[t].statu=RUN; printf("runPRODUCER.product%d",out); if(count>=8)tatu=WAIT; return(SLEEP); } tb->writeptr=tb->writeptr%8;ime++; ime); p[t].statu=READY; if((tb->pointc)! =NULL) { tatu=RUN; printf("runCONSUMER."); if(count<=0)tatu=WAIT; return(SLEEP); } c=pipe[tb->readptr]; pipe[tb->readptr]=0; tb->readptr++; tb->readptr=tb->readptr%8; printf("readptr=%d\n",tb->readptr); printf("use%d",c); count--; printf("count=%d\n",count); p[t].time++; ime); p[t].statu=READY; if(tb->pointp! =NULL) { tatu==WAIT)||countp>=1)tatu==WAIT)||countr>=1) printf("%dCONSUMERwait",countr); else printf("CONSUMERready"); printf("\n"); printf("\n######################\n"); } 拓展点: 设置了等待队列的长度,并显示等待队列内部情况 四、实验结果(截图) 生产者: 情况一正常生产 情况二超过缓冲区 情况三超过等待队列 消费者: 情况一正常 情况二无产品可消费 又开始生产: 实验四进程的管道通信 一、实验目的 加深对进程概念的理解,明确进程和程序的区别; 学习进程创建的过程,进一步认识并发执行的实质; 分析进程争用资源的现象,学习解决进程互斥的方法; 学习解决进程同步的方法; 掌握Linux系统进程间通过管道通信的具体实现方法。 二、实验原理 1.基本概念: 进程的概念;进程与程序的区别;并发执行的概念 进程互斥的概念;进程通信的基本原理 2.系统调用: 设置系统调用号: 设置多条系统调用命令,并赋予每条系统调用命令一个唯一的系统调用号 处理系统调用: OS中有一张系统调用入口表,表中每个表目对应一条系统调用命令,包含该系统调用自带参数的数目、系统调用命令处理程序的入口地址等。 OS内核便是根据所输入的系统调用号在该表中查找到相应的系统调用,进而转入它的入口地址去执行系统调用程序。 Linux的系统调用机制: 通过中断机制实现 三、实验内容(源码、注释、基础内容、扩展点等) #include<> #include<> #include<> #include #include intmain() { intpid1,pid2,pid3; intfd[2]; charoutpipe[50],inpipe[50]; pipe(fd); while((pid1=fork())==-1); if(pid1==0) { printf("s1\n"); lockf(fd[1],1,0); \n",diseffect/total_instruction); printf("TheHitRateis: %f.\n",1-diseffect/total_instruction); return0; } \n",diseffect/total_instruction); printf("TheHitRateis: %f.\n",1-diseffect/total_instruction); return0; } intFIFO4(intAcess_series[]){ intM_Frame[4];\n",diseffect/total_instruction); printf("TheHitRateis: %f.\n",1-diseffect/total_instruction); return0; } intmain() { intn,m; srand((int)time(NULL));//Initializationofrandomnumbergenerators //Initializepageaccesssequence12345 intAcess_series[total_instruction]; for(inti=0;i Acess_series[i]=(int)rand()%5+1; printf("TheAcess_seriesare: \n"); for(inti=0;i printf("%d",Acess_series[i]); printf("\n"); //Create2childprocesses intp1,p2,fd[2]; if((p1=fork())==0) { if((p2=fork())==0) { LRU(Acess_series); sleep (2); exit(0); } else { FIFO3(Acess_series); FIFO4(Acess_series); sleep (2); exit(0); } } else exit(0); return0; } 拓展点: 能显示每次的命中情况 一、实验结果(截图) 会出现Belady现象:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东北大学 操作系统 实验 报告