东北大学操作系统实验报告.doc

上传人:jian****018 文档编号:9377054 上传时间:2020-04-05 格式:DOC 页数:23 大小:961.50KB
返回 下载 相关 举报
东北大学操作系统实验报告.doc_第1页
第1页 / 共23页
东北大学操作系统实验报告.doc_第2页
第2页 / 共23页
东北大学操作系统实验报告.doc_第3页
第3页 / 共23页
点击查看更多>>
资源描述
课程编号:B080000070操作系统实验报告姓名班级指导教师石凯实验名称操作系统实验开设学期2016-2017第二学期开设时间第11周第18周报告日期2017年7月3日评定成绩评定人石凯评定日期2017年7月5日东北大学软件学院实验一 进程的同步与互斥实验题目:通过学习和分析基础例子程序,使用windows进程和线程编程(也可以采用Java 或Unix/Linux的POSIX线程编程)实现一个简单的生产者/消费者问题的程序。关键代码:import java.util.ArrayList; public class Produce public Object object; public ArrayList list;/用list存放生产之后的数据,最大容量为1 public Produce(Object object,ArrayList list ) this.object = object; this.list = list; public void produce() synchronized (object) /*只有list为空时才会去进行生产操作*/ try while(!list.isEmpty() System.out.println(生产者+Thread.currentThread().getName()+ waiting); object.wait(); int value = 9999; list.add(value); System.out.println(生产者+Thread.currentThread().getName()+ Runnable); object.notifyAll();/然后去唤醒因object调用wait方法处于阻塞状态的线程 catch (InterruptedException e) e.printStackTrace(); import java.util.ArrayList;public class Consumer public Object object; public ArrayList list;/用list存放生产之后的数据,最大容量为1 public Consumer(Object object,ArrayList list ) this.object = object; this.list = list; public void consmer() synchronized (object) try /*只有list不为空时才会去进行消费操作*/ while(list.isEmpty() System.out.println(消费者+Thread.currentThread().getName()+ waiting); object.wait(); list.clear(); System.out.println(消费者+Thread.currentThread().getName()+ Runnable); object.notifyAll();/然后去唤醒因object调用wait方法处于阻塞状态的线程 catch (InterruptedException e) e.printStackTrace(); 实验结果:思考题:(1)如何控制进程间的相互通信?答:主要有:管道,信号,共享内存,消息队列(2)什么是进程的同步?什么是进程的互斥?分别有哪些实现方式?答:进程互斥是进程之间的间接制约关系。当一个进程进入临界区使用临界资源时,另一个进程必须等待。只有当使用临界资源的进程退出临界区后,这个进程才会解除阻塞状态。进程同步也是进程之间直接的制约关系,是为完成某种任务而建立的两个或多个线程,这个线程需要在某些位置上协调他们的工作次序而等待、传递信息所产生的制约关系。进程间的直接制约关系来源于他们之间的合作。可以利用信号量来实现进程的同步与互斥。实验二 处理机调度实验题目:设计一个按优先权调度算法实现处理器调度的程序数据结构及符号说明: typedef struct pb /每个进程char pname5; /进程的名字char status8; /进程的状态int time; /要求运行时间int pri; /进程的优先权int cputime; /cpu时间struct pb *p; /队列结构,它的下一个。pbc, *pbcp;流程设计:关键代码: void attemper(pbcp pbca) pbcp pItem = pbca-p;pbcp pIterator = pbca-p;while (pIterator!= NULL) if (pItem-pri pri&pIterator-time != 0) pItem = pIterator;pIterator = pIterator-p;if (pItem-time -= 1) = 0) pItem-cputime += 1;pItem-pri -= 1;strcpy(pItem-status, finish);else strcpy(pItem-status, run);pItem-cputime += 1;pItem-pri -= 1;strcpy(pItem-status, run);pIterator = pbca-p;while (pIterator != NULL) if (pIterator-cputime != 0&pIterator!=pItem&pIterator-time!=0) pIterator-cputime += 1;strcpy(pIterator-status, ready);pIterator = pIterator-p;printPbc(pbca); 运行结果: 思考题:(1)处理机调度的目的?答:主要还是为了优化软件的运行。(2)你实现优先权调度算法的思想?答:遍历一次,取出优先权最高的,判断该进程是否还要运行,要允许就运行它。 实验三 存储管理实验题目:模拟分页式存储管理中硬件的地址转换和产生缺页中断。用先进先出(FIFO)页面调度算法处理缺页中断。数据结构及符号说明:int paper_table75 /7乘5的页表char *oper_char12 /每次操作int oper_table122 /指令序列的单元号和操作存储int fifo_table4 / 先进先出表,记录那几个在内存中int static count = 0; /记下哪个先来的流程设计:核心代码:void scheduler(void)int i, page, page_block, page_move;for (i = 0; i12; i+)page = *(oper_table + i);printf(-%d-n, i);if (*(*(paper_table + page) + 1) = 1) /在页表中page_block = *(*(paper_table + page) + 2);page_move = *(*(oper_table + i) + 1);printf(在内存中,块号:%d;偏移量:%d;物理地址:%dn, page_block, page_move, page_block * 128 + page_move);*(*(paper_table + count) + 4) = 1;/修改变为1fifo_print();else if (*(*(paper_table + fifo_tablecount % 4) + 4) = 1) printf(缺页中断,被替换的页号为:%d;页修改存入硬盘n, fifo_tablecount);*(*(paper_table + fifo_tablecount % 4) + 4) = 0;else printf(缺页中断,被替换的页号为:%d;页被直接替换n, fifo_tablecount);*(*(paper_table + page) + 1) = 1;/移入内存,改变在内存中的标志为1*(*(paper_table + fifo_tablecount) + 1) = 0;/改变在内存中的标志为0*(*(paper_table + page) + 2) = *(*(paper_table + fifo_tablecount) + 2);/重置页表里的主存块号值*(*(paper_table + fifo_tablecount) + 2) = 0;/重置页表里的主存块号值fifo_tablecount % 4 = *(*(oper_table + i) + 0);/更新fifo表page_block = *(*(paper_table + page) + 2);page_move = *(*(oper_table + i) + 1);printf(换入内存成功,块号:%d;偏移量:%d;物理地址:%d;n, page_block, page_move, page_block * 128 + page_move);fifo_print();count+;count = count % 4;printf(n);实验结果: 思考题:(1)先进先出页面调度算法的思想?答:基本思想:先进入内存的页面先淘汰,后进入内存的后淘汰(2)最近最少用(LRU)页面调度算法思想?答:基本思想:最近用的最少的最先淘汰。(3)比较两种调度算法的效率(哪种调度算法使产生缺页中断的次数少)? 答:从作业题我感觉最近最少使用优于先进先出。(4)分析在什么情况下采用哪种调度算法更有利? 答:如果页访问高度随机的话,不见得LRU好,LRU是根据最近最少使用的来决定哪个页表被替换,但过去很多时候不能代表未来。实验四 文件系统实验题目: 用高级语言编写和调试一个简单的文件系统,模拟文件管理的工作过程。数据结构及符号说明:struct TYPE_UFD /主文件目录 stringFile_Name; /文件名boolRead; /是否可读可写可执行boolWrite; boolExecute;intLength_File; /文件长度;struct TYPE_MFD /用户文件目录stringUser_Name; /用户名TYPE_UFD*Pointer;struct TYPE_AFD /打开文件目录,即运行文件目录intFile_ID; /文件IDboolRead;boolWrite;boolExecute;intPointer;class TYPE_FILE_SYSTEM /文件系统类public:void Initial(void);void Start(void);private:int_Number_Users; /用户数int_Number_Files; /文件数int_MaxNumber_Open_Files; /最大打开文件数TYPE_MFD *_MFD;TYPE_UFD *_UFD;TYPE_AFD *_AFD; 流程设计:关键代码:void TYPE_FILE_SYSTEM:Start(void)int User_ID;int i, temp_int;string temp;char choice;int Number_Open_Files;string User_Name;string Command;TYPE_UFD *UFD;dodocout 已创建指令有:create delete open dir diropen write read logout shutdown nn;cout User_Name;for (User_ID = 0; User_ID_Number_Users; User_ID+)if (_MFDUser_ID.User_Name = User_Name)break;if (User_ID = _Number_Users)cout 用户名错误,请再次输入 . endl; while (User_ID = _Number_Users);cout 欢迎登录 , User_Name ! endl;UFD = _MFDUser_ID.Pointer;for (i = 0; i_MaxNumber_Open_Files; i+)_AFDi.File_ID = -1;Number_Open_Files = 0;docout C: User_Name ;cin Command;if (Command = dir)cout endl;cout 打开用户 User_Name 的文件 endl;cout t Statet Lengtht File name endl;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1)cout t;if (UFDi.Read = true)cout R;elsecout -;if (UFDi.Write = true)cout W;elsecout -;if (UFDi.Execute = true)cout E;elsecout -;cout t;cout UFDi.Length_File;cout t;cout UFDi.File_Name endl;cout endl;else if (Command = diropen)cout endl;cout 打开用户 User_Name 的文件 endl;cout t Statet Open File name endl;for (i = 0; i_MaxNumber_Open_Files; i+)if (_AFDi.File_ID != -1)cout t;if (_AFDi.Read = true)cout R;elsecout -;if (_AFDi.Write = true)cout W;elsecout -;if (_AFDi.Execute = true)cout E;elsecout -;cout t;cout UFD_AFDi.File_ID.File_Name endl;cout endl;else if (Command = create)for (i = 0; i_Number_Files; i+)if (UFDi.Length_File = -1)break;if (i = _Number_Files)cout Error: 已有名为 _Number_Files 的文件. endl;elsecout 请输入新文件信息: endl;cout temp;UFDi.File_Name = temp;cout 文件权限 : ;cout Read (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)UFDi.Read = true;elseUFDi.Read = false;cout endl;cout Write (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)UFDi.Write = true;elseUFDi.Write = false;cout endl;cout Execute (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)UFDi.Execute = true;elseUFDi.Execute = false;cout endl;cout temp_int;if (temp_int 0)UFDi.Length_File = temp_int;cout 新文件 UFDi.File_Name 已建立! endl;else if (Command = delete)cout temp;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1) & (UFDi.File_Name = temp)break;if (i = _Number_Files)cout 文件名错误,请再次输入 . endl;elseUFDi.Length_File = -1;cout 文件 UFDi.File_Name 已删除 . endl;else if (Command = open)if (Number_Open_Files = _MaxNumber_Open_Files)cout Error: 你已经打开了 Number_Open_Files 文件. endl;elsecout temp;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1) & (UFDi.File_Name = temp)break;if (i = _Number_Files)cout 文件名错误,请再次输入 . endl;elseNumber_Open_Files+;for (temp_int = 0; temp_int_MaxNumber_Open_Files; temp_int+)if (_AFDtemp_int.File_ID = -1)break;_AFDtemp_int.File_ID = i;_AFDtemp_int.Pointer = 0;cout 请定义打开方式 : endl;if (UFDi.Read = true)cout Read (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)_AFDtemp_int.Read = true;else_AFDtemp_int.Read = false;cout endl;else_AFDtemp_int.Read = false;if (UFDi.Write = true)cout Write (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)_AFDtemp_int.Write = true;else_AFDtemp_int.Write = false;cout endl;else_AFDtemp_int.Write = false;if (UFDi.Execute = true)cout Execute (y/n):;dochoice = getch(); while (choice != y & choice != n);if (choice = y)_AFDtemp_int.Execute = true;else_AFDtemp_int.Execute = false;cout endl;else_AFDtemp_int.Execute;cout 文件 temp 已打开 . endl;else if (Command = logout)cout 再见 , User_Name ! endl;break;else if (Command = close)cout temp;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1) & (UFDi.File_Name = temp)break;if (i = _Number_Files)cout 文件名错误,请再次输入 . endl;elsefor (temp_int = 0; temp_int_MaxNumber_Open_Files; temp_int+)if (_AFDtemp_int.File_ID = i)break;if (temp_int = _MaxNumber_Open_Files)cout 文件 temp 未打开 . endl;else_AFDtemp_int.File_ID = -1;Number_Open_Files-;cout 文件 temp 已关闭 . endl;else if (Command = read)cout temp;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1) & (UFDi.File_Name = temp)break;if (i = _Number_Files)cout 文件名错误,请再次输入 . endl;elsefor (temp_int = 0; temp_int_MaxNumber_Open_Files; temp_int+)if (_AFDtemp_int.File_ID = i)break;if (temp_int = _MaxNumber_Open_Files)cout 文件 temp 未打开 . endl;elseif (_AFDtemp_int.Read = true)cout 文件 temp 成功读取. endl;elsecout Error: 文件打开模式错误 . endl;else if (Command = write)cout temp;for (i = 0; i_Number_Files; i+)if (UFDi.Length_File != -1) & (UFDi.File_Name = temp)break;if (i = _Number_Files)cout 文件名错误,请再次输入 . endl;elsefor (temp_int = 0; temp_int_MaxNumber_Open_Files; temp_int+)if (_AFDtemp_int.File_ID = i)break;if (temp_int = _MaxNumber_Open_Files)cout 文件 temp 未打开 . endl;elseif (_AFDtemp_int.Write = true)cout 文件 temp 成功写入. endl;elsecout Error: 文件打开模式错误 . endl;else if (Command = shutdown)cout 正在注销. endl;cout 再见 , User_Name ! endl;cout 正在关机. endl;break;elsecout 指令错误,请再次输入 . endl; while (Command != logout & Command != shutdown); while (Command != shutdown);实验结果:评价表格考核标准得分(1)正确理解和掌握实验所涉及的概念和原理(20%);(2)按实验要求合理设计数据结构和程序结构(20%);(3)运行结果正确(20%);(4)认真记录实验数据,原理及实验结果分析准确(20%);(5)实验过程中,具有严谨的学习态度和认真、踏实、一丝不苟的科学作风(10%);(7)实验报告规范(10%)。合计
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 大学资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


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