操作系统第九版部分课后作业习题答案分析解析

合集下载

操作系统第九版部分课后作业习题答案-推荐下载

操作系统第九版部分课后作业习题答案-推荐下载

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 verifies the 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. On 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 contorted 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 longest 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 a single-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 Why 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 number or size of caches would increase system cost.12.7 Why is it advantageous for the user for an operating system to dynamically 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, kernel structures 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 call structures likewise are file system-independent. The translation at the VFS layer turns these generic calls into file-system-specific operations.。

操作系统课后习题精选答案

操作系统课后习题精选答案

操作系统课后习题精选答案操作系统作为计算机科学的基础知识之一,是每个计算机专业学生必须掌握的内容。

课后习题的作用是提供课程内容的深度和拓展,以便帮助学生更好地理解和应用所学知识。

以下是我根据自己的学习经验,总结出的操作系统课后习题精选答案。

这些答案涵盖了操作系统中的主要概念和核心原理,对于加深对操作系统的理解有很大的帮助。

1. 什么是操作系统?答案:操作系统是一组程序,它们管理和控制计算机的各种硬件和软件资源,以便于应用程序进行交互式和高效的执行。

操作系统的主要功能包括进程管理、内存管理、磁盘管理、文件管理和网络管理等。

2. 什么是进程?答案:进程是指计算机系统中正在执行的程序的实例。

一个进程可以包含一个或多个线程,并且每个进程都有自己的地址空间、各种资源和状态信息等。

操作系统通过进程管理来协调和控制多个进程的执行,以提供对计算机资源的合理和优化的利用。

3. 什么是线程?答案:线程是进程中的一个独立执行单元,它可以在进程的上下文中运行,并与其他线程共享进程的资源和状态信息等。

线程和进程之间的区别在于,进程是资源分配的基本单位,而线程是操作系统中的调度基本单位。

操作系统利用线程进行并行计算和流程处理,以便快速实现多任务处理和高效运行。

4. 什么是虚拟内存?答案:虚拟内存是操作系统提供的一种机制,用于将计算机的物理内存和应用程序的逻辑地址空间进行映射和管理。

虚拟内存的基本思想是将进程的地址空间分为若干个物理和逻辑区域,并在需要时将这些区域进行映射和替换。

这样,操作系统可以允许应用程序访问超过物理内存容量的数据,从而提高系统的内存利用率和应用程序的执行效率。

5. 什么是文件系统?答案:文件系统是一种操作系统提供的数据存储和管理机制,用于将数据组织为文件、目录和子目录等形式,并提供对文件系统中的不同组成部分进行访问、传输和维护等操作。

文件系统的主要目的是让应用程序可以访问和共享系统中的数据资源,从而有效管理和利用计算机的存储资源。

操作系统课后部分习题及答案

操作系统课后部分习题及答案

第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的内容),以便转入中断处理程序。

操作系统课后习题及答案

操作系统课后习题及答案

第一章1.下面不属于操作系统的是(C )A、OS/2B、UCDOSC、WPSD、FEDORA2.操作系统的功能不包括(B )A、CPU管理B、用户管理C、作业管理D、文件管理3.在分时系统中,当时间片一定时,(B ),响应越快。

A、内存越大B、用户越少C、用户越多D、内存越小4.分时操作系统的及时性是指( B )A、周转时间B、响应时间C、延迟时间D、A、B和C5.用户在程序设计的过程中,若要得到系统功能,必须通过(D )A、进程调度B、作业调度C、键盘命令D、系统调用6.批处理系统的主要缺点是( C )A、CPU使用效率低B、无并发性C、无交互性D、都不是第二章1、若信号量的初值为2,当前值为-3,则表示有(C )个进程在等待。

A、1B、2C、3D、52、在操作系统中,要对并发进程进行同步的原因是(B )A、进程必须在有限的时间内完成B、进程具有动态性C、并发进程是异步的D、进程具有结构性3、下列选项中,导致创进新进程的操作是(C )I用户成功登陆II设备分配III启动程序执行A、仅I和IIB、仅II和IIIC、仅I和IIID、I,II,III4、在多进程系统中,为了保证公共变量的完整性,各进程应互斥进入临界区。

所谓的临界区是指(D )A、一个缓冲区B、一个数据区C、一种同步机构D、一段程序5、进程和程序的本质区别是(B )A、内存和外存B、动态和静态特征C、共享和独占计算机资源D、顺序和非顺序执行计算机指令6、下列进程的状态变化中,(A )的变化是不可能发生的。

A、等待->运行B、运行->等待C、运行->就绪D、等待->就绪7、能从1种状态变为3种状态的是(D )A、就绪B、阻塞C、完成D、执行8、下列关于进程的描述正确的是(A )A、进程获得CPU是通过调度B、优先级是进程调度的重要依据,一旦确定就不能改变C、在单CPU系统中,任何时刻都有一个进程处于执行状态D、进程申请CPU得不到满足时,其状态变为阻塞9、CPU分配给进程的时间片用完而强迫进程让出CPU,此时进程的状态为(C )。

操作系统第九版部分课后作业习题答案分析解析

