《操作系统》习题课分析
(完整版)操作系统第五版费祥林_课后习题答案解析参考

第一章操作系统概论1、有一台计算机,具有IMB 内存,操作系统占用200KB ,每个用户进程各占200KB 。
如果用户进程等待I/O 的时间为80 % ,若增加1MB 内存,则CPU 的利用率提高多少?答:设每个进程等待I/O 的百分比为P ,则n 个进程同时等待刀O 的概率是Pn ,当n 个进程同时等待I/O 期间CPU 是空闲的,故CPU 的利用率为1-Pn。
由题意可知,除去操作系统,内存还能容纳4 个用户进程,由于每个用户进程等待I/O的时间为80 % , 故:CPU利用率=l-(80%)4 = 0.59若再增加1MB 内存,系统中可同时运行9 个用户进程,此时:cPu 利用率=l-(1-80%)9 = 0.87故增加IMB 内存使CPU 的利用率提高了47 % :87 %/59 %=147 %147 %-100 % = 47 %2 一个计算机系统,有一台输入机和一台打印机,现有两道程序投入运行,且程序A 先开始做,程序B 后开始运行。
程序A 的运行轨迹为:计算50ms 、打印100ms 、再计算50ms 、打印100ms ,结束。
程序B 的运行轨迹为:计算50ms 、输入80ms 、再计算100ms ,结束。
试说明(1 )两道程序运行时,CPU有无空闲等待?若有,在哪段时间内等待?为什么会等待?( 2 )程序A 、B 有无等待CPU 的情况?若有,指出发生等待的时刻。
答:画出两道程序并发执行图如下:(1)两道程序运行期间,CPU存在空闲等待,时间为100 至150ms 之间(见图中有色部分)(2)程序A 无等待现象,但程序B 有等待。
程序B 有等待时间段为180rns 至200ms 间(见图中有色部分)3 设有三道程序,按A 、B 、C优先次序运行,其内部计算和UO操作时间由图给出。
试画出按多道运行的时间关系图(忽略调度执行时间)。
完成三道程序共花多少时间?比单道运行节省了多少时间?若处理器调度程序每次进行程序转换化时lms , 试画出各程序状态转换的时间关系图。
操作系统第二版课后习题答案

操作系统第二版课后习题答案操作系统第二版课后习题答案操作系统是计算机科学中的重要领域,它负责管理计算机硬件和软件资源,为用户提供良好的使用体验。
在学习操作系统的过程中,课后习题是巩固和深化知识的重要方式。
本文将为大家提供操作系统第二版课后习题的答案,帮助读者更好地理解和掌握操作系统的知识。
第一章:引论1. 操作系统的主要功能包括进程管理、内存管理、文件系统管理和设备管理。
2. 进程是指正在执行的程序的实例。
进程控制块(PCB)是操作系统用来管理进程的数据结构,包含进程的状态、程序计数器、寄存器等信息。
3. 多道程序设计是指在内存中同时存放多个程序,通过时间片轮转等调度算法,使得多个程序交替执行。
4. 异步输入输出是指程序执行期间,可以进行输入输出操作,而不需要等待输入输出完成。
第二章:进程管理1. 进程调度的目标包括提高系统吞吐量、减少响应时间、提高公平性等。
2. 进程调度算法包括先来先服务(FCFS)、最短作业优先(SJF)、优先级调度、时间片轮转等。
3. 饥饿是指某个进程长时间得不到执行的情况,可以通过调整优先级或引入抢占机制来解决。
4. 死锁是指多个进程因为争夺资源而陷入无限等待的状态,可以通过资源预分配、避免环路等方式来避免死锁。
第三章:内存管理1. 内存管理的主要任务包括内存分配、内存保护、地址转换等。
2. 连续内存分配包括固定分区分配、可变分区分配和动态分区分配。
3. 分页和分段是常见的非连续内存分配方式,分页将进程的地址空间划分为固定大小的页,分段将进程的地址空间划分为逻辑段。
4. 页面置换算法包括最佳置换算法、先进先出(FIFO)算法、最近最久未使用(LRU)算法等。
第四章:文件系统管理1. 文件是操作系统中用来存储和组织数据的逻辑单位,可以是文本文件、图像文件、音频文件等。
2. 文件系统的主要功能包括文件的创建、删除、读取、写入等操作。
3. 文件系统的组织方式包括层次目录结构、索引结构、位图结构等。
操作系统课后部分习题及答案

