操作系统作业解析答案
操作系统练习题_及答案解析

操作系统练习题第一章引言(一单项选择题1 操作系统是计算机系统的一种( 。
A.应用软件B. 系统软件c. 通用软件D.工具软件2.操作系统目的是提供一个供其他程序执行的良好环境,因此它必须使计算机( A.使用方便B. 高效工作C.合理使用资源D.使用方便并高效工作3.允许多个用户以交互方式使用计算机的操作系统是( 。
A.分时操作系统B. 批处理单道系统C.实时操作系统D.批处理多道系统4.下列系统中( 是实时系统。
A.计算机激光照排系统B. 办公自动化系统C.化学反应堆控制系统D.计算机辅助设计系统5.操作系统是一种系统软件,它( 。
A.控制程序的执行B. 管理计算机系统的资源C.方便用户使用计算机D.管理计算机系统的资源和控制程序的执行6.计算机系统把进行( 和控制程序执行的功能集中组成一种软件,称为操作系统A.CPU 管理B.作业管理C.资源管理D.设备管理7.批处理操作系统提高了计算机系统的工作效率,但( 。
A.不能自动选择作业执行B. 无法协调资源分配c.不能缩短作业执行时间D 在作业执行时用户不能直接干预8.分时操作系统适用于( 。
A.控制生产流水线B.调试运行程序c.大量的数据处理D.多个计算机资源共享9.在混合型操作系统中,“前台”作业往往是指( 。
A.由批量单道系统控制的作业B.由批量多道系统控制的作业c.由分时系统控制的作业D.由实时系统控制的作业10.在批处理兼分时的系统中,对( 应该及时响应,使用户满意。
A.批量作业B.前台作业c.后台作业D.网络通信11.实时操作系统对可靠性和安全性要求极高,它( 。
A.十分注重系统资源的利用率B.不强调响应速度c.不强求系统资源的利用率D.不必向用户反馈信息12.分布式操作系统与网络操作系统本质上的不同之处在于( 。
A.实现各台计算机之间的通信B.共享网络个的资源c.满足较大规模的应用D.系统中若干台计算机相互协作完成同一任务13.SPOOL技术用于( 。
操作系统作业题及答案

《操作系统》课程作业(2013年春)姓名:学号:专业:年级:学校:日期:作业一:作业管理1、有三道程序A、B、C在一个系统中运行,该系统有输入、输出设备各1台。
三道程序A、B、C构成如下:A:输入32秒,计算8秒,输出5秒B:输入21秒,计算14秒,输出35秒C:输入12秒,计算32秒,输出15秒问:(1)三道程序顺序执行的总时间是多少?(2)充分发挥各设备的效能,并行执行上述三道程序,最短需多少时间(不计系统开销)?并给出相应的示意图。
2、假设一个单CPU系统,以单道方式处理一个作业流,作业流中有2道作业,共占用CPU计算时间、输入卡片数和打印输出行数如下:其中,卡片输入机速度为1000张/分钟,打印机输出速度为1000行/分钟,试计算:(1)不采用spooling技术,计算这两道作业的总运行时间(从第1道作业输入开始到最后一个作业输出完毕)。
(2)如采用spooling技术,计算这2道作业的总运行时间(不计读/写盘时间),并给出相应的示意图。
作业二:进程管理1、 请写出两程序S1和S2可并发执行的Bernstein 条件。
2、 有以下5条语句,请画出这5条语句的前趋图。
S1:y=x+1 R(x) W(y) S2:c=f-w R(f,w) W(c) S3:d=r-y R(r,y) W(d) S4:x=a+b R(a,b) W(x) S5:r=c+y R(c,y) W(r)3、 设在教材第62页3.6.4节中所描述的生产者消费者问题中,其缓冲部分为m 个长度相等的有界缓冲区组成,且每次传输数据长度等于有界缓冲区长度以及生产者和消费者可对缓冲区同时操作。
重新描述发送过程deposit(data)和接收过程remove(data)。
P P P iP ....12ik4、 设有k 个进程共享一临界区,对于下述情况,请说明信号量的初值、含义,并用P ,V操作写出有关互斥算法。
(1) 一次只允许一个进程进入临界区;(2) 一次允许m (m<k )个进程进入临界区。
奥鹏北语14秋《操作系统》作业3满分答案

一,单选题
1.Dijkstra算法是()算法。
A.死锁预防
B.死锁避免
C.死锁检测
D.死锁恢复
?
正确答案:B
2.主存储器技术可分为实存储器技术和()存储器技术
A.固定分区
B.可变分区
C.虚拟
D.动态
?
正确答案:C
3.虚拟存储器最基本的特征是___。
A.交换性
B.提高内存利用率
A.时钟页面
B.最佳
C.最近未使用
D.最近最少使用
?
正确答案:D
16.以下是可抢占资源的是()
A.打印机
B. CPU
C.读卡机
D.传真机
?
正确答案:B
17.支持程序浮动的地址转换机制是___。
A.页式地址转换
B.段式地址转换
C.静态重定位
D.动态重定位
?
正确答案:D
18.进程所请求的一次打印输出结束之后,将使进程状态从___。
A.互斥
B.不可抢占
C.同步
D.循环等待
?
正确答案:D
7.作业进入内存到处理完毕进入输出井,这一过程中作业处于___。
A.执行
B.后备
C.完成
D.退出
?
正确答案:A
8.分页情况下,系统以()为单位把主存分给进程。
A.页架
B.页面
C.页表
D.页
?
正确答案:A
9.共享型设备包括除___机以外的所有块型设备。
A.磁盘机
B.磁带机
C.光盘
D.磁鼓
?
正确答案:B
10.对硬盘信息的存取是以___为单位进行的。
操作系统第九版部分课后作业习题答案解析

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.。
操作系统习题解答

《操作系统》习题解答习题11.术语解释裸机虚拟机操作系统程序接口命令接口非特权指令特权指令核心态用户态系统调用微内核批处理系统分时实时指令的执行周期中断中断源中断请求中断屏蔽中断禁止GPL POSIX 时间片答案:·未配置任何软件的计算机称为“裸机”。
·在裸机上安装一层软件,使机器的功能得以扩展,这时展现在用户面前的“机器”,就是所谓的虚拟机。
·操作系统是控制和管理计算机硬件和软件资源、合理地组织计算机工作流程以及方便用户使用计算机的一个大型系统软件。
·在用户编写的程序中,可使用系统调用命令获得操作系统提供的各种功能服务,这是操作系统在程序一级给予用户的支持,称其为程序接口。
·用户可使用操作系统提供的各种操作命令,通过键盘(或鼠标)控制和完成程序的运行,这是操作系统在作业控制一级给予用户的支持,称为命令接口。
·操作系统和用户程序都能使用的硬指令,称为非特权指令。
·只能由操作系统使用的硬指令,称为特权指令。
·所谓核心态,是指CPU处于可执行包括特权指令在内的一切机器指令的状态。
·所谓用户态,是指CPU处于只能执行非特权指令的状态。
·操作系统里预先编制了很多不同功能的子程序。
用户在自己的程序里调用这些子程序,以求得操作系统提供的功能服务。
就把这些功能服务子程序称为“系统功能调用”程序,简称“系统调用”。
·微内核即是把操作系统的内核分为基本功能和非基本功能两部分,在内核里只保留基本功能部分,在核心态下运行;非基本功能部分则从内核剥离下来,让它们以各种服务的形式,在用户态下运行。
这一的操作系统内核,称为微内核。
·若在某系统中,用户作业被分批处理,在处理一批的过程中不允许用户与计算机发生交互作用,即使作业在运行中出现错误,也只能等到整批作业处理完毕后在机下修改。
这样的系统,就是所谓的“批处理系统”。
操作系统第九版部分课后作业习题答案分析解析

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.什么是操作系统?其主要功能是什么?操作系统是控制和管理计算机系统内各种硬件和软件资源,有效组织多道程序运行的系统软件(或程序集合),是用户和计算机直接的程序接口.2.在某个计算机系统中,有一台输入机和一台打印机,现有两道程序投入运行,程序A、B 同时运行,A略早于B。
A的运行轨迹为:计算50ms、打印100ms、再计算50ms、打印100ms,结束。
B的运行轨迹为:计算50ms、输入80ms、再计算100ms,结束。
试说明:(1)两道程序运行时,CPU是否空闲等待?若是,在那段时间段等待?(2)程序A、B是否有等待CPU的情况?若有,指出发生等待的时刻。
0 50 100 150 200 250 30050 100 50 10050 100 20 100(1) cpu有空闲等待,在100ms~150ms的时候.(2) 程序A没有等待cpu,程序B发生等待的时间是180ms~200ms.1.设公共汽车上,司机和售票员的活动如下:司机的活动:启动车辆;正常行车;到站停车。
售票员的活动:关车门;售票;开车门。
在汽车不断的到站、停车、行驶过程中,用信号量和P、V操作实现这两个活动的同步关系。
semaphore s1,s2;s1=0;s2=0;cobegin司机();售票员();coendprocess 司机(){while(true){P(s1) ;启动车辆;正常行车;到站停车;V(s2);}}process 售票员(){while(true){关车门;V(s1);售票;P(s2);开车门;上下乘客;}}2.设有三个进程P、Q、R共享一个缓冲区,该缓冲区一次只能存放一个数据,P进程负责循环地从磁带机读入数据并放入缓冲区,Q进程负责循环地从缓冲区取出P进程放入的数据进行加工处理,并把结果放入缓冲区,R进程负责循环地从缓冲区读出Q进程放入的数据并在打印机上打印。
请用信号量和P、V操作,写出能够正确执行的程序。
操作系统作业参考答案及其知识点

占有和等待条件:申请新资源时得不到满足等待,不释放已占有资源
不剥夺条件:一个进程不能抢夺其他进程占有的资源
循环等待条件:存在一组进程循环等待资源的
31、何谓银行家算法?叙述其基本原理。
答:
银行家算法是资源分配时的保守算法,系统掌握资源动态申请和使用情况,每次资源申请时用某种分配算法测试安全性,以避免死锁发生。
包含三类基本信息:
(1)标识信息
•PID用于唯一地标识一个进程,分由用户使用的外部标识符和被系统使用内部标识号。
•常用的标识信息有进程标识符、父进程的标识符、用户进程名、用户组名等。
(2)现场信息
•保留进程运行时存放在处理器现场中的各种信息,进程让出处理器时必须把处理器现场信息保存到PCB中,当该进程重新恢复运行时也应恢复处理器现场。
操作系统作业参考答案及其知识点
第一章
思考题:
10、试叙述系统调用与过程调用的主要区别?
答:
(一)、调用形式不同
(二)、被调用代码的位置不同
(三)、提供方式不同
(四)、调用的实现不同
提示:每个都需要进一步解释,否则不是完全答案
13、为什么对作业进程批处理可以提高系统效率?
答:批处理时提交程序、数据和作业说明书,由系统操作员把作业按照调度策略,整理为一批,按照作业说明书来运行程序,没有用户与计算机系统的交互;采用多道程序设计,可以使CPU和外设并行工作,当一个运行完毕时系统自动装载下一个作业,减少操作员人工干预时间,提高了系统的效率。
基本工作原理:当一个进程要发送消息时,先在自己的消息发送区里生成发送的消息;然后向系统申请一个消息缓冲区,把消息从发送区复制到消息缓冲区中;随后该消息缓冲区被挂到接收消息的进程的消息队列上,供接近者在需要时从消息队列中摘下并复制到消息接近区去使用,同时释放消息缓冲区
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
选择题:(10道题)2.操作系统有并发、( B )、虚拟和异步四大基本特性。
A.独立B.共享C.动态D.及时正确答案:B解析:第一章第4小节内容,操作系统具有四大特征并发、共享、虚拟和异步。
其中最重要的的特征是并发性,要注意并发和并行的区别。
3.分时系统中,进程状态变迁,进程从运行态转变到就绪状态的原因是(A)。
A.时间片到B.中断返回C.被抢占D.睡眠正确答案:A解析:第二章第2小节内容,主要是进程最基础的三种基本状态之间的转换,当处于执行(运行)状态的进程时间片用完而此时进程并未完成,那么进程将要由执行状态转变成就绪转态,注意要理解时间片的概念以及能画出进程三种基本状态的转移图。
4.系统三个进程共享四个同类资源,这些资源的分配与释放只能一次一个。
已知每个进程最多需要两个该类资源,则该系统(A )。
A.必然无死锁B.必然死锁C.进程请求该类资源立刻能得到D.有某进程永远得不到该类资源正确答案:A解析:第三章第5小节内容,最不理想的情况下每个进程都需要2个该类资源才能执行并且每个进程都以申请到1个资源同时申请第二个资源,而此时还有一个资源可供使用,3个进程中任意一个进程再获得1个资源都可执行完毕释放自己的资源供其他进程使用,故必然不会出现死锁现象。
注意这是一类常考题型要总结经验利用假设法去做。
5.按用途分类,文件可以分为系统文件、用户文件和(C)三类。
A.源文件B.目标文件C.库文件D.只读文件正确答案:C解析:第七章第1小节内容,文件类型的分类。
按用途分类可以分为系统文件、用户文件和库文件。
注意其他三类的文件类型分类也要做相应了解,考试常考用途分类,无其他技巧,死记硬背就行了。
6.若信号量S的初值为1,当前值为-2,则表示有(C)个进程因S所代表的资源而阻塞等待。
A.0 B.1 C.2D.3正确答案:C解析:第二章第4节内容,若P、V操作的信号量S初值为1,当前值为-2,则表示有2个进程处在阻塞状态。
这是一类常考题型,这里我总结一下这类题目如何解决,首先要理解信号量S的含义,他表示某类资源当前可用量,当他的数值大于0时,表示当前S信号量表示的资源还有可用的,但是当其小于零时,表示将有进程等待该类资源处于阻塞状态,理解他表示的意义,知一题解百题。
7.数组多路通道的特点是(B)A.通道传输速率高但利用率低B.通道传输速率高且利用率高C.通道传输速率低但利用率高D.通道传输速率低且利用率低正确答案:B解析:第六章第2节内容,数组多路通道是对选择通道的一种改进,当某个设备进行数据传送时,通道只为该设备提供服务;当设备在执行寻址等控制性动作时,通道暂时断开与该设备的连接,挂起该设备的通道程序,而转去为其他设备提供服务,即执行其他设备的通道程序。
所以,数组多路通道很像一个多道程序的处理器。
选择题常见题型,死记硬背记住就行了,其他两种通道也做相应的了解吧。
8.磁盘的访问时间主要由寻道时间、(B )和传输时间三部分组成。
A.启动磁臂时间B.旋转延迟时间C.高速缓存时间D.扫描磁盘时间正确答案:B解析:第六章第8小节内容,磁盘的访问时间主要由寻道时间、旋转延迟时间和传输时间三部分组成,死记硬背就行了,常考题。
9.文件的物理结构有( B )、链接和索引三类。
A.记录B.顺序 C.离散 D.流式正确答案:B解析:第七章第2小节内容,文件按其组织的方式可以分为顺序、链接和索引三类,常考题。
死记硬背就行了。
10.关于虚拟存储器的说法不正确的是( D )。
A.虚拟存储器需具有请求调入和置换功能B.虚拟存储器在逻辑上扩充了内存C.虚拟存储器的理论基础是局部性原理D.虚拟存储器具有驻留性和一次性的特征正确答案:D解析:第五章第1节内容,虚拟存储器具有多次性和对换性和虚拟性三大特征。
驻留性和一次性是常规存储器所具有的特征。
11.下列调度算法中,只适用于进程调度的算法是(D )。
A.先来先服务调度算法B.高优先权优先调度算法C.高响应比优先调度算法D.基于时间片轮转调度算法正确答案:D解析:第三章第3节内容,首先解这道题如果你把算法进程调度作业调度记得很清楚当然知道是第四个选项,但没记住没关系,各种调度算法对象无非是作业和进程,你只要知道时间片是针对进程来说的很快就能选出答案,这里总结一下这两类调度各自有哪些调度算法。
作业调度有4种算法,短作业优先调度算法,先来先服务调度算法高响应比优先调度算法,优先权优先调度算法。
进程调度算法有5种类,轮转调度算法,优先级调度算法,多队列调度算法,多级反馈队列调度算法,基于公平原则调度算法。
判断题:(9道题)2.如果一个进程获得了除CPU外的所有所需运行资源,则该进程进入等待状态(×)正确答案:错解析:第二章第2节内容,其中等待状态就是所谓的阻塞转态,正确答案应该是转为就绪状态。
3.将一个页面由外存调入内存有两种方法,即部分调入和全部调入(×)。
正确答案:错解析:第五章第1节内容,这是一道有意思的题,很多人认为是对,我只能说概念掌握的不清晰,首先我们的页面是虚拟内存的逻辑单位,听清楚了是单位是不可在分割的一个单位所以正确的是程序数据由外存调入内存有两种方法,即部分调入和全部调入。
4.虚存容量的扩大是以牺牲CPU工作时间以及内、外存交换时间为代价的。
(√)正确答案:对解析:第五章第3节内容,理所应当的有得必有失,主要是增加了访问内存的有效时间。
5.树型目录结构能够解决文件重名问题。
(√)正确答案:对解析:第七章第3节内容,其中二级目录和树形目录结构都能解决文件重名的问题,树形目录结构主要的提高检索的速度,是当前最受欢迎的文件目录。
6.原语是一种不可分割的操作。
(√)正确答案:对解析:第二章第4节内容,详细说说原语吧,原语在执行时不可以被阻断,主要分为两类,机器指令级,特点是在执行时不可以被阻断,另一类是功能级的特点是不允许并发执行,这两种都是不可阻断的,其实还可以联系到以前数据库学的事务四大特性的原子性,原子性要么执行成功,那么不执行,所以是不可分割的。
7.在虚拟存储方式下,程序员编制程序时不必考虑主存的容量,但系统的吞吐量在很大程度上依赖于主存储器的容量(√)正确答案:对解析:第五章第1节内容,理论上虚拟存储可以无限大,实际上虚拟内存=内存+外存。
其实要明白吞吐量的概念,他是每秒的数据处理量,吞吐量是在给定时间段内系统完成的交易数量。
即系统的吞吐量越大,说明系统在单位时间内完成的用户或系统请求越多,系统的资源得到充分利用。
那么计算机系统的cpu 主要是与内存连接并行,就是现代计算机的处理数据的速度相当快,限制的原因主要取决主存储器的容量了。
8.文件系统最基本的功能是实现按名存取。
(√)正确答案:对解析:第七章第3节内容,实现按名存取,用户只要向系统提供所需要访问的文件的名字,就能快速查询指定文件在外存的存储位置,这是目录管理最基本的功能也是文件系统向用户提供最基本的服务。
9.进程可以删除自己的PCB表。
(×)正确答案:错解析:第二章第1节内容,这道题涉及到进程的定义,进程组成包括程序段,数据段,和pcb组成,pcb是一种数据结构,这种数据结构标志着进程的各种信息,可以说是进程最核心的组成组分,进程的各种操作也是由pcb决定的,所以题目说的很滑稽。
10.由于资源数少于进程对资源的需求数,因而产生资源的竞争,所以这种资源的竞争必然会引起死锁。
(×)正确答案:错解析:第二章第5节内容,凡是过于绝对的说法大部分是错的,分析一下吧,引起死锁主要原因是进程争抢临界资源,临界资源和临界区就不详说了,为了解决争抢资源引起死锁的情况,我们也采用了各种方式去避免比如银行家算法,所以不一定会产生死锁。
综合题:(2道题)1. 用非抢占式响应比高者优先算法完成下表,并计算出平均周转时间和平均带解析:第三章2节内容,这类题目主要有三种类型,先来先到和短作业优先,高响应比优先调度算法三种情况,做题思路有两点,第一是记住各类公式第二是要注意两点。
响应比=(等待时间+服务时间)/服务时间等待时间=上一个作业完成时间-到达时间完成时间=开始时间+服务时间周转时间=完成时间-到达时间(周转时间定义:从进程提交到进程完成的时间间隔为周转时间.也就是等待进入内存的时间,在就绪队列中等待的时间,在 CPU中执行的时间和I/O操作的时间的总和)带权周转时间=周转时间/服务时间注意点:第一无论是以上的任意一种算法,其第一个作业就是第一次执行的,主要是因为他是第一个到达的,没有其他任何作业与其竞争,适用任何算法。
第二点就是要注意到达时间,有些题目会故意把到达时间整的比较大,当期采用短作业或者高响应比调度算法时,尽管算出来是某一进程优先,但是若没到达就不予以考虑,还有就是多练几道题,公式记熟了,这类题型相当简单。
2. 假设某系统有4类资源R1,R2,R3,R4,有5个并发进程P0,P1,P2,P3,P4,请按照银行家算法回答下列问题。
(1)各进程的最大需求矩阵Max、分配矩阵Allocation和可用资源向量(3)当进程P2申请的资源分别为(0,3,2,0)时,系统能立即满足吗?为什么?解析:第三章第7节内容,银行家算法是一个避免死锁的著名算法,解决这类题目策略主要有两点,一是搞点他的各类符号的定义含义,二是能看懂他给的表。
如果问你是否处于安全状态,啥也别说,直接画个六列N行的表格,再去慢慢加减法计算向表格填数据就行了。
多练习几道题目,这类题目也很简单。
1)可利用资源向量Available是个含有m个元素的数组,其中的每一个元素代表一类可利用的资源数目。
如果Available[j]=K,则表示系统中现有Rj类资源K个。
2)最大需求矩阵Max这是一个n×m的矩阵,它定义了系统中n个进程中的每一个进程对m类资源的最大需求。
如果Max[i,j]=K,则表示进程i需要Rj类资源的最大数目为K。
3)分配矩阵Allocation这也是一个n×m的矩阵,它定义了系统中每一类资源当前已分配给每一进程的资源数。
如果Allocation[i,j]=K,则表示进程i当前已分得Rj类资源的数目为K。
4)需求矩阵Need。
这也是一个n×m的矩阵,用以表示每一个进程尚需的各类资源数。
如果Need[i,j]=K,则表示进程i还需要Rj类资源K个,方能完成其任务。
Need[i,j]=Max[i,j]-Allocation[i,j]安全性算法(1)设置两个向量:①工作向量Work:它表示系统可提供给进程继续运行所需的各类资源数量的多少,它含有m个元素,在执行安全算法开始时,Work∶=Available;②Finish:它表示系统是否有足够的资源分配给进程,使之运行完成。