操作系统第九版部分课后作业习题答案分析解析

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 veri?esthe 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 anypage-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 physicaladdresses in hexadecimal. All numbers are given in hexadecimal. (Adash 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 thesealgorithms on a ?ve-point scale from “bad” to “perfect” according to the page-fault rate. Separate those algorithms that suffer from Belady’sanomaly 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 whetherthe 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 revolutionsper minute and transfers 1 million words per second. The following statistical measurements were obtained from the system:page other than the? 1 percent of all instructions executed accessed acurrent 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 modi?ed 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:(2 sec)(1sec + 0.008 ×effective access time = 0.99 ×(10,000 sec + 1,000 sec)+ 0.002 ×(10,000 sec + 1,000 sec)+ 0.001 ×9.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 two are 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, ?ve, six, or seven frames? Remember all frames are initially empty, so your ?rst 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. On ?rst 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 thenew algorithm optimal? Explain your answer.Answer:No. An optimal algorithm will not suffer from Belady’s anomaly beca an optimal algorithm replaces the page that will not—by de?nition—be used for the longest time. Belady’s anomaly occurs when a pagereplacement a lgorithm evicts a page that will be needed in theimmediatefuture. An optimal algorithm would not have selected such a page.9.11 Segmentation is similar to paging but usesnevariable-sized“pages.”De?two segment-replacement algorithms based on FIFO and LRU pagereplacement s chemes. Remember that since segments are not thesamesize, the segment that is chosen to be replaced may not be big enoughto leave enough consecutive locations for the needed segment. Considerstrategies for systems where segments cannot be relocated, and thosefor systems where they can.Answer:a. FIFO. Find the ?rst segment large enough to accommodate theincoming 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 ?rst of the list” and which can accommodate the new segment. If relocation is possible,rearrange the memory so that the ?rstNsegments large enough forthe incoming segment are contiguous in memory. Add any leftoverspace 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 becontiguous in memory and replace those with the new segment.9.12 Consider a demand-paged computer system where the degree of multiprogramming is currently ?xed at four. The system was recentlymeasured to determine utilization of CPU and the paging disk. The resultsare 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 suf?ciently high to leave things alone, andincrease 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 modi?ed the ma chine 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 ?xed-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 actionis 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 f ewer pages c an 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 a single-userenvironment? Explain your answer.Answer: In a single-user environment, the I/O queue usually is empty. Requests g enerally 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 ?le currently consisting of 100 blocks. Assume that the?lecontrol 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 ?le system to be mounted simultaneously at more than one location?Answer:4344 Chapter 12 File-System ImplementationThere would be multiple paths to the same ?le, which could confuse users or encourage mistakes (deleting a ?le with one path deletes the?le in all the other paths).12.3 Why must the bit map for ?le allocation be kept on mass storage, ratherthan in main memory?Answer:In case of system crash (memory failure) the free-space list would not be 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 ?le?Answer:?Contiguous—if ?le is usually accessed sequentially, if ?le isrelatively small.?Linked—if ?le is large and usually accessed sequentially.? Indexed—if ?le is large and usually accessed randomly.12.5 One problem with contiguous allocation is that the user must preallocate enough space for each ?le. If the ?le grows to be larger than thespace allocated for it, special actions must be taken. One solution to this problem is to de?ne a ?le structure consisting of an initial contiguousarea (of a speci?ed size). If this area is ?lled, the operating system automatically de?nes an over?ow area that is linked to the initial contiguous area. If the over?ow area is ?lled, another over?ow areais allocated. Compare this implementation of a ?le 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 moreef?ciently by storing data from the slower device, temporarily, ina faster device (the cache). Caches are, almost by de?nition, moreexpensive 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 to dynamically allocate its internal tables? What are the penalties to the operating system for doing so?Answer:tablesDynamic tables allow more ?exibility in system use growth —are never exceeded, avoiding arti?cial use limits. Unfortunately, kernel structures 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 ?le systems easily.Answer:VFS introduces a layer of indirection in the ?le system implementation. In many ways, it is similar to object-oriented programming techniques. System calls can be made generically (independent of ?le system type). Each ?le system type provides its function calls and data structuresto the VFS layer. A system call is translated into the proper speci?c functions for the target ?le system at the VFS layer. The calling program has no ?le-system-speci?c code, and the upper levels of the system call structures likewise are ?le system-independent. The translation at the VFS layer turns these generic calls into ?le-system-speci?c operations.。

操作系统习题答案第-(3)

操作系统习题答案第-(3)

操作系统习题答案第-(3)CH3 应用题参考答案1、有三个并发进程:R 负责从输入设备读入信息块,M 负责对信息块加工处理;P 负责打印输出信息块。

今提供;l )一个缓冲区,可放置K 个信息块;2 )二个缓冲区,每个可放置K 个信息块;试用信号量和P 、V 操作写出三个进程正确工作的流程。

答:1 ) var B : array [ 0 , k-1 ] of item ;sread : semaPhore : = k ;smanage : semaPhore : = 0 ;swrite : semaphore : = 0 ;rptr : integer : = O ;mptr : integer : = O ;wptr :integer : = 0 ;x : itemcobeginprocess reader ; processmanager ; process writer ;begin begin beginLI : read a message intox ; L2 : P( smanage ) ; L3 : P( swnte ) ;P ( sread ) ; x:=B[mptr];x:=B[swrite];B[rptr]:=x;mptr:=(mptr+1) mod k; wptr:=(wptr+1) mod k;Rptr:=(rptr+1) mod k; manage the message in x; V(sread);V(smanage);B[mptr]:=x;print the message in x;Goto L1; V(swrite);goto L3;End; gotoL2; end;End;coend2 ) var A , B :array [ 0 , k -l ] of item ;sPut1 : semaphore:=k;SPut2: semaPhore:=k;sget1 : semaPhore : = 0 ;sget2 : semaphore : = 0 ;put1 :integer :=O ;put2:integer : = 0 ;get1 :integer :=O ;get2 : integer : = O ;cobeginprocess reader ; processn manager; process Writer ;begin begin beginLl : read a message into x ; L2 : P( sgetl ) ; L3 : P( sgetZ ) ;P ( SPut1 ) ; x : =A [ get1] ; x : = B[get2];A [put1]:=x ; get1 :(get1+1 ) mod k ; get2:=(get2 + l ) mod k ;Put1:=(put1+1) mod k; V(sput1);V(sput2);V(sget1);manage the message into x; print the message in x;Goto L1; P(sput2);goto L3;Put2:=(put2+1) mod k;V(sget2);Goto L2;End;Coend2 设有n 个进程共享一个互斥段,如果:( 1 )每次只允许一个进程进入互斥段;( 2 )每次最多允许m 个进程(m 簇n )同时进入互斥段。

计算机操作系统课后答案第9章习题解答

计算机操作系统课后答案第9章习题解答

第9章习题解答一、填空1.MS-DOS操作系统由BOOT、IO.SYS、MSDOS.SYS以及 所组成。

2.MS-DOS的一个进程,由程序(包括代码、数据和堆栈)、程序段前缀以及环境块三部分组成。

3.MS-DOS向用户提供了两种控制作业运行的方式,一种是批处理方式,一种是命令处理方式。

4.MS-DOS存储管理规定,从地址0开始每16个字节为一个“节”,它是进行存储分配的单位。