第2章操作系统的运行环境2.2 现代计算机为什么设置目态/管态这两种不同的机器状态?现在的lntel80386设置了四级不同的机器状态(把管态又分为三个特权级),你能说出自己的理解吗?答:现在的Intel 80386把执行全部指令的管态分为三个特权级,再加之只能执行非特权指令的目态,这四级不同的机器状态,按照系统处理器工作状态这四级不同的机器状态也被划分管态和目态,这也完全符合处理器的工作状态。
2.6 什么是程序状态字?主要包括什么内容?答:如何知道处理器当前处于什么工作状态,它能否执行特权指令,以及处理器何以知道它下次要执行哪条指令呢?为了解决这些问题,所有的计算机都有若干的特殊寄存器,如用一个专门的寄存器来指示一条要执行的指令称程序计数器PC,同时还有一个专门的寄存器用来指示处理器状态的,称为程序状态字PSW。
主要内容包括所谓处理器的状态通常包括条件码--反映指令执行后的结果特征;中断屏蔽码--指出是否允许中断,有些机器如PDP-11使用中断优先级;CPU的工作状态--管态还是目态,用来说明当前在CPU上执行的是操作系统还是一般用户,从而决定其是否可以使用特权指令或拥有其它的特殊权力。
2.11 CPU如何发现中断事件?发现中断事件后应做什么工作?答:处理器的控制部件中增设一个能检测中断的机构,称为中断扫描机构。
通常在每条指令执行周期内的最后时刻中扫描中断寄存器,询为是否有中断信号到来。
若无中断信号,就继续执行下一条指令。
若有中断到来,则中断硬件将该中断触发器内容按规定的编码送入程序状态字PSW的相应位(IBM-PC中是第16~31位),称为中断码。
发现中断事件后应执行相中断处理程序,先由硬件进行如下操作:1、将处理器的程序状态字PSW压入堆栈2、将指令指针IP(相当于程序代码段落的段内相对地址)和程序代码段基地址寄存器CS的内容压入堆栈,以保存被子中断程序的返回地址。
3、取来被接受的中断请求的中断向量地址(其中包含有中断处理程序的IP,CS的内容),以便转入中断处理程序。
操作系统习题 (2)

