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

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.。
操作系统第九版部分课后作业习题答案分析解析

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.。
操作系统(1~8章的课后习题答案)

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

北京大学操作系统课后题参考答案操作系统1.什么是计算机系统?计算机系统是怎么构成的?了解PC的组成情况,说明:1)硬件组织的基本结构,画出硬件配置图;2)主要系统软件和应用软件(若有的话)他们的作用。
答:计算机系统就是按照人的要求接收和存储信息,自动进行数据处理和计算,并输出结果信息的系统。
计算机系统由硬件子系统和软件子系统组成。
计算机系统的构成包括:如图 1.2计算机硬件系统的构成:如图 1.42.从功能以及程序涉设计的角度说明计算机系统中软件系统是如何构成的?答:计算机系统中软件系统分为系统软件,支撑软件和应用软件三层。
3.什么是操作系统?请举例说明操作系统在计算机系统中的重要地位。
答:操作系统是计算机系统中的一个系统软件,是一些程序模块的集合。
它们能以尽量有效、合理的方式组织和管理计算机的软硬件资源,合理的组织计算机的工作流程,控制程序的执行并向用户提供各种服务功能,使得用户能够灵活、方便、有效的使用计算机,使整个计算机系统能安全高效地运行4.请举一个实际的例子来说明操作系统的功能。
答:你能用用操作系统管理很多资源5.为什么说“操作系统是控制硬件的软件”的说法不确切?答:操作系统不仅能够控制硬件,也可以控制各种软件资源。
6.操作系统的基本特征是什么?说明他们之间的关系。
答:1.并发性2.共享性3.随机性7.试从独立性,并发性和交互性和实时性四个方面来比较批处理系统,分时系统以及实时系统。
答:分时系统:并发性是指同时有多个用户共同使用一个计算机,宏观上看是多个人同时使用一个CPU,微观上是多个人在不同时刻轮流使用CPU.独占性,是指用户感觉不到计算机为他们服务,就好像整个系统为他所独占。
交互性:是指用户根据系统响应结果进一步提出新要求,用户直接干预每一步。
实时性:是指系统对用户提出的请求及时响应。
8.引入多道程序设计技术的起因和目的是什么?多道程序系统的特征是什么?答:多道程序设计的基本思想在内存中保持多个作业,主机可以交替的方式同时处理多个作业,一般来说任何一道作业的运行总是要交替的使用处理器和外设子案9.多道程序设计的度是指在任一给定时刻,单个CPU所能支持的进程数目最大值。
操作系统 第三章,第四章,第九章课后习题整理

第3章进程描述和控制复习题:什么是指令跟踪?答:指令跟踪是指为该进程而执行的指令序列。
通常那些事件会导致创建一个进程?答:新的批处理作业;交互登录;操作系统因为提供一项服务而创建;由现有的进程派生。
(详情请参考表3.1)对于图3.6中的进程模型,请简单定义每个状态。
答:运行态:该进程正在执行。
就绪态:进程做好了准备,只要有机会就开始执行。
阻塞态:进程在某些事件发生前不能执行,如I/O操作完成。
新建态:刚刚创建的进程,操作系统还没有把它加入到可执行进程组中。
退出态:操作系统从可执行进程组中释放出的进程,或者是因为它自身停止了,或者是因为某种原因被取消。
抢占一个进程是什么意思?答:处理器为了执行另外的进程而终止当前正在执行的进程,这就叫进程抢占。
什么是交换,其目的是什么?答:交换是指把主存中某个进程的一部分或者全部内容转移到磁盘。
当主存中没有处于就绪态的进程时,操作系统就把一个阻塞的进程换出到磁盘中的挂起队列,从而使另一个进程可以进入主存执行。
为什么图3.9(b)中有两个阻塞态?答:有两个独立的概念:进程是否在等待一个事件(阻塞与否)以及进程是否已经被换出主存(挂起与否)。
为适应这种2*2的组合,需要两个阻塞态和两个挂起态。
列出挂起态进程的4个特点。
答:1.进程不能立即执行。
2.进程可能是或不是正在等待一个事件。
如果是,阻塞条件不依赖于挂起条件,阻塞事件的发生不会使进程立即被执行。
3.为了阻止进程执行,可以通过代理把这个进程置于挂起态,代理可以是进程自己,也可以是父进程或操作系统。
4.除非代理显式地命令系统进行状态转换,否则进程无法从这个状态中转移。
对于哪类实体,操作系统为了管理它而维护其信息表?答:内存、I/O、文件和进程。
列出进程控制块中的三类信息。
答:进程标识,处理器状态信息,进程控制信息。
为什么需要两种模式(用户模式和内核模式)?答:用户模式下可以执行的指令和访问的内存区域都受到限制。
这是为了防止操作系统受到破坏或者修改。
计算机操作系统课后习题答案解析张尧学