5.MS-DOS在每个内存分区的前面都开辟一个16个字节的区域,在它里面存放该分区的尺寸和使用信息。

这个区域被称为是一个内存分区所对应的内存控制块。

6.MS-DOS有4个存储区域,它们是:常规内存区、上位内存区、高端内存区和扩充内存区。

7.“簇”是MS-DOS进行磁盘存储空间分配的单位,它所含扇区数必须是2的整数次方。

8.当一个目录表里仅包含“.”和“..”时,意味该目录表为空。

9.在MS-DOS里,用文件名打开文件,随后就通过句柄来访问该文件了。

10.在MS-DOS里,把字符设备视为设备文件。

二、选择1.下面对DOS的说法中,B 是正确的。

A.内、外部命令都常驻内存B.内部命令常驻内存,外部命令非常驻内存C.内、外部命令都非常驻内存D.内部命令非常驻内存,外部命令常驻内存2.DOS进程的程序,在内存里 D 存放在一起。

A.总是和程序段前缀以及环境块B.和谁都不C.总是和进程的环境块D.总是和程序段前缀3.MS-DOS启动时能够自动执行的批处理文件名是: C 。

A.CONFIG.SYS B.MSDOS.SYSC.AUTOEXEC.BAT D.4.下面所列的内存分配算法, D 不是MS-DOS采用的。

A.最佳适应法B.最先适应法C.最后适应法D.最坏适应法5.在MS-DOS里,从1024K到1088K的存储区域被称为 D 区。

A.上位内存B.扩展内存C.扩充内存D.高端内存6.MS-DOS的存储管理是对A的管理。

A.常规内存B.常规内存和上位内存C.常规内存和扩展内存D.常规内存和扩充内存7.在下面给出的MS-DOS常用扩展名中,B 不表示一个可执行文件。

最新操作系统第九版部分课后作业习题答案分析解析

最新操作系统第九版部分课后作业习题答案分析解析

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.。

操作系统概念(第九版)答案

操作系统概念(第九版)答案

操作系统概念(第九版)答案简介《操作系统概念(第九版)答案》是一本针对《操作系统概念(第九版)》教材的答案集合。

本文档旨在提供读者对操作系统相关概念的理解和应用基础。

目录1.引论2.进程管理3.处理机调度4.进程同步5.死锁6.内存管理7.虚拟内存8.文件系统9.输入与输出10.磁盘存储管理11.安全性和保护12.分布式系统13.多媒体操作系统14.实时系统第一章引论本章的目标是介绍操作系统的概念和功能,包括定义了什么是操作系统、操作系统的历史和发展、操作系统的分类以及操作系统的基本组成部分。

问题1:操作系统是什么?答案:操作系统是一个管理计算机硬件和软件资源的软件系统。

它为用户提供一个在硬件和软件之间进行交互的接口,同时协调和控制计算机的各个组件,以实现有效和可靠的计算机操作。

问题2:操作系统的历史和发展?答案:操作系统的历史可以追溯到大约20世纪50年代,当时计算机的使用范围相对较小,操作系统也比较简单。

随着计算机技术的发展,操作系统逐渐变得复杂而且功能强大。

在20世纪60年代,随着多道程序设计的发展,操作系统开始支持同时运行多个程序。

这就导致了对资源的合理分配和进程调度的需求。

同时,操作系统的文件系统和输入输出功能也得到了改进和扩展。

在20世纪70年代,个人计算机的出现使得操作系统变得更加普及。

同时,分时操作系统和分布式操作系统的概念也开始出现。

到了20世纪80年代和90年代,图形用户界面(GUI)的引入和互联网的普及使得操作系统更加用户友好和功能丰富。

现在,操作系统已经成为计算机系统中不可或缺的一部分,为计算机用户提供各种功能和服务。

问题3:操作系统的分类有哪些?答案:操作系统可以根据不同的标准进行分类。

以下是国际上常用的操作系统分类方法:1.目标计算机系统:大型机操作系统、小型机操作系统、微型机操作系统、嵌入式系统操作系统。

2.处理方式:批处理系统、分时操作系统、实时操作系统。

3.用户数量:单用户操作系统、多用户操作系统。

操作系统课后练习精选(答案)

操作系统课后练习精选(答案)

操作系统课后练习精选(答案)7.根据图2-18,回答以下问题。

(1)进程发生状态变迁1、3、4、6、7的原因。

答:1表示操作系统把处于创建状态的进程移入就绪队列;3表示进程请求I/O或等待某事件;4表示进程用行的时间片用完;6表示I/O完成或事件完成;7表示进程完成。

(2)系统中常常由于某一进程的状态变迁引起另一进程也产生状态变迁,这种变迁称为因果变迁。

下述变迁是否为因果变迁:3~2,4~5,7~2,3~6,是说明原因。

答:3→2是因果变迁,当一个进程从运行态变为阻塞态时,此时CPU空闲,系统首先到高优先级队列中选择一个进程。

4→5是因果变迁,当一个进程运行完毕时,此时CPU空闲,系统首先到高优先级队列中选择进程,但如果高优先级队列为空,则从低优先队列中选择一个进程。

7→2 是因果变迁,当一个进程运行完毕时,CPU空闲,系统首先到高优先级队列中选择一个进程。

3→6不是因果变迁。

一个进程阻塞时由于自身的原因而发生的,和另一个进程等待的时间到达没有因果关系。

(3)根据此进程状态转换图,说明该系统CPU调度的策略和效果。

答:当进程调度时,首先从高优先级就绪队列选择一个进程,赋予它的时间片为100ms。

如果高优先级就绪队列为空,则从低优先级就绪队列选择进程,并且赋予该进程的时间片为500ms。

这种策略一方面照顾了短进程,一个进程如果在100ms运行完毕它将退出系统,更主要的是照顾了I/O量大的进程,进程因I/O进入阻塞队列,当I/O完成后它就进入了高优先级就绪队列,在高优先级就绪队列等待的进程总是优于低优先级就绪队列的进程。

而对于计算量较大的进程,它的计算如果在100ms的时间内不能完成,它将进入低优先级就绪队列,在这个队列的进程被选中的机会要少,只有当高优先级就绪队列为空,才从低优先级就绪队列选择进程,但对于计算量大的进程,系统给予的适当照顾时间片增大为500ms。