计算5
某磁盘共有200个柱面,每个柱面20个磁道,每个磁道8个扇区,每个扇区1024B。 如果驱动程序接到请求是读取606块,计算该信息块的物理位置?
答案: 每个柱面的物理块数为:20*8=160块 606/160的商为3,余数为126。 即,物理位置为:第3柱面的126个物理块
7
计算6
• 假定磁带记录密度为每英寸800字符,每一逻辑 记录为160个字符,块间隙为0.6英寸。今有1500 个逻辑记录要存储,尝试(1)计算磁带利用率? (2)1500个逻辑记录占用多少磁带空间?(3) 若要使磁带空间利用率不少于50%,至少应以多 少个逻辑记录为一组?
2
分析2
• 假设用下列流程将一批数据以串行方式从输入设备送至磁盘,在硬件提供通 路的情况下,软件如何将下述流程改造为并行方式(外设与外设间并行)
• 流程: (1)启动输入设备将一块数据读入内存缓冲区 (2)等待输入结束 (3)启动磁盘设备将缓冲区中信息写盘 (4)等待写盘结束 (5)转第一步,直至一批数据传输结束
率,也带来一种危险,会出现“死锁”。
5
计算4
• 磁盘系统调度中,采用SCAN调度算法为任务队列 67/65/124/14/122/37/183/98服务。当计算任务结束时,磁头总共移动了 多少个磁道?假设磁头总在第0道至第199道之间移动;开始服务时,磁头 刚从60移到67。
解答:
磁头移动的顺序: 67、98、122、124、183、65、37、14 共285个磁道
(1)间隙可存放的字符数是: (3)设组成块因子为x,则有
800*0.6=480个字符,
(160*X/(480+160X)>=50%
此时的磁带利用率:
操作系统(1~8章的课后习题答案)

1.1:存储程序式计算机的主要特点是:集中顺序过程控制(1)过程性:模拟人们手工操作(2)集中控制:由CPU集中管理(3)顺序性:程序计数器1.2:a:批处理系统的特点:早期批处理有个监督程序,作业自动过渡直到全部处理完,而脱机批处理的特点:主机与卫星机并行操作。
b:分时系统的特点:(1):并行性。
共享一台计算机的众多联机用户可以在各自的终端上同时处理自己的程序。
(2):独占性。
分时操作系统采用时间片轮转的方法使一台计算机同时为许多终端上同时为许多终端用户服务,每个用户的感觉是自己独占计算机。
操作系统通过分时技术将一台计算机改造为多台虚拟计算机。
(3):交互性。
用户与计算机之间可以进行“交互会话”,用户从终端输入命令,系统通过屏幕(或打印机)将信息反馈给用户,用户与系统这样一问一答,直到全部工作完成。
c:分时系统的响应比较快的原因:因为批量操作系统的作业周转时间较长,而分时操作系统一般采用时间片轮转的方法,一台计算机与许多终端设备连接,使一台计算机同时为多个终端用户服务,该系统对每个用户都能保证足够快的响应时间,并提供交互会话功能。
1.3:实时信息处理系统和分时系统的本质区别:实时操作系统要追求的目标是:对外部请求在严格时间范围内做出反应,有高可靠性和完整性。
其主要特点是资源的分配和调度首先要考虑实时性然后才是效率。
此外,实时操作系统应有较强的容错能力,分时操作系统的工作方式是:一台主机连接了若干个终端,每个终端有一个用户在使用。
用户交互式地向系统提出命令请求,系统接受每个用户的命令,采用时间片轮转方式处理服务请求,并通过交互方式在终端上向用户显示结果。
用户根据上步结果发出下道命。
分时操作系统将CPU 的时间划分成若干个片段,称为时间片。
操作系统以时间片为单位,轮流为每个终端用户服务。
每个用户轮流使用一个时间片而使每个用户并不感到有别的用户存在。
分时系统具有多路性、交互性、“独占”性和及时性的特征。
操作系统课后习题总结(清华大学出版社)

习题二参考答案4、答:在生产者—消费者问题中,Producer进程中P(empty)和P(mutex)互换先后次序。
先执行P(mutex),假设成功,生产者进程获得对缓冲区的访问权,但如果此时缓冲池已满,没有空缓冲区可供其使用,后续的P(empty)原语没有通过,Producer阻塞在信号量empty 上,而此时mutex已被改为0,没有恢复成初值1。
切换到消费者进程后,Consumer进程执行P(full)成功,但其执行P(mutex)时由于Producer正在访问缓冲区,所以不成功,阻塞在信号量mutex上。
生产者进程和消费者进程两者均无法继续执行,相互等待对方释放资源,会产生死锁。
在生产者和消费者进程中,V操作的次序无关紧要,不会出现死锁现象。
5、答:6、答:设信号量sp用于控制对盘子的互斥操作,信号量sg1用于计数,表示盘子中的苹果数目,信号量sg2用于计数,表示盘子中的桔子数目。
Semaphore sp=1,sg1=0,sg2=0dad(){while(1){ prepare an apple;p(sp);put an apple on the plate;v(sg2);}}mom(){while(1){prepare an orange;p(sp);put an orange on the plate;v(sg1);}}son(){while(1){p(sg1);take an orange from the plate;v(sg);eat the orange;}}daughter(){while(1){p(sg2);take an apple from the plate;v(sg);eat the apple;}}7、答:为了使写者优先,在原来的读优先算法基础上增加一个初值为1的信号量S,使得当至少有一个写者准备访问共享对象时,它可使后续的读者进程等待写完成;初值为0的整型变量writecount,用来对写者进行计数;初值为1的互斥信号量wmutex,用来实现多个写者对writecount的互斥访问。
最新操作系统第九版部分课后作业习题答案分析解析

CHAPTER 9 Virtual Memory Practice Exercises9.1 Under what circumstances do page faults occur? Describe the actions taken by the operating system when a page fault occurs.Answer:A page fault occurs when an access to a page that has not beenbrought into main memory takes place. The operating system verifiesthe memory access, aborting the program if it is invalid. If it is valid, a free frame is located and I/O is requested to read the needed page into the free frame. Upon completion of I/O, the process table and page table are updated and the instruction is restarted.9.2 Assume that you have a page-reference string for a process with m frames (initially all empty). The page-reference string has length p;n distinct page numbers occur in it. Answer these questions for any page-replacement algorithms:a. What is a lower bound on the number of page faults?b. What is an upper bound on the number of page faults?Answer:a. nb. p9.3 Consider the page table shown in Figure 9.30 for a system with 12-bit virtual and physical addresses and with 256-byte pages. The list of freepage frames is D, E, F (that is, D is at the head of the list, E is second, and F is last).Convert the following virtual addresses to their equivalent physical addresses in hexadecimal. All numbers are given in hexadecimal. (A dash for a page frame indicates that the page is not in memory.)• 9EF• 1112930 Chapter 9 Virtual Memory• 700• 0FFAnswer:• 9E F - 0E F• 111 - 211• 700 - D00• 0F F - EFF9.4 Consider the following page-replacement algorithms. Rank these algorithms on a five-point scale from “bad” to “perfect” according to their page-fault rate. Separate those algorithms that suffer from Belady’s anomaly from those that do not.a. LRU replacementb. FIFO replacementc. Optimal replacementd. Second-chance replacementAnswer:Rank Algorithm Suffer from Belady’s anomaly1 Optimal no2 LRU no3 Second-chance yes4 FIFO yes9.5 Discuss the hardware support required to support demand paging. Answer:For every memory-access operation, the page table needs to be consulted to check whether the corresponding page is resident or not and whether the program has read or write privileges for accessing the page. These checks have to be performed in hardware. A TLB could serve as a cache and improve the performance of the lookup operation.9.6 An operating system supports a paged virtual memory, using a central processor with a cycle time of 1 microsecond. It costs an additional 1 microsecond to access a page other than the current one. Pages have 1000 words, and the paging device is a drum that rotates at 3000 revolutions per minute and transfers 1 million words per second. The following statistical measurements were obtained from the system:• 1 percent of all instructions executed accessed a page other than the current page.•Of the instructions that accessed another page, 80 percent accesseda page already in memory.Practice Exercises 31•When a new page was required, the replaced page was modified 50 percent of the time.Calculate the effective instruction time on this system, assuming that the system is running one process only and that the processor is idle during drum transfers.Answer:effective access time = 0.99 × (1 sec + 0.008 × (2 sec)+ 0.002 × (10,000 sec + 1,000 sec)+ 0.001 × (10,000 sec + 1,000 sec)= (0.99 + 0.016 + 22.0 + 11.0) sec= 34.0 sec9.7 Consider the two-dimensional array A:int A[][] = new int[100][100];where A[0][0] is at location 200 in a paged memory system with pages of size 200. A small process that manipulates the matrix resides in page 0 (locations 0 to 199). Thus, every instruction fetch will be from page 0. For three page frames, how many page faults are generated bythe following array-initialization loops, using LRU replacement andassuming that page frame 1 contains the process and the other twoare initially empty?a. for (int j = 0; j < 100; j++)for (int i = 0; i < 100; i++)A[i][j] = 0;b. for (int i = 0; i < 100; i++)for (int j = 0; j < 100; j++)A[i][j] = 0;Answer:a. 5,000b. 509.8 Consider the following page reference string:1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.How many page faults would occur for the following replacement algorithms, assuming one, two, three, four, five, six, or seven frames? Remember all frames are initially empty, so your first unique pages will all cost one fault each.•LRU replacement• FIFO replacement•Optimal replacement32 Chapter 9 Virtual MemoryAnswer:Number of frames LRU FIFO Optimal1 20 20 202 18 18 153 15 16 114 10 14 85 8 10 76 7 10 77 77 79.9 Suppose that you want to use a paging algorithm that requires a referencebit (such as second-chance replacement or working-set model), butthe hardware does not provide one. Sketch how you could simulate a reference bit even if one were not provided by the hardware, or explain why it is not possible to do so. If it is possible, calculate what the cost would be.Answer:You can use the valid/invalid bit supported in hardware to simulate the reference bit. Initially set the bit to invalid. O n first reference a trap to the operating system is generated. The operating system will set a software bit to 1 and reset the valid/invalid bit to valid.9.10 You have devised a new page-replacement algorithm that you thinkmaybe optimal. In some contorte d test cases, Belady’s anomaly occurs. Is the new algorithm optimal? Explain your answer.Answer:No. An optimal algorithm will not suffer from Belady’s anomaly because —by definition—an optimal algorithm replaces the page that will notbe used for the long est time. Belady’s anomaly occurs when a pagereplacement algorithm evicts a page that will be needed in the immediatefuture. An optimal algorithm would not have selected such a page.9.11 Segmentation is similar to paging but uses variable-sized“pages.”Definetwo segment-replacement algorithms based on FIFO and LRU pagereplacement schemes. Remember that since segments are not the samesize, the segment that is chosen to be replaced may not be big enoughto leave enough consecutive locations for the needed segment. Consider strategies for systems where segments cannot be relocated, and thosefor systems where they can.Answer:a. FIFO. Find the first segment large enough to accommodate the incoming segment. If relocation is not possible and no one segmentis large enough, select a combination of segments whose memoriesare contiguous, which are “closest to the first of the list” andwhich can accommodate the new segment. If relocation is possible, rearrange the memory so that the firstNsegments large enough forthe incoming segment are contiguous in memory. Add any leftover space to the free-space list in both cases.Practice Exercises 33b. LRU. Select the segment that has not been used for the longestperiod of time and that is large enough, adding any leftover spaceto the free space list. If no one segment is large enough, selecta combination of the “oldest” segments that are contiguous inmemory (if relocation is not available) and that are large enough.If relocation is available, rearrange the oldest N segments to be contiguous in memory and replace those with the new segment.9.12 Consider a demand-paged computer system where the degree of multiprogramming is currently fixed at four. The system was recently measured to determine utilization of CPU and the paging disk. The results are one of the following alternatives. For each case, what is happening? Can the degree of multiprogramming be increased to increase the CPU utilization? Is the paging helping?a. CPU utilization 13 percent; disk utilization 97 percentb. CPU utilization 87 percent; disk utilization 3 percentc. CPU utilization 13 percent; disk utilization 3 percentAnswer:a. Thrashing is occurring.b. CPU utilization is sufficiently high to leave things alone, and increase degree of multiprogramming.c. Increase the degree of multiprogramming.9.13 We have an operating system for a machine that uses base and limit registers, but we have modified the machine to provide a page table.Can the page tables be set up to simulate base and limit registers? How can they be, or why can they not be?Answer:The page table can be set up to simulate base and limit registers provided that the memory is allocated in fixed-size segments. In this way, the base of a segment can be entered into the page table and the valid/invalid bit used to indicate that portion of the segment as resident in the memory. There will be some problem with internal fragmentation.9.27.Consider a demand-paging system with the following time-measured utilizations:CPU utilization 20%Paging disk 97.7%Other I/O devices 5%Which (if any) of the following will (probably) improve CPU utilization? Explain your answer.a. Install a faster CPU.b. Install a bigger paging disk.c. Increase the degree of multiprogramming.d. Decrease the degree of multiprogramming.e. Install more main memory.f. Install a faster hard disk or multiple controllers with multiple hard disks.g. Add prepaging to the page fetch algorithms.h. Increase the page size.Answer: The system obviously is spending most of its time paging, indicating over-allocationof memory. If the level of multiprogramming is reduced resident processeswould page fault less frequently and the CPU utilization would improve. Another way toimprove performance would be to get more physical memory or a faster paging drum.a. Get a faster CPU—No.b. Get a bigger paging drum—No.c. Increase the degree of multiprogramming—No.d. Decrease the degree of multiprogramming—Yes.e. Install more main memory—Likely to improve CPU utilization as more pages canremain resident and not require paging to or from the disks.f. Install a faster hard disk, or multiple controllers with multiple hard disks—Also animprovement, for as the disk bottleneck is removed by faster response and morethroughput to the disks, the CPU will get more data more quickly.g. Add prepaging to the page fetch algorithms—Again, the CPU will get more datafaster, so it will be more in use. This is only the case if the paging action is amenableto prefetching (i.e., some of the access is sequential).h. Increase the page size—Increasing the page size will result in fewer page faults ifdata is being accessed sequentially. If data access is more or less random, morepaging action could ensue because fewer pages can be kept in memory and moredata is transferred per page fault. So this change is as likely to decrease utilizationas it is to increase it.10.1、Is disk scheduling, other than FCFS scheduling, useful in asingle-userenvironment? Explain your answer.Answer: In a single-user environment, the I/O queue usually is empty. Requests generally arrive from a single process for one block or for a sequence of consecutive blocks. In these cases, FCFS is an economical method of disk scheduling. But LOOK is nearly as easy to program and will give much better performance when multiple processes are performing concurrent I/O, such as when aWeb browser retrieves data in the background while the operating system is paging and another application is active in the foreground.10.2.Explain why SSTF scheduling tends to favor middle cylindersover theinnermost and outermost cylinders.The center of the disk is the location having the smallest average distance to all other tracks.Thus the disk head tends to move away from the edges of the disk.Here is another way to think of it.The current location of the head divides the cylinders into two groups.If the head is not in the center of the disk and a new request arrives,the new request is more likely to be in the group that includes the center of the disk;thus,the head is more likely to move in that direction.10.11、Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, in FIFO order, is86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests, for each of the following disk-scheduling algorithms?a. FCFSb. SSTFc. SCANd. LOOKe. C-SCANAnswer:a. The FCFS schedule is 143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130. The total seek distance is 7081.b. The SSTF schedule is 143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774. The total seek distance is 1745.c. The SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86. The total seek distance is 9769.d. The LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86. The total seek distance is 3319.e. The C-SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 86, 130. The total seek distance is 9813.f. (Bonus.) The C-LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130. The total seek distance is 3363.12CHAPTERFile-SystemImplementationPractice Exercises12.1 Consider a file currently consisting of 100 blocks. Assume that the filecontrol block (and the index block, in the case of indexed allocation)is already in memory. Calculate how many disk I/O operations are required for contiguous, linked, and indexed (single-level) allocation strategies, if, for one block, the following conditions hold. In the contiguous-allocation case, assume that there is no room to grow atthe beginning but there is room to grow at the end. Also assume thatthe block information to be added is stored in memory.a. The block is added at the beginning.b. The block is added in the middle.c. The block is added at the end.d. The block is removed from the beginning.e. The block is removed from the middle.f. The block is removed from the end.Answer:The results are:Contiguous Linked Indexeda. 201 1 1b. 101 52 1c. 1 3 1d. 198 1 0e. 98 52 0f. 0 100 012.2 What problems could occur if a system allowed a file system to be mounted simultaneously at more than one location?Answer:4344 Chapter 12 File-System ImplementationThere would be multiple paths to the same file, which could confuse users or encourage mistakes (deleting a file with one path deletes thefile in all the other paths).12.3 Wh y must the bit map for file allocation be kept on mass storage, ratherthan in main memory?Answer:In case of system crash (memory failure) the free-space list would notbe lost as it would be if the bit map had been stored in main memory.12.4 Consider a system that supports the strategies of contiguous, linked, and indexed allocation. What criteria should be used in deciding which strategy is best utilized for a particular file?Answer:•Contiguous—if file is usually accessed sequentially, if file isrelatively small.•Linked—if file is large and usually accessed sequentially.• Indexed—if file is large and usually accessed randomly.12.5 One problem with contiguous allocation is that the user must preallocate enough space for each file. If the file grows to be larger than thespace allocated for it, special actions must be taken. One solution to this problem is to define a file structure consisting of an initial contiguous area (of a specified size). If this area is filled, the operating system automatically defines an overflow area that is linked to the initial contiguous area. If the overflow area is filled, another overflow areais allocated. Compare this implementation of a file with the standard contiguous and linked implementations.Answer:This method requires more overhead then the standard contiguousallocation. It requires less overheadthan the standard linked allocation. 12.6 How do caches help improve performance? Why do systems not use more or larger caches if they are so useful?Answer:Caches allow components of differing speeds to communicate moreefficiently by storing data from the slower device, temporarily, ina faster device (the cache). Caches are, almost by definition, more expensive than the device they are caching for, so increasing the numberor size of caches would increase system cost.12.7 Why is it advantageous for the user for an operating system todynamically allocate its internal tables? What are the penalties to the operating system for doing so?Answer:Dynamic tables allow more flexibility in system use growth — tablesare never exceeded, avoiding artificial use limits. Unfortunately, kernelstructures and code are more complicated, so there is more potentialfor bugs. The use of one resource can take away more system resources (by growing to accommodate the requests) than with static tables.Practice Exercises 4512.8 Explain how the VFS layer allows an operating system to support multiple types of file systems easily.Answer:VFS introduces a layer of indirection in the file system implementation.In many ways, it is similar to object-oriented programming techniques. System calls can be made generically (independent of file system type). Each file system type provides its function calls and data structuresto the VFS layer. A system call is translated into the proper specific functions for the target file system at the VFS layer. The calling program has no file-system-specific code, and the upper levels of the system callst ructures likewise are file system-independent. The translation at the VFS layer turns these generic calls into file-system-specific operations.。
106256-操作系统(第5版)-9-《操作系统教程》(5版)教学重点、难点及解决办法

《操作系统教程》(笫5版)教学重点、难点及解决办法(按十个核心知识单元排列)1、概念与原理重点:操作系统的发展历史、定义、作用、功能、特征、分类、发展动力和研究动向;操作系统在计算机系统中的地位,以及与其他软件的联系与区别;操作系统的资源管理技术:复用、虚拟和抽象;操作系统三个最基本抽象:进程抽象、虚存抽象和文件抽象;操作系统虚拟机及其实现原理;多道程序设计定义、实现基础、基本原理、主要特征、优点缺点。
难点:对并发性和共享性及其关系的深刻理解;多道程序运行的时间关系、处理器及设备利用率计算;操作系统在计算机系统中的地位和作用;操作系统与其他软件的联系与区别;对操作系统三个最基本抽象的深刻理解,虚拟机的定义及其实现原理。
解决办法:讲解操作系统是计算机系统的核心和灵魂,是各类软件系统中最复杂的软件之一,是软件系统中的基础软件;提醒学生注意学习方法、激发学习兴趣,学习本课程最终目标是建立起以操作系统为中心的计算机系统的系统级的认识和全局性把握;强调操作系统是理论性与实践性并重的课程,理论与实践相结合十分重要,既要学好原理,又要动手实践,做到课程教学与实验内容彼此呼应、掌握基本原理与提高编程能力相互并重;多道程序设计是讲授的重点之一,让学生理解和掌握多道程序设计原理,实现它必须解决的若干问题,基本调度思想,理解计算机效率的计算方法;可通过图解方法介绍操作系统三个最基本抽象,在此基础上再介绍虚拟机,让学生牢固掌握操作系统资源管理技术;本知识单元主要要求是讲清楚“操作系统是什么?为什么要它?它干什么?它如何干?”等问题,回顾操作系统的发展历史和分类,有助于理解操作系统的实质,提醒学生带着以上问题学习操作系统;建议学生多看参考书和参考资料,多浏览相关网站,并为学生提供这类信息资源。
2、接口与服务重点:操作系统接口、操作系统服务;POSIX标准、访管指令、应用编程接口API、标准库函数;程序接口与系统调用;操作接口与系统程序;shell概念、变量、命令、语句及其简单程序设计。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算题类型:
1.重定位地址计算:
1)给定逻辑地址,计算物理地址(分段或分页,一级页表或二级页表)
2)给定逻辑地址LA,页长度,计算逻辑地址的页号和偏移
3)给定物理地址RA,页帧长度,计算物理地址的页帧号和偏移
2.有效内存访问时间计算:
给定内存访问时间、快表访问时间及快表命中率、调页时间及缺页率,计算有效内存访问时间
3.磁盘地址及容量计算:
1)给定一维的逻辑扇区编址A,柱面数C、磁头数H、扇区数S,计算物
理c、h、s
2)给定柱面数C、磁头数H、扇区数S,计算磁盘容量
4.文件系统相关计算:
1)给定inode数据结构,盘块大小,地址长度,计算文件最大容量
2)给定卷的容量,簇大小,FAT12/16/32分别需要多少个簇来存放FAT表
3)给定RAID5阵列的磁盘数量n,计算磁盘空间有效利用率
5.给定作业到达时刻、计算时间长度,调度策略,计算响应时间、周转时间
例1:在某个采用分页存储管理的系统中,假定逻辑页面和物理存储块的大小
均为1KB,主存容量为10KB。
某个用户编写的程序P共有4个页面,
被分别装入到主存的第3、4、6、8存储块中。
(1)写出P对应进程的页面映射表;
(2)当P在CPU运行时,执行了一条指令:MOV [2100],[3100]
请计算指令中的两个操作数的物理地址。
解答:(1)由于页大小为长。
页表应为:
(2
例2:在请求分页式存储管理中,假设一次内存访问时间为100ns,一次快表(TLB)访问时间为20ns,地址转换计算时的快表命中率为80%,请计算
平均有效内存访问时间为多少ns?若缺页率为1‰,且每次缺页中断处
理时间为20ms,请计算平均有效内存访问时间为多少ns?
解答:
如果快表命中(即页号在快表中),则内存访问时间A1=20+100=120ns
如果快表未命中,则内存访问时间
A2=20+100+100=220ns【含一次访问内存中页表】则平均有效内存访问时间
A=A1×80%+A2×20%=120×0.8+220×0.2=140ns
缺页率p=1‰的含义是,每1000次内存访问中有1次需要调页处理!
因此,请求分页式存储管理过程中,平均有效内存访问时间:
T = (1-p)×A+p×20(ms)
=(1-0.001)×140 + 0.001×20000000(ns)
=139.86+20000
=20139ns
【注】1s=1000ms=1000 000us=1000 000 000ns
例3:假设一个磁盘共有2048个柱面,16个磁头,每个磁道分为64个扇区,
每个扇区容量为512字节,请计算该磁盘的总容量有多少GB?假设磁
盘的一个逻辑盘块大小为2KB,则逻辑盘块号513所对应的首个扇区
的三维物理地址(c,h,s)为多少?
解答:
(1)C=2048=2K个柱面(即每个盘面有2K个磁道)
H=16个磁头(即16个盘面)S=64个扇区/每个磁道
每个扇区的容量=512字节=0.5KB
则磁盘总容量=0.5KB×C×H×S = 0.5KB×2K×16×64 = 1GB
(2)1个盘块由2KB/0.5K=4个扇区构成
因此,513号盘块的首块扇区号A=4×513=2052
s = A % S = 2052 % 64= 4
h = ⌊A / S⌋ % H = ⌊2052 / 64⌋ % 16 = 0
c = ⌊A / (S×H)⌋ = ⌊2052 / (64×16)⌋ = 2
结果=(2,0,4)
例4-1:RAID5磁盘阵列共有8块磁盘构成,请计算磁盘空间有效利用率?解答:磁盘空间有效利用率= (n-1) / n = 7 / 8 = 87.5%
例4-2:已知磁盘容量为256MB,簇大小为4KB,对FAT16格式的文件系统
来说,文件分配表应该占用多大磁盘空间?(不考虑文件系统的空间开销)解答:整个磁盘逻辑盘块(簇)个数= 256MB/4KB = 256×1024 / 4 = 64K个FAT16文件格式的文件分配表每项占用16bit即2B空间
因此,文件分配表占用空间= 2B×64K = 128KB,即128KB/4KB=32个簇
例4-3:MINIX文件系统1.0中,每个文件均有唯一的一个inode数据结构,
其中共有9个文件数据块指针zone[0..8],每个指针为short类型。
前
7个即zone[0..6]为直接数据块指针,zone[7]为一级数据块指针,zone[8]
为二级数据块指针。
而每个数据块大小为1KB。
试计算该文件系统能
够支持的最大文件是多大?
解答:数据块大小为1KB,而每个指针为short整型,占2B空间,因此1个数据块可以有512个指针。
inode的直接数据块有7个,即可以指出7KB的空间;
inode的一级间接指针块,共有512个指针,可以指出512×1KB = 0.5MB 空间;
inode的二级间接指针块,共有512个指针,可以指出512个一级指针块,共可以指出512×512个数据块,即可以指出512×512×1KB = 0.25GB
空间。
因此,MINIX文件系统1.0的单个文件最大容量为0.25GB+0.5MB+7KB
例5:给定作业到达时刻、计算时间长度,调度策略,计算响应时间、周转时
间
采用SRFS(调度执行结果甘特图:
则响应时间(提交到第1次执行):
5
61
8
13
20
30
42
例6:在银行家算法中,系统有5个进程和3类资源。
若出现以下资源分配情况:
目前状态是否为安全状态?如果是安全状态,给出一个安全序列,否则给出死锁进程集合。
解答:
(1)P1、P3、P0、P2、P4
(2)P1、P3、P0、P4、P2
(3)P1、P3、P2、P0、P4
(4)P1、P3、P2、P4、P0
(5)P1、P3、P4、P0、P2
(6)P1、P3、P4、P2、P0
(7)P1、P4、P3、P0、P2
(8)P1、P4、P3、P2、P0
(9)P3、P1、P0、P2、P4
(10)P3、P1、P0、P4、P2
(11)P3、P1、P2、P0、P4
(12)P3、P1、P2、P4、P0
(13)P3、P1、P4、P0、P2
(14)P3、P1、P4、P2、P0
(15)P3、P4、P1、P0、P2
(16)P3、P4、P1、P2、P0
调度策略:
1.CPU调度(进程调度)
FCFS(先来先服务)、
SJF(最短作业优先)、
SRJF(最短剩余时间作业优先)、
RR(时间片轮转)
四种方式的作业(任务)调度执行结果的甘特图,并通过甘特图计算响应时间、周转时间等
2.虚拟内存的缺页置换
FIFO(先进先出);OPT(MIN)(最优置换);LRU(最近最少使用);LRU的准确实现算法(计数器算法、页码栈算法);LRU的近似实现算法(CLOCK 算法)
针对各种具体置换策略或算法,计算缺页数及缺页率
3.磁盘调度
FCFS(先来先服务)、
SSTF(最短寻道时间优先)、
SCAN(扫描/电梯法)、
LOOK(查看扫描/电梯法)
CSCAN(周期扫描法)
CLOOK(周期查看扫描)
六种调度策略的寻道移动磁道数量计算
进程状态变迁及条件
三状态、五状态、七状态
算法:
银行家算法检测死锁
哲学家进餐问题
信号量控制互斥、同步程序编写
简答题例子:
(1)解释什么是并行和并发?
答案:并行是指两个或多个活动在同一时刻同时执行的情况;
并发是指系统中存在着若干个逻辑上相互独立的程序或程序段,它们都已经被启动执行,在相对短的时间内,它们交叉地在CPU上执行的情况。
给使用者一个并行的感觉。
(2)进程与程序之间的联系与区别?
答案:进程是程序的一次执行过程,没有程序就没有进程;
程序是完成某个特定功能的一系列程序语句的集合,只要不被破坏,它就永远存在;
程序是一个静态的概念,而进程是一个动态的概念,它由创建而产生,完成任务后因撤销而消亡;进程是系统进行资源分配和调度的独立单位,而程序不是。
选择题例子:
(1)如果分时系统的时间片一定,那么( A ),则响应时间越长。
A 用户数越多
B 用户数越少
C 主存容量越大
D 主存容量越小
(2)在分时系统中,当用户数为100时,为保证响应时间不超过2s,系统设置的时间片应为(D)。
A 50ms
B 100ms
C 10ms
D 20ms
(3)若信号量S的初值为2,当前值为-1,则表示有(B)个等待进程。
A 0
B 1
C 2
D 3
判断题例子:
死锁是指系统中的全部进程都处于阻塞状态。
【×】
一个程序在执行过程中可能产生多进程。
【√】
P、V操作既可以用来实现进程间的同步,也可以实现进程间互斥。
【√】
当进程调度未能选中一个进程运行时,就绪队列和阻塞队列一定为空。
【×】。