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

    东北大学操作系统实验报告(共28页).docx

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

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

    东北大学操作系统实验报告(共28页).docx

    精选优质文档-倾情为你奉上计算机科学与工程学院实验报告实验课程名称操作系统实验实验成绩专业计算机科学与技术班级1507班指导教师签字学号姓名罗艺博实验报告批改时间实验项目目录1. 实验一 熟悉Linux系统2. 实验二 进程状态3. 实验三 进程同步和通信4. 实验四 进程的管道通信5. 实验五 页面置换算法实验报告正文实验一 熟悉Linux系统一、 实验目的熟悉和掌握Linux系统基本命令,熟悉Linux编程环境,为以后的实验打下基础。二、 实验原理基于linux系统的基础操作三、 实验内容(源码、注释、基础内容、扩展点等)启动、退出、ls(显示目录内容)、cp(文件或目录的复制)、mv(文件、目录更名或移动)、rm(删除文件或目录)、mkdir(创建目录)、rmdir(删除空目录)、cd(改变工作目录)C语言编辑、编译四、 实验结果(截图)ls mkdir:cd:rmdir:实验二 进程状态一、 实验目的自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容 、组织的变化,理解进程与其PCB间的一一对应关系。二、 实验原理1.进程在内存中存在三种基本状态:就绪态、执行态、阻塞态2.三种状态在满足某种条件时会发生转换:就绪运行:调度程序选择一个新的进程运行运行就绪:运行进程用完了时间片运行进程被中断,因为一高优先级进程处于就绪状态运行阻塞:当一进程等待某一事件的发生时,如请求系统服务; 初始化I/O 且必须等待结果; 无新工作可做; 等待某一进程提供输入 (IPC)阻塞就绪:当所等待的事件发生时三、 实验内容(源码、注释、基础内容、扩展点等)#include <iostream>#include <vector>#include <stdlib.h>#include <algorithm> /for "sort" in vectorusing namespace std;class Pro /process classpublic: char name; string status;vector<Pro> ru,re,bl; /ru->running,re->ready,bl->blocked/function declarationint helloUI();int iniQ();int showPCB();int ruTOre();int ruTObl();int blTOre();int neTOre();int ruTOex();int helloUI() /start UI cout << "Hello!Welcome to come back." << endl; cout << "#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#" << endl; cout << endl; cout << endl; return 0;int iniQ() /initialize the process int i; cout << "Please enter processes names and their status." << endl; cout << endl; for(i=0; i<5; i+) /15 process a to o Pro process; char nam; string sta; cout << "Please enter " << i <<" processes names." << endl; cin >> nam; process.name = nam; cout << "Please enter processes status." << endl; cout << "Status contains r1(running),r2(ready) and b(blocked)." << endl; cin >> sta; process.status = sta; if(sta = "r1") /judge which status if(ru.size()<1) ru.push_back(process); cout << "yes" << endl; else cout << "Error!" << endl; else if(sta = "r2") re.push_back(process); else if(sta = "b") bl.push_back(process); else cout << "Error!" << endl; cout << "" << endl; cout << endl; showPCB(); return 0;int showPCB() int i; cout << "running:" for(i=0; i<ru.size(); i+) cout << rui.name << "," cout << endl; cout << "ready:" for(i=0; i<re.size(); i+) cout << rei.name << "," cout << endl; cout << "blocked:" for(i=0; i<bl.size(); i+) cout << bli.name << "," cout << endl; return 0;int ruTOre() if(!ru.empty() /runningQueue is being used. re.push_back(ru.front(); /running's first process go to ready'last ru.erase(ru.begin(); /delete running's first process ru.push_back(re.front(); re.erase(re.begin(); else cout << "Error in ruTOre" << endl; showPCB(); return 0;int ruTObl() if(!ru.empty() /runningQueue is being used. bl.push_back(ru.front(); ru.erase(ru.begin(); if(!re.empty() ru.push_back(re.front(); re.erase(re.begin(); else cout << "Error in ruTObl1." << endl; else cout << "Error in ruTObl2." << endl; showPCB(); return 0;int blTOre() if(!bl.empty() /blockedQueue is not empty. re.push_back(bl.front(); bl.erase(bl.begin(); if(ru.empty() /runningQueue is empty,then ready->running ru.push_back(re.front(); re.erase(re.begin(); else cout << "Error in blTOre" << endl; showPCB(); return 0;int neTOre() int i; cout << "Please enter processes names and their status." << endl; cout << endl; Pro process; char nam; string sta; cout << "Please enter processes names." << endl; cin >> nam; process.name = nam; process.status = "r2" re.push_back(process); cout << "" << endl; cout << endl; if(ru.empty() ru.push_back(re.front(); re.erase(re.begin(); showPCB(); return 0;int ruTOex() if(!ru.empty() /runningQueue is being used. ru.erase(ru.begin(); if(!re.empty() ru.push_back(re.front(); re.erase(re.begin(); else cout << "Error in ruTOex1." << endl; else cout << "Error in ruTOex2." << endl; showPCB(); return 0;int main() int act; /choose action helloUI(); cout << "Please initialize the process." << endl; iniQ(); while(1) cout << "" << endl; cout << "Please select the action to take." << endl; cout << "2:running->ready" << endl; cout << "3:running->blocked" << endl; cout << "4:blocked->ready" << endl; cout << "5:new->ready" << endl; cout << "6:running->exit" << endl; cin >> act; if(act = 2) ruTOre(); else if(act = 3) ruTObl(); else if(act = 4) blTOre(); else if(act = 5) neTOre(); else if(act = 6) ruTOex(); else cout << "Error in select."<<endl; cout << "#" << endl; cout << endl; return 0;拓展点:五状态模型四、 实验结果(截图)创建进程:状态 running?ready:状态 running?blocked:状态 blocked?ready:创建新进程:情况一 有进程正在运行情况二 无进程正在运行终止进程:实验三 进程同步和通信一、实验目的调试、修改、运行模拟程序,通过形象化的状态显示,使学生理解进程的概念,了解同步和通信的过程,掌握进程通信和同步的机制,特别是利用缓冲区进行同步和通信的过程。通过补充新功能,使学生能灵活运用相关知识,培养创新能力。二、 实验原理假定.缓冲区可以容纳8个数据;因为缓冲区是有限的,因此当其满了时生产者进程应该等待;当消费者取走一个数据后,应唤醒正在等待的生产者进程;当缓冲区空时,消费者进程应该等待;当生产者向缓冲区放入了一个数据时,应唤醒正在等待的消费者进程。这就是生产者和消费者之间的同步三、 实验内容(源码、注释、基础内容、扩展点等)基础内容:编写程序使其模拟两个进程,即生产者(producer)进程和消费者(Consumer)进程工作;生产者每次产生一个数据,送入缓冲区中;消费者每次从缓冲区中取走一个数据。每次写入和读出数据时,都将读和写指针加一。当指针到达缓冲区尾,重新将指针退回起点;/*/* PROGRAM NAME: PRODUCER_CONSUMER */* This program simulates two processes, producer which */* continues to produce message and put it into a buffer */* implemented by PIPE, and consumer which continues to get */* message from the buffer and use it. */* The program also demonstrates the synchronism between */* processes and uses of PIPE. */*/#include <stdio.h>#include <stdlib.h>/#include <time.h>#define PIPESIZE 8#define PRODUCER 0#define CONSUMER 1#define RUN 0 /* statu of process */#define WAIT 1 /* statu of process */#define READY 2 /* statu of process */#define NORMAL 0#define SLEEP 1#define AWAKE 2#include <stdio.h>/Process Control block struct pcb char *name; int statu; int time; ; /* times of execution */ /Buffer struct pipetype char type; /type int writeptr; /Write pointer int readptr; /Read pointer struct pcb *pointp; /* write wait point */ struct pcb *pointc; ; /* read wait point */ int pipePIPESIZE; /Buffer array struct pipetype pipetb; struct pcb process2; /number of producer - number of consumer,buffer. count >= 8:too many prodecers; <=0:too many consumers int count=0; int countp=0,countr=0;main()int output,ret,i; /output->number of times, ret->present status char in2; int runp(),runc(),prn(); pipetb.type = 'c' pipetb.writeptr = 0; pipetb.readptr = 0; pipetb.pointp = pipetb.pointc = NULL; processPRODUCER.name = "Producer0" processCONSUMER.name = "Consumer0" processPRODUCER.statu = processCONSUMER.statu = READY; processPRODUCER.time = processCONSUMER.time = 0; output = 0;printf("Now starting the program!n"); printf(" Press 'p1' to run PRODUCER1, press 'p2' to run PRODUCER2.n press 'c' to run CONSUMER.n"); /PRODUCER1->product 1 new data, PRODUCER2->product 2 new data printf(" Press 'e' to exit from the program.n"); for(i=0;i<1000;i+)in0='N' while(in0='N')scanf("%s",in); if(in0!='e'&&in0!='p'&&in0!='c') /when not p,c,e continuein0='N' if(in0='p'&&processPRODUCER.statu=READY) /producer and ready if(in1 = '2') /producer2 int m; for(m=0;m<2;m+) if(countp > 3) /the number of waitting producer over 4,waitqueue=4 printf("wrong!n"); continue; if(count<8) /output = rand()%99+1; /099 output = (output+1)%100; if(ret=runp(output,process,pipe,&pipetb,PRODUCER)=SLEEP) /sleep,set write wait pointer pipetb.pointp = &processPRODUCER; if(ret=AWAKE) /awake,execute consumer (pipetb.pointc)->statu=READY; runc(process,pipe,&pipetb,CONSUMER); countr-; printf("countr=%dn",countr); if(countr=0) pipetb.pointc=NULL; else if(in1 = '1') /producer1 if(countp > 3) printf("wrong!n"); continue; if(count<8) /output = rand()%99+1; /099 output = (output+1)%100; if(ret=runp(output,process,pipe,&pipetb,PRODUCER)=SLEEP) /sleep pipetb.pointp = &processPRODUCER; if(ret=AWAKE) /awake (pipetb.pointc)->statu=READY; runc(process,pipe,&pipetb,CONSUMER); countr-; printf("countr=%dn",countr); if(countr=0)pipetb.pointc=NULL; if(in0='c'&&processCONSUMER.statu=READY) /consumer and readyif(ret=runc(process,pipe,&pipetb,CONSUMER)=SLEEP) /sleeppipetb.pointc = &processCONSUMER; if(ret=AWAKE) /awake(pipetb.pointp)->statu=READY;output=(output+1)%100; runp(output,process,pipe,&pipetb,PRODUCER);countp-;printf("countp=%dn",countp);if(countp=0)pipetb.pointp=NULL;if(in0='p'&&processPRODUCER.statu=WAIT) /producer and wait if(in1 = '2') /producer2 int m; for(m=0;m<2;m+) if(countp > 3) printf("wrong!n"); printf("PRODUCER is waiting, can't be scheduled.n"); continue; countp+; printf("countp=%dn",countp); else if(in1 = '1') /producer1 if(countp > 3) printf("wrong!n"); printf("PRODUCER is waiting, can't be scheduled.n"); continue; countp+; printf("countp=%dn",countp); printf("Look out.n");/printf("PRODUCER is waiting, can't be scheduled.n"); if(in0='c'&&processCONSUMER.statu=WAIT) /consumer and wait if(countr > 3) printf("wrong!n"); printf("CONSUMER is waiting, can't be scheduled.n"); continue; countr+;printf("countr=%dn",countr);printf("Look out!n"); /printf("CONSUMER is waiting, can't be scheduled.n"); if(in0='e') exit(1); prn(process,pipe,pipetb); in0='N' runp(out,p,pipe,tb,t) /* run producer */ int out,pipe,t; struct pcb p; struct pipetype *tb; pt.statu=RUN; printf("run PRODUCER. product %d ",out); if(count>=8) /buffer over 8 pt.statu=WAIT; return(SLEEP); tb->writeptr=tb->writeptr%8; /only has pipetb->writeptr=out; /change tb->writeptr+; printf("writeptr%dn",tb->writeptr); count+; printf("count=%dn",count); pt.time+; /printf("time+%dn",pt.time); pt.statu=READY; if(tb->pointc)!=NULL) /printf("返回AWAKE"); return(AWAKE); return(NORMAL); runc(p,pipe,tb,t) /* run consumer */ int pipe,t; struct pcb p; struct pipetype *tb; int c; pt.statu = RUN; printf("run CONSUMER. "); if(count<=0) /buffer too less pt.statu=WAIT; return(SLEEP); c=pipetb->readptr; pipetb->readptr=0; tb->readptr+; tb->readptr=tb->readptr%8; printf("readptr=%dn",tb->readptr); printf(" use %d ",c); count-; printf("count=%dn",count); pt.time+; /printf("time+%dn",pt.time); pt.statu=READY; if(tb->pointp!=NULL) /printf("返回AWAKEn"); return(AWAKE); return(NORMAL); prn(p,p

    注意事项

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

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




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

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

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

    收起
    展开