8.回答以下问题。

(1)若系统中没有运行进程,是否一定没有就绪进程?为什么?答:是,因为当CPU空闲时,系统就会在就绪队列里调度进程,只有当就绪队列为空时,系统中才没有运行程序。

操作系统-9章作业答案

操作系统-9章作业答案

第七章设备管理一、判断题1在I/O控制方式中,程序I/O控制,中断,DMA以及通道4种方式都可以使 CPU与I/O 并行工作。

X 2. 文件目录具有将文件名转换为该文件在外存物理位置的功能。

V二•填空1微机I/O系统多采用总线I/O系统结构。

CPU与内存直接连接到总线上。

而I/O设备则通过设备控制器连接到总线上。

2. I/O设备按传输速率分类:低速设备、中速设备、高速设备。

3•按信息交换的单位分类块设备、字符设备4. 缓冲的类型可分为:?单缓冲、?双缓冲、?多缓冲、?缓冲池5. 设备分配中数据结构要用到:系统设备表(SDT)、设备控制表(DCT)、控制器控制表(COCT)、通道控制表(CHCT)。

在整个系统中,有一张系统设备表(SDT),用于记录系统中全部设备的信息。

系统为每一个设备都配置了一张设备控制表(DCT ),用于记录该设备的情况。

6. I/O的控制方式一般可分为:程序I/O方式、中断方式、DMA方式和通道方式。

7. 主机I/O系统的4级结构分别为设备、设备控制器、通道和主机。

三•选择题1. 微机I/O系统是一种 ___________A)总线型I/O系统 B)通道型I/O系统C)总线通道型I/O系统D)都不是2. __________ 是处理机和设备之间的接口。

A)总线 B)通道 C)设备控制器D)通道控制器3. _以下那种控制方式使得 CPU、通道和I/O设备三者之间的并行性最高。

_________________A)程序I/O方式 B )中断方式C) DMA方式D)通道方式4•以下关于通道的说法正确的是___________A)通道是数据在cpu与I/O设备之间的通路B)所有的计算机系统中都采用了通道技术C)在具有通道的计算机系统中,通道处理机和主处理机具有一样的功能。

D)通道是通过执行通道程序,并与设备控制器来共同实现对I/O设备的控制。

5.目前为了解决 CPU与I/O设备间速度不匹配的矛盾,提高的I/O速度和设备利用率,在所有的I/O设备与处理机(内存)之间,都使用了___________ 来交换数据。

操作系统课后习题答案

操作系统课后习题答案

操作系统课后习题答案问题一:简述进程和线程的区别。

进程是操作系统进行资源分配和调度的一个独立单位,它是程序在数据集上的一次动态执行过程。

线程是进程中的一个实体,是CPU调度和分派的基本单位,比进程更小的能独立运行的基本单位。

线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如执行栈),但它可以与同属一个进程的其他线程共享进程所拥有的全部资源。

问题二:什么是死锁?如何避免死锁?死锁是指两个或两个以上的进程在执行过程中,因争夺资源而造成的一种僵局,若无外力作用,这些进程都将无法向前推进。

避免死锁的方法包括:1. 互斥条件:确保系统资源足够,以避免多个进程争夺同一资源。

2. 请求和保持条件:设计资源分配策略,确保进程不会在请求新资源的同时保持已分配的资源。

3. 不剥夺条件:一旦资源被分配给某进程,除非该进程自愿释放资源,否则系统不应强制剥夺。

4. 循环等待条件:通过资源分配图检测循环等待并进行处理。

问题三:描述操作系统中的分页和分段机制。

分页机制是操作系统用来实现虚拟内存的一种技术,它将物理内存分割成固定大小的页,并将这些页与进程的虚拟地址空间中的页表项关联起来。

当进程访问一个不在物理内存中的虚拟地址时,操作系统会触发一个缺页中断,将所需的页从辅助存储器加载到物理内存中。

分段机制则是将程序的地址空间划分为多个段,每个段可以是不同的大小,并且可以独立地被加载和链接。

段表项包含了段的基地址和段的长度信息。

当程序访问一个段内的地址时,操作系统将虚拟地址转换为物理地址。

问题四:什么是文件系统?它有什么作用?文件系统是操作系统用于有效地存储、组织、管理和访问磁盘上的数据的一种系统。

它的作用包括:1. 数据持久性:确保即使在系统崩溃或电源故障后,数据也不会丢失。

2. 数据共享:允许多个用户或进程访问和共享数据。

3. 抽象:为用户和应用程序提供统一的接口来访问存储在磁盘上的数据。

4. 安全性:通过权限控制保护数据不被未授权访问。

操作系统课后习题1-9答案

操作系统课后习题1-9答案

操作系统课后习题1-9答案练习11.1-1.10题解见书1.11 有⼀台输⼊设备和⼀台输出设备的计算机系统上,运⾏有两道程序。

两道程序投⼊运⾏情况如下:程序1先开始运⾏,其运⾏轨迹为:计算50ms、输出100ms、计算50ms、输出100ms,结束;程序2后开始运⾏,其运⾏轨迹为:计算50ms、输⼊100ms、计算100ms、结束。

1. 忽略调度时间,指出两道程序运⾏时,CPU是否有空闲?在哪部分空闲?指出程序1和程序2. 有⽆等待CPU的情况?如果有,发⽣在哪部分?题解:由题画出CPU利⽤图如下:由图可知,1.CPU有空闲,在100ms~150ms时间段是空闲的。

2.程序1⽆等待时间,⽽程序2在⼀开始的0ms~50ms时间段会等待。

1.12 在计算机系统上运⾏三道程序,运⾏次序为程序1、程序2、程序3。

程序3的运⾏轨迹为:计算60ms、输⼊30ms、计算20ms。

忽略调度时间,画出三道程序运⾏的时间关系图;完成三道程序共花多少时间?与单道程序⽐较,节省了多少时间?解答:三道程序运⾏,完成三道程序共花170ms。

与单道程序(260ms)⽐较,节省了90ms。