第一章绪论1.什么是操作系统的基本功能?答:操作系统的职能是管理和控制汁算机系统中的所有硬、软件资源,合理地组织计算机工作流程,并为用户提供一个良好的工作环境和友好的接口。
操作系统的基本功能包括:处理机管理、存储管理、设备管理、信息管理(文件系统管理)和用户接口等。
2.什么是批处理、分时和实时系统?各有什么特征?答:批处理系统(batchprocessingsystem):操作员把用户提交的作业分类,把一批作业编成一个作业执行序列,由专门编制的监督程序(monitor)自动依次处理。
其主要特征是:用户脱机使用计算机、成批处理、多道程序运行。
分时系统(timesharingoperationsystem):把处理机的运行时间分成很短的时间片,按时间片轮转的方式,把处理机分配给各进程使用。
其主要特征是:交互性、多用户同时性、独立性。
实时系统(realtimesystem):在被控对象允许时间范围内作出响应。
其主要特征是:对实时信息分析处理速度要比进入系统快、要求安全可靠、资源利用率低。
3.多道程序(multiprogramming)和多重处理(multiprocessing)有何区别?答;多道程序(multiprogramming)是作业之间自动调度执行、共享系统资源,并不是真正地同时值行多个作业;而多重处理(multiprocessing)系统配置多个CPU,能真正同时执行多道程序。
要有效使用多重处理,必须采用多道程序设计技术,而多道程序设计原则上不一定要求多重处理系统的支持。
6.设计计算机操作系统时与那些硬件器件有关运算器、控制器、存储器、输入设备、输出设备第二章作业管理和用户接口2.作业由哪几部分组成?各有什么功能?答:作业由三部分组成:程序、数据和作业说明书。
程序和数据完成用户所要求的业务处理工作,作业说明书则体现用户的控制意图。
3.作业的输入方式有哪几种?各有何特点答:作业的输入方式有5种:联机输入方式、脱机输入方式、直接耦合方式、SPOOLING(Simultaneous Peripheral OperationsOnline)系统和网络输入方式,各有如下特点:(1)联机输入方式:用户和系统通过交互式会话来输入作业。
《操作系统》课后题
习题一1、什么是操作系统?操作系统与普通的程序工作方式有何不同?操作系统是一个大型的程序系统,它负责计算机系统软、硬件资源的分配和管理;控制和协调并发活动;提供用户借口,使用户获得良好的工作环境。
操作系统资源管理的目标是提高系统资源的利用率和方便用户使用。
操作系统实际上是一组计算机程序,与普通的程序工作方式相同。
主要区别在于程序的意图和运行模式不同。
操作系统控制CPU和其它系统资源的使用,并调度CPU运行普通程序的时间。
OS的程序在核心态(kernel mode)下运行,硬件保护它免受用户程序的破坏;而应用程序都在用户态(user mode)下运行,它们不受硬件保护。
2、批处理系统与分时系统各有那些特点?为什么一般而言分时系统对交互式用户的响应比较快?批处理系统:先将程序加载到内存中然后再由CPU执行。
时系统:分时系统是把处理机时间划分成很短的时间片(如几百毫秒)轮流地分配给各个联机作业使用,如果某个作业在分配的时间片用完之前还未完成计算,该作业就暂时中断。
分时系统由于是时间片轮转来运行程序,所以比多道处理系统响应更快。
3、操作系统的主要特征是什么?操作系统的特征有:并发性,共享性,不确定性,虚拟性。
4、操作系统的主要功能是什么?存储器管理的功能处理机管理的功能设备管理的功能文件管理的功能5、多道程序执行时的特征是什么?需要多道程序设计的主要原因是什么?特征:(1)多道:计算机内存中同时存放几道相互独立的程序。
(2)宏观上并行:同时进入系统的几道程序都处于运行过程中,即它们先后开始了各自的运行,但都未运行完毕。
(3)微观上串行:从微观上看,内存中的多道程序轮流地或分时地占有处理机,交替执行(单处理机情况)原因:改善了输入输出量少,外围设备空闲、主机空闲6、何谓脱机I/O和联机I/O?(I/O输入输出)脱机I/O 是指事先将装有用户程序和数据的纸带或卡片装入纸带输入机或卡片机,在外围机的控制下,把纸带或卡片上的数据或程序输入到磁带上。
操作系统习题课
3、在甲地和乙地之间有一条弯曲小路,其中从S到T段每次只ቤተ መጻሕፍቲ ባይዱ许一 辆自行车通过,但中间有一安全岛M(同时允许两辆自行车停留), 可供两辆自行车在已从两端进入小路情况下错车使用,如下图所示。 试设计一个算法来保证来往自行车均可顺利通过。(南开97考研题) 乙地 T
K
M
L
S 甲地
4、华工99考研题 设公共汽车上,司机和售票员活动分别为: 司机: 启动车辆 正常行车 到站停车 售票员: 上乘客 关车门 售票 开车门 下乘客 在汽车不断地到站、停车、行驶过程中,这两个活动有什么同步关 系?并用信号灯和PV操作实现他们的同步。
Pa
Pb
Pc
buf1
buf2
7、有一个仓库,可以存放A、B两种产品,仓库的存储空间足够大, 但要求: (1)每次只能存入一种产品(A或B) (2)-n<A产品数-B产品数<m 其中,n和m是正整数。试用PV操作描述产品A、B的入库过程。 (PKU91)
8、理发师问题: 理发店有n把椅子和一个理发师; 如果没有顾客,理发师睡觉; 如果顾客进入理发店,发现椅子满,离开;否则在空椅子上等待; 如果理发师正在睡觉,顾客必须唤醒他。试用PV操作写出工作流程。
11 桌上有1只盘子,每次只能放/取1个水果; 爸爸专门向盘中放苹果,妈妈专门放桔子; 女儿专吃苹果,儿子专吃桔子; 请用PV操作实现4个人的同步关系。(南京理工04)
死锁
• 若系统中有5台绘图仪,有多个进程每个进程都 需要2个绘图仪,规定每个进程每次只能申请1 台,则最多允许几个进程并发运行,才不会发 生死锁? • 死锁是指系统中所有进程均处于阻塞状态( )
5-1、设有8个进程,它们在并发系统中执行时有下图的顺序关系, 试用PV操作实现这些进程的同步。(PKU91考研题) P1 P2
操作系统课后习题答案4
6. 设备管理6.1 例题解析例6.2.1 何谓虚拟设备?请说明SPOOLing系统是如何实现虚拟设备的。
解本题的考核要点是虚拟设备的实现方法。
虚拟设备是指利用软件方法,比如SPOOLing系统,把独享设备分割为若干台逻辑上的独占的设备,使用户感受到系统有出若干独占设备在运行。
当然,系统中至少一台拥有物理设备,这是虚拟设备技术的基础。
SPOOLing系统又称“假脱机I/O系统”,其中心思想是,让共享的、高速的、大容量外存储器(比如,磁盘)来模拟若干台独占设备,使系统中的一台或少数几台独占设备变成多台可并行使用的虚拟设备。
SPOOLing系统主要管理外存上的输入井和输出井,以及内存中的输入缓冲区和输出缓冲区。
其管理进程主要有输入和输出进程,负责将输入数据装入到输入井,或者将输出井的数据送出。
它的特点是:提高了I/O操作的速度;将独占设备改造为共享设备;实现了虚拟设备功能。
例6.2.2有关设备管理要领的下列叙述中,( )是不正确的。
A.通道是处理输入、输出的软件B.所有外围设备都由系统统一来管理C.来自通道的I/O中断事件由设备管理负责处理D.编制好的通道程序是存放在主存贮器中的E.由用户给出的设备编号是设备的绝对号解本题的考核要点是设备管理的基本概念。
(1)通道是计算机上配置的一种专门用于输入输出的设备,是硬件的组成部分。
因此A是错误的。
(2)目前常见I/O系统其外部设备的驱动和输入输出都由系统统一管理。
因此B是对的。
(3)设备管理模块中的底层软件中配有专门处理设备中断的处理程序。
通道中断属于设备中断的一种。
因此C是对的。
(4)通道设备自身只配有一个简单的处理装置(CPU),并不配有存储器,它所运行的通道程序全部来自内存。
因此D是对的。
(5)系统在初启时为每台物理设备赋予一个绝对号,设备绝对号是相互独立的。
由用户给出的设备号只能是逻辑编号,由系统将逻辑号映射为绝对号。
因此E是错误的。
0 6. 设备管理112例6.2.3 在关于SPOOLING 的叙述中, 描述是不正确的。
操作系统第八章课后习题
1.目前常用的外存有哪几种组织方式?答;(1)连续组织方式。
为每一个文件分配--组位置相邻接的盘块,由此形成的文件物理结构是顺序式的文件结构。
(2)链接组织方式。
为每个文件分配一组位置离散的盘块,通过给每个盘块设置一个指针,将属于同-一个文件的盘块链接在一起,链接的顺序和文件的逻辑页的顺序一致。
由此形成的文件物理结构是链接文件。
(3)索引组织方式。
为每个文件分配--组位置离散的盘块,为每个文件建立一个物理结构的索引表,记录分配给该文件的物理盘块,以及这些盘块和文件逻辑页顺序的对应关系。
由此形成的文件物理结构是索引文件。
2 •山连续组织方式所形成的顺序文件的主要优缺点是什么?它主要应用于何种场合?(1)连续组织方式所形成的顺序文件的主要优点①顺序访问容易②顺序访问速度快(2)连续组织方式所形成的顺序文件的主要缺点①要求为一个文件分配连续的存储空间②必须事先知道文件的长度;③不能灵活地删除和插入记录④对于那些动态增长的文件,山于事先很难知道文件的最终大小,因而很难为分配空间,而即使事先知道文件的最终大小,在采用预分配存储空间的方法时也会使大量的存储空间长期空闲。
(3)主要适用场合:连续组织方式所形成的顺序文件是一种最简单、最常用的文件组织方法,它适用于许多资料处理的场合,如磁带文件,打印文件都是常用的顺序文件。
3.在链接式文件中常用哪种链接方式?为什么?答:链接方式分为隐式链接和显式链接两种形式。
隐式链接是在文件U录的每U 录项中,都含有指向链接文件第一个盘块和最后一个盘块的指针。
显式链接贝把用于链接文件各物理块的指针,显式地存放在内存的一张链接表中。
4•在文件分配表中为什么要引入“簇”的概念?以“簇"为基本的分配单位有什么好处?(1)引入“簇”的原因:为了适应磁盘容量不断增大的需要,在进行盘块分配时不再以盘块而是以簇(Cluster)为基本单位。
一个簇应包含扇区的数量与磁盘量的大小直接有关。