(始终按照1-2-3的次序,即程序1→程序2→程序3→程序1→程序2→(在程序3运⾏前会停10ms等待输⼊完成)程序3。

(如果不是按照程序1、2、3的次序完成则会有多种情况。

)1.13 在计算机系统上有两台输⼊/输出设备,运⾏两道程序。

程序1的运⾏轨迹为:计算10ms、输⼊5ms、计算5ms、输出10ms、计算10ms。

程序2的运⾏轨迹为:输⼊10ms、计算10ms、输出5ms、计算5ms、输出10ms。

在顺序环境下,先执⾏程序1,再执⾏程序2,求总的CPU利⽤率为多少?题解:由题画出CPU利⽤图如下:由图可知,在总共80ms的时间⾥,CPU空闲时间为40ms,即:CPU利⽤率=40ms/80ms*100%=50%1.14 ⼀个计算机系统有⾜够的内存空间存放3道程序,这些程序有⼀半的时间在空闲等待I/O操作。

操作系统第九版部分课后作业习题答案

操作系统第九版部分课后作业习题答案

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 ma chine 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 Why 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 initialc ontiguous 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 moreefficie ntly 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 number or size of caches would increase system cost.12.7 Why is it advantageous for the user for an operating system to dynamically 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, kernel structures 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 ta rget file system at the VFS layer. The calling program has no file-system-specific code, and the upper levels of the system call structures likewise are file system-independent. The translation at the VFS layer turns these generic calls into file-system-specific operations.。

操作系统课后习题答案

操作系统课后习题答案

操作系统课后习题答案第一章o引论1.设计现代OS的主要目标是什么方便性,有效性,可扩充性和开放性.2.OS的作用可表现为哪几个方面a.OS作为用户与计算机硬件系统之间的接口;b.OS作为计算机系统资源的管理者;c.OS作为扩充机器.4.试说明推动多道批处理系统形成和发展的主要动力是什么不断提高计算机资源利用率和系统吞吐量的需要;5.何谓脱机I/O和联机I/Oa.脱机输入输出方式(Off-LineI/O)是为了解决人机矛盾及CPU和I/O设备之间速度不匹配而提出的.它减少了CPU的空闲等待时间,提高了I/O速度.具体内容是将用户程序和数据在一台外围机的控制下,预先从低速输入设备输入到磁带上,当CPU需要这些程序和数据时,在直接从磁带机高速输入到内存,从而大大加快了程序的输入过程,减少了CPU等待输入的时间,这就是脱机输入技术;当程序运行完毕或告一段落,CPU需要输出时,无需直接把计算结果送至低速输出设备,而是高速把结果输出到磁带上,然后在外围机的控制下,把磁带上的计算结果由相应的输出设备输出,这就是脱机输出技术.b.若这种输入输出操作在主机控制下进行则称之为联机输入输出方式.6.试说明推动分时系统形成和发展的主要动力是什么用户的需要.即对用户来说,更好的满足了人-机交互,共享主机以及便于用户上机的需求.7.实现分时系统的关键问题是什么应如何解决a.关键问题:及时接收,及时处理;b.对于及时接收,只需在系统中设置一多路卡,多路卡作用是使主机能同时接收用户从各个终端上输入的数据;---对于及时处理,应使所有的用户作业都直接进入内存,在不长的时间内,能使每个作业都运行一次.8为什么要引入实时操作系统更好地满足实时控制领域和实时信息处理领域的需要.12试从交互性,及时性和可靠性方面,将分时系统与实时系统进行比较.a.分时系统是一种通用系统,主要用于运行终端用户程序,因而它具有较强的交互能力;而实时系统虽然也有交互能力,但其交互能力不及前者.b.实时信息系统对实用性的要求与分时系统类似,都是以人所能接收的等待时间来确定;而实时控制系统的及时性则是以控制对象所要求的开始截止时间和完成截止时间来确定的.c.实时系统对系统的可靠性要求要比分时系统对系统的可靠性要求高.13OS具有哪几大特征它的最基本特征是什么a.并发(Concurrence),共享(Sharing),虚拟(Virtual),异步性(Aynchronim).b.其中最基本特征是并发和共享.14处理机管理具有哪些功能它们的主要任务是什么a.进程控制,进程同步,进程通信和调度.b.进程控制的主要任务是为作业创建进程,撤销已结束的进程,以及控制进程在运行过程中的状态转换.---进程同步的主要任务是对诸进程的运行进行调节.---进程通信的任务是实现在相互合作进程之间的信息交换.---调度分为作业调度和进程调度.作业调度的基本任务是从后备队列中按照一定的算法,选择出若干个作业,为它们分配必要的资源;而进程调度的任务是从进程的就绪队列中,按照一定的算法选出一新进程,把处理机分配给它,并为它设置运行现场,是进程投入运行.15内存管理有哪些主要功能它们的主要任务是什么a.主要功能:内存分配,内存保护,地址映射和内存扩充等.b.内存分配的主要任务是为每道程序分配内存空间,提高存储器利用率,以减少不可用的内存空间,允许正在运行的程序申请附加的内存空间,以适应程序和数据动态增长的需要.---内存保护的主要任务是确保每道用户程序都在自己的内存空间中运行,互不干扰.---地址映射的主要任务是将地址空间中的逻辑地址转换为内存空间中与之对应的物理地址.---内存扩充的主要任务是借助虚拟存储技术,从逻辑上去扩充内存容量.16设备管理有哪些主要功能其主要任务是什么a.主要功能:缓冲管理,设备分配和设备处理,以及虚拟设备等.b.主要任务:完成用户提出的I/O请求,为用户分配I/O设备;提高CPU和I/O设备的利用率;提高I/O速度;以及方便用户使用I/O设备.17文件管理有哪些主要功能其主要任务是什么a.主要功能:对文件存储空间的管理,目录管理,文件的读,写管理以及文件的共享和保护.b.主要任务:对用户文件和系统文件进行管理,以方便用户使用,并保证文件的安全性.18是什么原因使操作系统具有异步性特征a.程序执行结果是不确定的,即程序是不可再现的.b.每个程序在何时执行,多个程序间的执行顺序以及完成每道程序所需的时间都是不确定的,即不可预知性.第二章2.试画出下面条语句的前趋图:S1:a=5-某;S2:b=a某某;S3:c=4某某;S4:d=b+c;S5:e=d+3.S1->S2->S4->S5......../......S33.程序并发执行为什么会产生间断性因为程序在并发执行过程中存在相互制约性.4.程序并发执行为什么会失去封闭性和可再现性因为程序并发执行时,多个程序共享系统中的各种资源,资源状态需要多个程序来改变,即存在资源共享性使程序失去封闭性;而失去了封闭性导致程序失去可再现性.5.在操作系统中为什么要引入进程概念它会产生什么样的影响为了使程序在多道程序环境下能并发执行,并能对并发执行的程序加以控制和描述,而引入了进程概念.影响:使程序的并发执行得以实行.6.试从动态性,并发性和独立性上比较进程和程序a.动态性是进程最基本的特性,可表现为由创建而产生,由调度而执行,因得不到资源而暂停执行,以及由撤销而消亡,因而进程由一定的生命期;而程序只是一组有序指令的集合,是静态实体.b.并发性是进程的重要特征,同时也是OS的重要特征.引入进程的目的正是为了使其程序能和其它进程的程序并发执行,而程序是不能并发执行的.c.独立性是指进程实体是一个能独立运行的基本单位,同时也是系统中独立获得资源和独立调度的基本单位.而对于未建立任何进程的程序,都不能作为一个独立的单位参加运行.7.试说明PCB的作用为什么说PCB是进程存在的唯一标志a.PCB是进程实体的一部分,是操作系统中最重要的记录型数据结构.PCB中记录了操作系统所需的用于描述进程情况及控制进程运行所需的全部信息.因而它的作用是使一个在多道程序环境下不能独立运行的程序(含数据),成为一个能独立运行的基本单位,一个能和其它进程并发执行的进程.b.在进程的整个生命周期中,系统总是通过其PCB对进程进行控制,系统是根据进程的PCB而不是任何别的什么而感知到该进程的存在的,所以说,PCB是进程存在的唯一标志.8.试说明进程在三个基本状态之间转换的典型原因.a.处于就绪状态的进程,当进程调度程序为之分配了处理机后,该进程便由就绪状态变为执行状态.b.当前进程因发生某事件而无法执行,如访问已被占用的临界资源,就会使进程由执行状态转变为阻塞状态.c.当前进程因时间片用完而被暂停执行,该进程便由执行状态转变为就绪状态.9.为什么要引入挂起状态该状态具有哪些性质a.引入挂起状态处于5中需要:终端用户的需要,父进程的需要,操作系统的需要,对换的需要和负荷调节的需要.b.处于挂起状态的进程不能接收处理机调度.10在进行进程切换时,所要保存的处理机状态信息主要有哪些a.进程当前暂存信息;b.下一条指令地址信息;c.进程状态信息;d.过程和系统调用参数及调用地址信息.11试说明引起进程创建的主要事件.a.用户登陆;b.作业调度;c.提供服务;d.应用请求.12试说明引起进程撤消的主要事件.a.正常结束;b.异常结束;c.外界干预;13在创建一个进程时,需完成的主要工作是什么a.操作系统发现请求创建新进程事件后,调用进程创建原语Creat();b.申请空白PCB;c.为新进程分配资源;d.初始化进程控制块;e.将新进程插入就绪队列.14在撤消一个进程时,需完成的主要工作是什么a.OS调用进程终止原语;b.根据被终止进程的标志符,从PCB集合中检索出该进程的PCB,从中读出该进程的状态;c.若被终止进程正处于执行状态,应立即中止该进程的执行,并设置调度标志为真;d.若该进程还有子孙进程,还应将其所有子孙进程予以终止;e.将该进程所拥有的全部资源,或者归还给其父进程,或者归还给系统;f.将被终止进程(它的PCB)从所在队列(或链表)中移出,等待其它程序来搜集信息.15试说明引起进程阻塞或被唤醒的主要事件是什么a.请求系统服务;b.启动某种操作;c.新数据尚未到达;d.无新工作可做.17.为什么进程在进入临界区之前,应先执行"进入区"代码,在退出临界区后又执行"退出区"代码为了实现多个进程对临界资源的互斥访问,必须在临界区前面增加一段用于检查欲访问的临界资源是否正被访问的代码,如果未被访问,该进程便可进入临界区对资源进行访问,并设置正被访问标志,如果正被访问,则本进程不能进入临界区,实现这一功能的代码成为"进入区"代码;在退出临界区后,必须执行"退出区"代码,用于恢复未被访问标志.18.同步机构应遵循哪些基本准则为什么a.空闲让进.b.忙则等待.c.有限等待.d.让权等待.20.你认为整型信号量机制和记录型信号量机制,是否完全遵循了同步机构的四条准则a.在整型信号量机制中,未遵循"让权等待"的准则.b.记录型信号量机制完全遵循了同步机构的"空闲让进,忙则等待,有限等待,让权等待"四条准则.23.在生产者-消费者问题中,如果缺少了ignal(full)或ignal(empty),对执行结果会有何影响生产者-消费者问题可描述如下: varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat.produceaniteminne某tp;..wait(empty);wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;ignal(mute某);/某某某某某某某某某某某某某某某某/ ignal(full);/某某某某某某某某某某某某某某某某/ untilfale;endconumer:beginrepeatwait(full);wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);/某某某某某某某某某某某某某某某某/ ignal(empty);/某某某某某某某某某某某某某某某某/conumetheiteminne某tc;untilfale;endparendend可见,生产者可以不断地往缓冲池送消息,如果缓冲池满,就会覆盖原有数据,造成数据混乱.而消费者始终因wait(full)操作将消费进程直接送入进程链表进行等待,无法访问缓冲池,造成无限等待.24.在生产者-消费者问题中,如果将两个wait操作即wait(full)和wait(mute某)互换位置;或者是将ignal(mute某)与ignal(full)互换位置结果会如何varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat..produceaniteminne某tp;.wait(empty);wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;/某某某某某某某某某某某某某某某某某某某/ ignal(full);ignal(mute某);/某某某某某某某某某某某某某某某某某某某/ untilfale;endconumer:beginrepeat/某某某某某某某某某某某某某某某某某某/ wait(mute某);wait(full);/某某某某某某某某某某某某某某某某某某/ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);conumetheiteminne某tc;untilfale;endparendendwait(full)和wait(mute某)互换位置后,因为mute某在这儿是全局变量,执行完wait(mute某),则mute某赋值为0,倘若full也为0,则该生产者进程就会转入进程链表进行等待,而生产者进程会因全局变量mute某为0而进行等待,使full始终为0,这样就形成了死锁.而ignal(mute某)与ignal(full)互换位置后,从逻辑上来说应该是一样的.25.我们为某临界区设置一把锁W,当W=1时,表示关锁;W=0时,表示锁已打开.试写出开锁原语和关锁原语,并利用它们去实现互斥.开锁原语:unlock(W):W=0;关锁原语:lock(W);if(W==1)dono_op;W=1;利用开关锁原语实现互斥:varW:emaphore:=0;beginparbeginproce:repeatlock(W);criticalectionunlock(W);remainderectionuntilfale;endparend26.试修改下面生产者-消费者问题解法中的错误: producer:beginrepeat..produceraniteminne某tp;wait(mute某);wait(full);/某应为wait(empty),而且还应该在wait(mute某)的前面某/buffer(in):=ne某tp;/某缓冲池数组游标应前移:in:=(in+1)modn;某/ignal(mute某);/某ignal(full);某/untilfale;endconumer:beginrepeatwait(mute某);wait(empty);/某应为wait(full),而且还应该在wait(mute某)的前面某/ne某tc:=buffer(out);out:=out+1;/某考虑循环,应改为:out:=(out+1)modn;某/ignal(mute某);/某ignal(empty);某/conumeriteminne某tc;untilfale;end27.试利用记录型信号量写出一个不会出现死锁的哲学家进餐问题的算法.设初始值为1的信号量c[I]表示I号筷子被拿(I=1,2,3,4,...,2n),其中n为自然数.end(I):BeginifImod2==1then{P(c[I]);P(c[I-1mod5]);V(c[I-1mod5]);}ele{P(c[I-1mod5]);P(c[I]);Eat;V(c[I]);V(c[I-1mod5]);}End28.在测量控制系统中的数据采集任务,把所采集的数据送一单缓冲区;计算任务从该单缓冲中取出数据进行计算.试写出利用信号量机制实现两者共享单缓冲的同步算法.intmute某=1;intempty=n;intfull=0;intin=0;intout=0;{cobeginend();obtain();coend}end(){while(1){..collectdatainne某tp; ..wait(empty);wait(mute某);buffer(in)=ne某tp;in=(in+1)modn;ignal(mute某);ignal(full);}}//endobtain(){while(1){wait(full);wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);culculatethedatainne某tc;}//while}//obtain29画图说明管程由哪几部分组成为什么要引入条件变量管程由三部分组成:局部于管程的共享变量说明;对该数据结构进行操作的一组过程;对局部于管程的数据设置初始值的语句.(图见P59)因为调用wait原语后,使进程等待的原因有多种,为了区别它们,引入了条件变量.30.如何利用管程来解决生产者-消费者问题(见P60)31.什么是AND信号量试利用AND信号量写出生产者-消费者问题的解法.为解决并行所带来的死锁问题,在wait操作中引入AND条件,其基本思想是将进程在整个运行过程中所需要的所有临界资源,一次性地全部分配给进程,用完后一次性释放.解决生产者-消费者问题可描述如下:varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat..produceaniteminne某tp;..wait(empty);wait(1,2,3,...,n);//1,2,...,n为执行生产者进程除empty外其余的条件wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;ignal(mute某);ignal(full);ignal(1,2,3,...,n);untilfale;endconumer:beginrepeatwait(full);wait(k1,k2,k3,...,kn);//k1,k2,...,kn为执行消费者进程除full 外其余的条件wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);ignal(k1,k2,k3,...,kn);conumetheiteminne某tc;untilfale;endparendend33.试比较进程间的低级通信工具与高级通信工具.用户用低级通信工具实现进程通信很不方便,因为其效率低,通信对用户不透明,所有的操作都必须由程序员来实现.而高级通信工具则可弥补这些缺陷,用户可直接利用操作系统所提供的一组通信命令,高效地传送大量的数据.第三章1.高级调度与低级调度的主要任务是什么为什么要引入中级调度a.作业调度又称宏观调度或高级调度,其主要任务是按一定的原则对外存上处于后备状态的作业进行选择,给选中的作业分配内存,输入输出设备等必要的资源,并建立相应的进程,以使该作业的进程获得竞争处理机的权利.b.进程调度又称微观调度或低级调度,其主要任务是按照某种策略和方法选取一个处于就绪状态的进程,将处理机分配给它.c.为了提高内存利用7.选择调度方式和调度算法时,应遵循的准则是什么a.面向用户的准则有周转时间短,响应时间快,截止时间的保证,以及优先权准则.b.面向系统的准则有系统吞吐量高,处理机利用率好,各类资源的平衡利用.11.在时间片轮转法中,应如何确定时间片的大小?a.系统对响应时间的要求;b.就绪队列中进程的数目;c.系统的处理能力。

操作系统部分课后习题答案

操作系统部分课后习题答案

操作系统部分课后习题答案第一章1、设计现代OS的主要目标就是什么?便利性,有效性,可扩充性与开放性。

2、OS的作用可表现在哪几个方面?(1)OS作为用户与计算机硬件系统之间的接口。

(2)OS作为计算机系统资源的管理者。

(3)OS实现了对计算机资源的抽象。

4、试说明推进多道批处理系统形成与进展的主要动力就是什么主要动力来源于四个方面的社会需求与技术进展(1)不断提高计算机资源的利用率(2)便利用户(3)器件的不断更新换代(4)计算机体系结构的不断进展。

7、实现分时系统的关键问题就是什么?应如何解决关键问题就是当用户在自己的终端上键入命令时,系统应能准时接收并准时处理该命令。

在用户能接受的时延内将结果返回给用户。

解决办法:针对准时接收问题,可以在系统中设置多路卡,使主机能同时接收用户从各个终端上输入的数据,为每个终端配置缓冲区,暂存用户键入的命令或数据。

针对准时处理问题,应使全部的用户作业都直接进入内存,并且为每个作业分配一个时光片,允许作业只在自己的时光片内运行。

这样在不长的时光内,能使每个作业都运行一次。

12、试从交互性、准时性以及牢靠性方面,将分时系统与实时系统举行比较。

(1)准时性。

实时信息处理系统对实时性的要求与分时系统类似,都就是以人所能接受的等待时光来确定,而实时控制系统的准时性,就是以控制对象所要求的开头截止时光或完成截止时光来确定的,普通为秒级到毫秒级,甚至有的要低于100微妙。

(2)交互性。

实时信息处理系统具有交互性,但人与系统的交互仅限于拜访系统中某些特定的专用服务程序,不像分时系统那样能向终端用户提供数据与资源分享等服务。

(3)牢靠性。

分时系统也要求系统牢靠,但相比之下,实时系统则要求系统具有高度的牢靠性。

由于任何差错都可能带来巨大的经济损失,甚至就是灾害性后果,所以在实时系统中,往往都实行了多级容错措施保障系统的平安性及数据的平安性。

13、OS有哪几大特征?其最基本的特征就是什么?并发性、分享性、虚拟性与异步性四个基本特征。

操作系统第九版部分课后作业习题答案分析解析

操作系统第九版部分课后作业习题答案分析解析

CHAPTER 9 Virtual MemoryPractice Exercises9.1 Under what circumstances do page faults occur? Describe the actionstaken 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, afree frame is located and I/O is requested to read the needed page intothe free frame. Upon completion of I/O, the process table and page tableare updated and the instruction is restarted.9.2 Assume that you have a page-reference string for a process with mframes (initially all empty). The page-reference string has length p;n distinct page numbers occur in it. Answer these questionsfor anypage-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-bitvirtual 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 physicaladdresses in hexadecimal. All numbers are given in hexadecimal. (Adash 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 theirpage-fault rate. Separate those algorithms that suffer from Belady’sanomaly 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 consultedto check whether the corresponding page is resident or not and whetherthe program has read or write privileges for accessing the page. Thesechecks have to be performed in hardware. A TLB could serve as a cacheand improve the performance of the lookup operation.9.6 An operating system supports a paged virtual memory, using a centralprocessor with a cycle time of 1 microsecond. It costs an additional 1microsecond to access a page other than the current one. Pages have 1000words, and the paging device is a drum that rotates at 3000 revolutionsper minute and transfers 1 million words per second. The followingstatistical measurements were obtained from the system:• 1 percent of all instructions executed accessed a page other than thecurrent page.Of the instructions that accessed another page, 80 percent accesseda page already in memory.Practice Exercises 31When a new page was required, the replaced page was modified 50percent of the time.Calculate the effective instruction time on this system, assuming that thesystem is running one process only and that the processor is idle duringdrum 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 pagesof size 200. A small process that manipulates the matrix resides in page0 (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;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 replacementalgorithms, assuming one, two, three, four, five, six, or seven frames?Remember all frames are initially empty, so your first unique pages willall cost one fault each.LRU replacement• FIFO replacementOptimal replacement32 Chapter 9 Virtual MemoryAnswer:Number of frames LRU FIFO Optimal1 20 20 202 18 18 153 15 16 114 10 14 86 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 areference bit even if one were not provided by the hardware, or explainwhy it is not possible to do so. If it is possible, calculate what the costwould be.Answer:You can use the valid/invalid bit supported in hardware to simulate thereference bit. Initially set the bit to invalid. On first reference a trap to theoperating system is generated. The operating system will set a softwarebit to 1 and reset the valid/invalid bit to valid.9.10 You have devised a new page-replacement algorithm that you think maybe optimal. In some contorted test c ases, Belady’s anomaly occurs. Is thenew 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 longest 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 sucha 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. Considerstrategies for systems where segments cannot be relocated, and thosefor systems where they can.Answer:a. FIFO. Find the first segment large enough to accommodate theincoming 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 leftoverspace 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 becontiguous 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 resultsare one of the following alternatives. For each case, what is happening?Can the degree of multiprogramming be increased to increase the CPUutilization? 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 percent Answer:a. Thrashing is occurring.b. CPU utilization is sufficiently high to leave things alone, andincrease degree of multiprogramming.c. Increase the degree of multiprogramming.9.13 We have an operating system for a machine that uses base and limitregisters, but we have modified the machine to provide a page table.Can the page tables be set up to simulate base and limit registers? Howcan they be, or why can they not be?Answer:The page table can be set up to simulate base and limit registers providedthat the memory is allocated in fixed-size segments. In this way, the baseof a segment can be entered into the page table and the valid/invalid bitused 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 a single-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 aneconomicalmethod of disk scheduling. But LOOK is nearly as easy to programand 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 anotherapplication is active in the foreground.10.2.Explain why SSTF scheduling tends to favor middle cylinders over 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.Ifthe head is not in the center of the disk and a new request arrives,thenew 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, is 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130 Starting 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 followingdisk-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. 12CHAPTERImplementationPractice 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 arerequired for contiguous, linked, and indexed (single-level) allocationstrategies, if, for one block, the following conditions hold. In thecontiguous-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 bemounted simultaneously at more than one location? Answer:4344 Chapter 12 ImplementationThere would be multiple paths to the same file, which could confuseusers or encourage mistakes (deleting a file with one path deletes thefile in all the other paths).12.3 Why 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 whichstrategy 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 thisproblem is to define a file structure consisting of an initial contiguousarea (of a specified size). If this area is filled, the operating systemautomatically defines an overflow area that is linked to the initialcontiguous area. If the overflow area is filled, another overflow areais allocated. Compare this implementation of a file with the standardcontiguous 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 usemore 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, moreexpensive 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 theoperating 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 supportmultiple 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 specificfunctions for the target file system at the VFS layer. The calling programhas no file-system-specific code, and the upper levels of the system callstructures likewise are file system-independent. The translation at theVFS layer turns these generic calls into file-system-specific operations.。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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.12CHAPTERImplementationPractice 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 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 Why 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—i f 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 number or size of caches would increase system cost.12.7 Why is it advantageous for the user for an operating system to dynamically 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, kernel structures 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 sp ecific 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 call structures likewise are file system-independent. The translation at the VFS layer turns these generic cal ls into file-system-specific operations.。

相关文档
最新文档