操作系统第五版答案第7章内存管理

合集下载

操作系统教程第五版费翔林课后答案

操作系统教程第五版费翔林课后答案

操作系统教程第五版费翔林课后答案本文是针对操作系统教程第五版费翔林书籍中的课后题目提供的答案解析。

在这个教程中,费翔林教授详细介绍了操作系统的基本概念、原理和实践,涵盖了进程管理、内存管理、文件系统、设备管理等各个方面。

通过对这些课后题目的解答,可以更好地理解和巩固操作系统的知识。

第一章:引论1.什么是操作系统?它的主要目标是什么?–答案:操作系统是一种控制和管理计算机硬件和软件资源的系统软件。

操作系统的主要目标是为用户提供一个方便、高效、安全的计算机环境。

2.请简要描述操作系统的角色和功能。

–答案:操作系统有几个角色和功能:•资源管理:操作系统管理计算机的各种硬件资源,包括处理器、内存、存储设备和输入输出设备。

•进程管理:操作系统创建、调度和终止进程,以及处理进程间的通信和同步。

•内存管理:操作系统分配和回收内存,管理虚拟内存,以及处理内存的保护和共享机制。

•文件系统:操作系统管理文件和目录的存储和访问,提供文件的创建、读取、写入和删除等操作。

•设备管理:操作系统管理计算机的输入输出设备,包括键盘、鼠标、显示器、打印机等。

•用户接口:操作系统提供了与计算机交互的界面,包括命令行界面和图形用户界面等。

第二章:进程管理1.什么是进程?进程的状态有哪些?–答案:进程是指在计算机中正在运行的程序的实例。

进程的状态包括:•就绪:进程已经准备好执行,但是还没有被分配到处理器。

•运行:进程正在处理器上执行。

•阻塞:进程由于某些原因不能继续执行,需要等待某个事件的发生。

•终止:进程已经完成或被终止,等待被操作系统回收。

2.请简要描述进程的创建、终止和状态切换的过程。

–答案:进程的创建是通过调用系统调用来完成的,系统为新进程分配资源,并设置进程的初始状态。

进程的终止可以是正常终止(调用系统调用进行退出)或异常终止(例如发生错误)。

进程状态之间的切换通过操作系统的调度算法来实现,例如从就绪状态切换到运行状态,或从运行状态切换到阻塞状态。

操作系统第五版--精髓与设计概要第7章课后习题答案2

操作系统第五版--精髓与设计概要第7章课后习题答案2

7.1.如果使用动态分区方案,下图所示为在某个给定的时间点的内存配置:阴影部分为已经被分配的块;空白部分为空闲块。

接下来的三个内存需求分别为40MB,20MB和10MB。

分别使用如下几种放置算法,指出给这三个需求分配的块的起始地址。

a.首次适配b.最佳适配c.临近适配(假设最近添加的块位于内存的开始)d.最坏适配答:a.40M的块放入第2个洞中,起始地址是80M. 20M的块放入第一个洞中.起始地址是20M. 10M的块的起始地址是120M。

b.40M,20N,10M的起始地址分别为230M,20M和160M.c.40M,20M,10M的起始地址是80M,120160M.d.40M,20M,10M,的起始地址是80M,230M,360M.7.2.使用伙伴系统分配一个1MB的存储块。

a.利用类似于图7.6的图来说明按下列顺序请求和返回的结果:请求70;请求35;请求80;返回A;请求60;返回B;返回D;返回C。

b.给出返回B之后的二叉树表示。

答:a.b.7.3.考虑一个伙伴系统,在当前分配下的一个特定块地址为011011110000.a.如果块大小为4,它的伙伴的二进制地址为多少?b.如果块大小为16,它的伙伴的二进制地址为多少?答:a.011011110100b.0110111000007.4.令buddy k(x)为大小为2k、地址为x的块的伙伴的地址,写出buddy k(x)的通用表达式。

答:7.5.Fabonacci序列定义如下:F0=0,F1=1,F n+2=F n+1+F n,n≧0a.这个序列可以用于建立伙伴系统吗?b.该伙伴系统与本章介绍的二叉伙伴系统相比,有什么优点?答:a.是。

字区大小可以确定Fn = Fn-1 + Fn-2.。

b.这种策略能够比二叉伙伴系统提供更多不同大小的块,因而具有减少内部碎片的可能性。

但由于创建了许多没用的小块,会造成更多的外部碎片。

7.6.在程序执行期间,每次取指令后处理器把指令寄存器的内容(程序计数器)增加一个字,但如果遇到会导致在程序中其他地址继续执行的转跳或调用指令,处理器将修改这个寄存器的内容。

《操作系统精髓与设计原理·第五版》习题答案

《操作系统精髓与设计原理·第五版》习题答案

第1章计算机系统概述1.1、图1.3中的理想机器还有两条I/O指令:0011 = 从I/O中载入AC0111 = 把AC保存到I/O中在这种情况下,12位地址标识一个特殊的外部设备。

请给出以下程序的执行过程(按照图1.4的格式):1.从设备5中载入AC。

2.加上存储器单元940的内容。

3.把AC保存到设备6中。

假设从设备5中取到的下一个值为3940单元中的值为2。

答案:存储器(16进制内容):300:3005;301:5940;302:7006步骤1:3005->IR;步骤2:3->AC步骤3:5940->IR;步骤4:3+2=5->AC步骤5:7006->IR:步骤6:AC->设备61.2、本章中用6步来描述图1.4中的程序执行情况,请使用MAR和MBR扩充这个描述。

答案:1. a. PC中包含第一条指令的地址300,该指令的内容被送入MAR中。

b. 地址为300的指令的内容(值为十六进制数1940)被送入MBR,并且PC增1。

这两个步骤是并行完成的。

c. MBR中的值被送入指令寄存器IR中。

2. a. 指令寄存器IR中的地址部分(940)被送入MAR中。

b. 地址940中的值被送入MBR中。

c. MBR中的值被送入AC中。

3. a. PC中的值(301)被送入MAR中。

b. 地址为301的指令的内容(值为十六进制数5941)被送入MBR,并且PC增1。

c. MBR中的值被送入指令寄存器IR中。

4. a. 指令寄存器IR中的地址部分(941)被送入MAR中。

b. 地址941中的值被送入MBR中。

c. AC中以前的内容和地址为941的存储单元中的内容相加,结果保存到AC中。

5. a. PC中的值(302)被送入MAR中。

b. 地址为302的指令的内容(值为十六进制数2941)被送入MBR,并且PC增1。

c. MBR中的值被送入指令寄存器IR中。

6. a. 指令寄存器IR中的地址部分(941)被送入MAR中。

操作系统 题库 判断题

操作系统 题库 判断题

第一章计算机系统概论1.操作系统类似于计算机硬件和人类用户之间的接口。

答案:T。

2.处理器的一个主要功能是与内存交换数据。

答案:T。

3.一般用户对系统程序无障碍,对应用程序有障碍。

答案:F4.数据寄存器一般是通用的,但可能局限于像浮点数运算这样的特定任务。

T5.程序状态字(PSW)通常包含条件码等状态信息。

条件码是由程序员为操作结果设置的位。

答案:F6.一个单一的指令需要的处理称为执行周期。

答案:F(称为指令周期)7.取到的指令通常被存放在指令寄存器中(IR)。

答案:T8.中断是系统模块暂停处理器正常处理过程所采用的一种机制。

答案:T9.为适应中断产生的情况,必须在指令周期中增加一个额外的读取阶段。

F10.在处理器控制控制例行的中断处理器之前,需要储存的最少信息有程序状态字和当前指令地址。

答案:F11.多中断的一个处理方法是在处理一个中断时禁止再发生中断。

答案:T12.多道程序设计允许处理器使用长时间等待的中断处理的空闲时间。

答案:T13.在两级存取优先级中,命中率定义为对较慢存储器的访问次数与对所有存储器访问次数的比值。

答案:F14.高速缓冲存储器的开发利用了局部性原理,即在处理器与主存储器之间提供一个容量小而快速的存储器。

T15.在高速缓冲存储器的设计中,块大小与高速缓冲存储器和主存储器间的数据交换单位有关。

答案:T16.可编程I/O的一个主要问题是,处理器必须等到I/O模块准备完毕,并且在等待的过程中必须反复不停的检查I/O模块的状态。

答案:T第二章操作系统概述1.操作系统是控制应用程序执行的程序,并充当应用程序和计算机硬件之间的接口。

(对)2.在多用户系统中,操作系统管理那些用作重要目的的资源。

(对)3.操作系统通常在它的专用O/S处理器上并行应用程序。

(错)4.操作系统演化的动力之一就是基本硬件技术的进步。

(对)5. 早期的计算机中没有操作系统,用户直接与硬件打交道。

(对)6 在一个批处理系统,“control is passed to a job”意味着处理器正在取指令和执行用户程序。

操作系统精髓与设计原理第五版习题与答案

操作系统精髓与设计原理第五版习题与答案

第1章计算机系统概述1.1 列出并简要地定义计算机的四个主要组成部分。

主存储器,存储数据和程序;算术逻辑单元,能处理二进制数据;控制单元,解读存储器中的指令并且使他们得到执行;输入/输出设备,由控制单元管理。

1.2 定义处理器寄存器的两种主要类别。

用户可见寄存器:优先使用这些寄存器,可以使机器语言或者汇编语言的程序员减少对主存储器的访问次数。

对高级语言而言,由优化编译器负责决定把哪些变量应该分配给主存储器。

一些高级语言,如C语言,允许程序言建议编译器把哪些变量保存在寄存器中。

控制和状态寄存器:用以控制处理器的操作,且主要被具有特权的操作系统例程使用,以控制程序的执行。

1.3 一般而言,一条机器指令能指定的四种不同操作是什么?处理器-寄存器:数据可以从处理器传送到存储器,或者从存储器传送到处理器。

处理器-I/O:通过处理器和I/O模块间的数据传送,数据可以输出到外部设备,或者从外部设备输入数据。

数据处理:处理器可以执行很多关于数据的算术操作或逻辑操作。

控制:某些指令可以改变执行顺序。

1.4 什么是中断?中断:其他模块(I/O,存储器)中断处理器正常处理过程的机制。

1.5 多中断的处理方式是什么?处理多中断有两种方法。

第一种方法是当正在处理一个中断时,禁止再发生中断。

第二种方法是定义中断优先级,允许高优先级的中断打断低优先级的中断处理器的运行。

1.6 存层次的各个元素间的特征是什么?存储器的三个重要特性是:价格,容量和访问时间。

1.7 什么是高速缓冲存储器?高速缓冲存储器是比主存小而快的存储器,用以协调主存跟处理器,作为最近储存地址的缓冲区。

1.8 列出并简要地定义I/O操作的三种技术。

可编程I/O:当处理器正在执行程序并遇到与I/O相关的指令时,它给相应的I/O模块发布命令(用以执行这个指令);在进一步的动作之前,处理器处于繁忙的等待中,直到该操作已经完成。

中断驱动I/O:当处理器正在执行程序并遇到与I/O相关的指令时,它给相应的I/O模块发布命令,并继续执行后续指令,直到后者完成,它将被I/O 模块中断。

操作系统精髓与设计原理第五版 课后题答案

操作系统精髓与设计原理第五版 课后题答案

操作系统精髓与设计原理第五版课后题答案C HAPTER 2O PERATING S YSTEMO VERVIEWReview Questions2.1 Convenience: An operating system makes a computer more convenientto use. Efficiency: An operating system allows the computer systemresources to be used in an efficient manner. Ability to evolve: Anoperating system should be constructed in such a way as to permit theeffective development, testing, and introduction of new systemfunctions without interfering with service.2.5 The execution context, or process state, is the internal data by which theoperating system is able to supervise and control the process. Thisinternal information is separated from the process, because theoperating system has information not permitted to the process. Thecontext includes all of the information that the operating system needsto manage the process and that the processor needs to execute theprocess properly. The context includes the contents of the variousprocessor registers, such as the program counter and data registers. Italso includes information of use to the operating system, such as thepriority of the process and whether the process is waiting for thecompletion of a particular I/O event.Problems2.1 The answers are the same for (a) and (b). Assume that althoughprocessor operations cannot overlap, I/O operations can.1 Job: TAT = NT Processor utilization = 50%2 Jobs: TAT = NT Processor utilization = 100%4 Jobs: TAT = (2N – 1)NT Processor utilization = 100% 2.4 A system call is used by an application program to invoke a functionprovided by the operating system. Typically, the system call results intransfer to a system program that runs in kernel mode.C HAPTER 3P ROCESS D ESCRIPTION ANDC ONTROLReview Questions3.5 Swapping involves moving part or all of a process from main memoryto disk. When none of the processes in main memory is in the Ready state, the operating system swaps one of the blocked processes out onto disk into a suspend queue, so that another process may be brought into main memory to execute.3.10 The user mode has restrictions on the instructions that can be executedand the memory areas that can be accessed. This is to protect theoperating system from damage or alteration. In kernel mode, theoperating system does not have these restrictions, so that it canperform its tasks.Problems3.1 •Creation and deletion of both user and system processes. Theprocesses in the system can execute concurrently for informationsharing, computation speedup, modularity, and convenience.Concurrent execution requires a mechanism for process creation and deletion. The required resources are given to the process when it iscreated, or allocated to it while it is running. When the processterminates, the OS needs to reclaim any reusable resources.•Suspension and resumpti on of processes. In process scheduling, theOS needs to change the process's state to waiting or ready state when it is waiting for some resources. When the required resources areavailable, OS needs to change its state to running state to resume itsexecution.•Provision of mechanism for process synchronization. Cooperatingprocesses may share data. Concurrent access to shared data mayresult in data inconsistency. OS has to provide mechanisms forprocesses synchronization to ensure the orderly execution ofcooperating processes, so that data consistency is maintained.•Provision of mechanism for process communication. The processesexecuting under the OS may be either independent processes orcooperating processes. Cooperating processes must have the meansto communicate with each other.•Provision of mechanisms for deadlock handling. In amultiprogramming environment, several processes may compete fora finite number of resources. If a deadlock occurs, all waitingprocesses will never change their waiting state to running state again, resources are wasted and jobs will never be completed.3.3Figure 9.3 shows the result for a single blocked queue. The figurereadily generalizes to multiple blocked queues.C HAPTER 4P ROCESS D ESCRIPTION ANDC ONTROLReview Questions4.2 Less state information is involved.4.5 Address space, file resources, execution privileges are examples.4.6 1. Thread switching does not require kernel mode privileges becauseall of the thread management data structures are within the useraddress space of a single process. Therefore, the process does notswitch to the kernel mode to do thread management. This saves theoverhead of two mode switches (user to kernel; kernel back to user). 2.Scheduling can be application specific. One application may benefit most from a simple round-robin scheduling algorithm, while another might benefit from a priority-based scheduling algorithm. Thescheduling algorithm can be tailored to the application withoutdisturbing the underlying OS scheduler. 3. ULTs can run on anyoperating system. No changes are required to the underlying kernel to support ULTs. The threads library is a set of application-level utilities shared by all applications.4.7 1. In a typical operating system, many system calls are blocking. Thus,when a ULT executes a system call, not only is that thread blocked, but also all of the threads within the process are blocked. 2. In a pure ULT strategy, a multithreaded application cannot take advantage ofmultiprocessing. A kernel assigns one process to only one processor ata time. Therefore, only a single thread within a process can execute at atime.Problems4.2Because, with ULTs, the thread structure of a process is not visible to theoperating system, which only schedules on the basis of processes.C HAPTER 5C ONCURRENCY:M UTUALE XCLUSION ANDS YNCHRONIZATIONReview Questions5.1 Communication among processes, sharing of and competing forresources, synchronization of the activities of multiple processes, and allocation of processor time to processes.5.9 A binary semaphore may only take on the values 0 and 1. A generalsemaphore may take on any integer value.Problems5.2 ABCDE; ABDCE; ABDEC; ADBCE; ADBEC; ADEBC;DEABC; DAEBC; DABEC; DABCE5.5Consider the case in which turn equals 0 and P(1) sets blocked[1] totrue and then finds blocked[0] set to false. P(0) will then setblocked[0] to true, find turn = 0, and enter its critical section. P(1) will then assign 1 to turn and will also enter its critical section.C HAPTER 6C ONCURRENCY:D EADLOCK ANDS TARVATIONReview Questions6.2 Mutual exclusion. Only one process may use a resource at a time. Holdand wait. A process may hold allocated resources while awaitingassignment of others. No preemption. No resource can be forciblyremoved from a process holding it.6.3 The above three conditions, plus: Circular wait. A closed chain ofprocesses exists, such that each process holds at least one resourceneeded by the next process in the chain.Problems6.4 a. 0 0 0 00 7 5 06 6 2 22 0 0 20 3 2 0b. to d. Running the banker's algorithm, we see processes can finishin the order p1, p4, p5, p2, p3.e. Change available to (2,0,0,0) and p3's row of "still needs" to (6,5,2,2).Now p1, p4, p5 can finish, but with available now (4,6,9,8) neitherp2 nor p3's "still needs" can be satisfied. So it is not safe to grantp3's request.6.5 1. W = (2 1 0 0)2. Mark P3; W = (2 1 0 0) + (0 1 2 0) = (2 2 2 0)3. Mark P2; W = (2 2 2 0) + (2 0 0 1) = (4 2 2 1)4. Mark P1; no deadlock detectedReview Questions7.1 Relocation, protection, sharing, logical organization, physicalorganization.7.7 A logical address is a reference to a memory location independent ofthe current assignment of data to memory; a translation must be made to a physical address before the memory access can be achieved. A relative address is a particular example of logical address, in which the address is expressed as a location relative to some known point, usually the beginning of the program. A physical address, or absolute address, is an actual location in main memory.Problems7.6 a. The 40 M block fits into the second hole, with a starting address of80M. The 20M block fits into the first hole, with a starting address of 20M. The 10M block is placed at location 120M.40M 40M 60M 40M 40M 40M 30Mb. The three starting addresses are 230M, 20M, and 160M, for the 40M, 20M, and 10M blocks, respectively. 40M 60M 60M 40M 40M 40M 30Mc. The three starting addresses are 80M, 120M, and 160M, for the 40M,20M, and 10M blocks, respectively. C HAPTER 7M EMORY M ANAGEMENT7.12 a. The number of bytes in the logical address space is (216 pages) (210bytes/page) = 226 bytes. Therefore, 26 bits are required for the logical address.b. A frame is the same size as a page, 210 bytes.c. The number of frames in main memory is (232 bytes of mainmemory)/(210 bytes/frame) = 222 frames. So 22 bits is needed tospecify the frame.d. There is one entry for each page in the logical address space.Therefore there are 216 entries.e. In addition to the valid/invalid bit, 22 bits are needed to specify theframe location in main memory, for a total of 23 bits.30M40M40M60M40M40M40Md. The three starting addresses are 80M, 230M, and 360M, for the 40M,20M, and 10M blocks, respectively.C HAPTER 8V IRTUAL M EMORYReview Questions8.1 Simple paging: all the pages of a process must be in main memory forprocess to run, unless overlays are used. Virtual memory paging: not all pages of a process need be in main memory frames for the process to run.; pages may be read in as needed8.2 A phenomenon in virtual memory schemes, in which the processorspends most of its time swapping pieces rather than executinginstructions.Problems8.1 a. Split binary address into virtual page number and offset; use VPNas index into page table; extract page frame number; concatenateoffset to get physical memory addressb. (i) 1052 = 1024 + 28 maps to VPN 1 in PFN 7, (7 ⨯ 1024+28 = 7196)(ii) 2221 = 2 ⨯ 1024 + 173 maps to VPN 2, page fault(iii) 5499 = 5 ⨯ 1024 + 379 maps to VPN 5 in PFN 0, (0 ⨯ 1024+379 =379)8.4 a. PFN 3 since loaded longest ago at time 20b. PFN 1 since referenced longest ago at time 160c. Clear R in PFN 3 (oldest loaded), clear R in PFN 2 (next oldestloaded), victim PFN is 0 since R=0d. Replace the page in PFN 3 since VPN 3 (in PFN 3) is used furthestin the futuree. There are 6 faults, indicated by **4 0 0 0 *2*4 2*1**3 2VPN of pages in memory in LRU order 32143243434242241241243122Review Questions9.1 Long-term scheduling: The decision to add to the pool of processes tobe executed. Medium-term scheduling: The decision to add to thenumber of processes that are partially or fully in main memory.Short-term scheduling: The decision as to which available process willbe executed by the processor9.3 Turnaround time is the total time that a request spends in the system(waiting time plus service time. Response time is the elapsed timebetween the submission of a request until the response begins toappear as output.Problems9.1 Each square represents one time unit; the number in the square refersto the currently-running process.FCFS A A A B B B B B C C D D D D D E E E E E RR, q = 1 A B A B C A B C B D B D E D E D E D E E RR, q = 4 A A A B B B B C C B D D D D E E E E D E SPN A A A C C B B B B B D D D D D E E E E E SRT A A A C C B B B B B D D D D D E E E E E HRRN A A A B B B B B C C D D D D D E E E E E Feedback, q = 1 A B A C B C A B B D B D E D E D E D E EFeedback, q = 2i A B A A C B B C B B D D E D D E E D E EC HAPTER 9U NIPROCESSORS CHEDULINGA B C D ET a0 1 3 9 12T s 3 5 2 5 5 FCFS T f 3 8 10 15 20T r 3.00 7.00 7.00 6.00 8.00 6.20T r/T s 1.00 1.40 3.50 1.20 1.60 1.74 RR qT f 6.00 11.00 8.00 18.00 20.00= 1T r 6.00 10.00 5.00 9.00 8.00 7.60T r/T s 2.00 2.00 2.50 1.80 1.60 1.98RR qT f 3.00 10.00 9.00 19.00 20.00= 4T r 3.00 9.00 6.00 10.00 8.00 7.20T r/T s 1.00 1.80 3.00 2.00 1.60 1.88 SPN T f 3.00 10.00 5.00 15.00 20.00T r 3.00 9.00 2.00 6.00 8.00 5.60T r/T s 1.00 1.80 1.00 1.20 1.60 1.32SRT T f 3.00 10.00 5.00 15.00 20.00T r 3.00 9.00 2.00 6.00 8.00 5.60T r/T s 1.00 1.80 1.00 1.20 1.60 1.32 HRRT f 3.00 8.00 10.00 15.00 20.00NT r 3.00 7.00 7.00 6.00 8.00 6.20T r/T s 1.00 1.40 3.50 1.20 1.60 1.74FB qT f7.00 11.00 6.00 18.00 20.00= 1T r7.00 10.00 3.00 9.00 8.00 7.40T r/T s 2.33 2.00 1.50 1.80 1.60 1.85 FB T f 4.00 10.00 8.00 18.00 20.00q = 2i T r 4.00 9.00 5.00 9.00 8.00 7.00 T r/T s 1.33 1.80 2.50 1.80 1.60 1.819.16 a. Sequence with which processes will get 1 min of processor time:1 2 3 4 5 Elapsed timeA A A A A A A A A A A A A A BBBBBBBBCCDDDDDEEEEEEEEEEE1015192327303336384042434445The turnaround time for each process:A = 45 min,B = 35 min,C = 13 min,D = 26 min,E = 42 minThe average turnaround time is = (45+35+13+26+42) / 5 = 32.2 min b.Priority Job Turnaround Time3 4 6 7 9 BEACD99 + 12 = 2121 + 15 = 3636 + 3 = 3939 + 6 = 45The average turnaround time is: (9+21+36+39+45) / 5 = 30 min c.Job Turnaround TimeA B C D E 1515 + 9 = 24 24 + 3 = 27 27 + 6 = 33 33 + 12 = 45The average turnaround time is: (15+24+27+33+45) / 5 = 28.8 min d.RunningTimeJob Turnaround Time6 9 12 15 DBEA3 + 6 = 99 + 9 = 1818 + 12 = 3030 + 15 = 45The average turnaround time is: (3+9+18+30+45) / 5 = 21 minC HAPTER 10M ULTIPROCESSOR AND R EAL-T IMES CHEDULINGReview Questions10.1 Fine: Parallelism inherent in a single instruction stream. Medium: Parallelprocessing or multitasking within a single application. Coarse:Multiprocessing of concurrent processes in a multiprogrammingenvironment. Very Coarse: Distributed processing across network nodes toform a single computing environment. Independent: Multiple unrelatedprocesses.10.4 A hard real-time task is one that must meet its deadline; otherwise it willcause undesirable damage or a fatal error to the system. A soft real-timetask has an associated deadline that is desirable but not mandatory; it stillmakes sense to schedule and complete the task even if it has passed itsdeadline.Problems10.1 For fixed priority, we do the case in which the priority is A, B, C. Eachsquare represents five time units; the letter in the square refers to thecurrently-running process. The first row is fixed priority; the secondrow is earliest deadline scheduling using completion deadlines.A AB B A AC C A A B B A A C C A AA AB B AC C A C A A B B A A C C C A AFor fixed priority scheduling, process C always misses its deadline.10.4normal executionexecution in critical sectionT 1T 2T 3s locked by T 3s unlockeds locked by T 1Once T 3 enters its critical section, it is assigned a priority higher than T1. When T3 leaves its critical section, it is preempted by T 1.C HAPTER 11I/O M ANAGEMENT AND D ISK S CHEDULING Review Questions11.1 Programmed I/O: The processor issues an I/O command, on behalf of aprocess, to an I/O module; that process then busy-waits for theoperation to be completed before proceeding. Interrupt-driven I/O:The processor issues an I/O command on behalf of a process,continues to execute subsequent instructions, and is interrupted by the I/O module when the latter has completed its work. The subsequent instructions may be in the same process, if it is not necessary for that process to wait for the completion of the I/O. Otherwise, the process is suspended pending the interrupt and other work is performed. Direct memory access (DMA): A DMA module controls the exchange of data between main memory and an I/O module. The processor sends arequest for the transfer of a block of data to the DMA module and is interrupted only after the entire block has been transferred.11.5 Seek time, rotational delay, access time.Problems11.1 If the calculation time exactly equals the I/O time (which is the mostfavorable situation), both the processor and the peripheral devicerunning simultaneously will take half as long as if they ran separately.Formally, let C be the calculation time for the entire program and let T be the total I/O time required. Then the best possible running timewith buffering is max(C, T), while the running time without buffering is C + T; and of course ((C + T)/2) ≤ max(C, T) ≤ (C + T). Source:[KNUT97].11.3 Disk head is initially moving in the direction of decreasing tracknumber:FIFO SSTF SCAN C-SCANNext track accessed Numberof trackstraversedNexttrackaccessedNumberof trackstraversedNexttrackaccessedNumberof trackstraversedNexttrackaccessedNumberof trackstraversed27 73 110 10 64 36 64 36129 102 120 10 41 23 41 23 110 19 129 9 27 14 27 14 186 76 147 18 10 17 10 17 147 39 186 39 110 100 186 17641 106 64 122 120 10 147 3910 31 41 23 129 9 129 1864 54 27 14 147 18 120 9120 56 10 17 186 39 110 10 Average 61.8 Average 29.1 Average 29.6 Average 38If the disk head is initially moving in the direction of increasing tracknumber, only the SCAN and C-SCAN results change:SCAN C-SCANNext track accessed Numberof trackstraversedNexttrackaccessedNumberof trackstraversed110 10 110 10120 10 120 10129 9 129 9147 18 147 18186 39 186 3964 122 10 17641 23 27 1727 14 41 1410 17 64 23 Average 29.1 Average 35.1Review Questions12.1 A field is the basic element of data containing a single value. A recordis a collection of related fields that can be treated as a unit by some application program.12.5 Pile: Data are collected in the order in which they arrive. Each recordconsists of one burst of data. Sequential file: A fixed format is used for records. All records are of the same length, consisting of the same number of fixed-length fields in a particular order. Because the length and position of each field is known, only the values of fields need to be stored; the field name and length for each field are attributes of the file structure. Indexed sequential file: The indexed sequential file maintains the key characteristic of the sequential file: records are organized in sequence based on a key field. Two features are added; an index to the file to support random access, and an overflow file. The index provides a lookup capability to reach quickly the vicinity of a desired record. The overflow file is similar to the log file used with a sequential file, but is integrated so that records in the overflow file are located by following a pointer from their predecessor record. Indexed file: Records are accessed only through their indexes. The result is that there is now no restriction on the placement of records as long as a pointer in at least one index refers to that record. Furthermore,variable-length records can be employed. Direct, or hashed, file: The direct file makes use of hashing on the key value.Problems12.1 Fixed blocking: F = largest integer B RWhen records of variable length are packed into blocks, data formarking the record boundaries within the block has to be added to separate the records. When spanned records bridge block boundaries, some reference to the successor block is also needed. One possibility is a length indicator preceding each record. Another possibility is a special separator marker between records. In any case, we can assume that each record requires a marker, and we assume that the size of a marker is about equal to the size of a block pointer [WEID87]. For spanned blocking, a block pointer of size P to its successor block may C HAPTER 12F ILE M ANAGEMENTbe included in each block, so that the pieces of a spanned record can easily be retrieved. Then we haveVariable-length spanned blocking: F=B-P R+PWith unspanned variable-length blocking, an average of R/2 will be wasted because of the fitting problem, but no successor pointer is required:Variable-length unspanned blocking: F=B-R2 R+P12.3 a. Indexedb. Indexed sequentialc. Hashed or indexed。

操作系统课后习题答案6 内存管理

操作系统课后习题答案6 内存管理

习题 6 内存管理一、选择题题号1 2 3 4 5 6 7 8 9 10答案B A D B A B A B C B题号11 12 13 14 15答案B A A C C二、综合题4、答:操作系统中的存储管理主要指内存管理。

内存又称主存,它是计算机系统中仅次于CPU 的另一个宝贵资源。

内存的主要职责是存放程序、数据以及操作结果,任何程序只有装入内存后才能被处理机执行,管理好内存是操作系统的重要任务之一。

2、答:(1)内存分配和回收:记录内存的使用情况,为每道程序分配内存空间,回收系统或用户程序释放的内存空间。

(2)内存保护:确保每道用户程序都只在自己的内存空间内运行,彼此互不干扰。

(3)地址变换:将地址空间中的逻辑地址转换为内存空间中与之对应的物理地址。

(4)内存扩充:借助于虚拟存储技术来扩大物理内存的容量,使用户所感觉到的内存容量比实际内存容量大得多。

3、答:当一个程序的相对地址装入到与其逻辑地址空间不一致的绝对地址空间中时,为了保证程序的正确运行,必须把指令和数据的逻辑地址转换为物理地址,这项工作称为地址重定位。

①静态地址重定位在程序装入时由程序装入程序(装配程序)实现地址转换,将程序中的所有逻辑地址都加上目标代码在主存内的起始地址。

这种方式要求地址变换在程序执行前一次性完成。

②动态地址重定位。

程序执行过程中,CPU 在执行指令时实现地址转换。

在多道程序系统中,内存空间常常被多个进程共享,程序员事先不可能知道程序执行时在内存中的物理位置,且必须允许进程在执行期间因对换或空闲区拼接而移动,这都需程序的动态重定位。

动态重定位通常利用基址寄存器的内容加上变址寄存器中的内容计算出指令的物理地址,它需要借助一定的硬件地址转换机构才能实现。

4、答:当某一个进程执行完成并释放所占分区时,系统应进行回收,此时会出现以下4 种情况。

①若回收区只与上空闲区相邻接,即其低地址部分邻接一空闲区。

此时将回收区与上空闲区合并,不必为回收区分配新表项,只需修改上空闲区的大小为二者之和即可。

操作系统教程第5版部分习题答案

操作系统教程第5版部分习题答案

操作系统教程第 5 版部分习题答案第一章:一、3、10、15、23、27、353. 什么是操作系统?操作系统在计算机系统中的主要作用是什么?操作系统是管理系统资源、控制程序执行、改善人机界面、提供各种服务,并合理组织计算机工作流程和为用户有效地使用计算机提供良好运行环境的一种系统软件.主要作用(1)服务用户—操作系统作为用户接口和公共服务程序(2)进程交互—操作系统作为进程执行的控制者和协调者(3)系统实现—操作系统作为扩展机或虚拟机(4)资源管理—操作系统作为资源的管理者和控制者10. 试述系统调用与函数(过程)调用之间的区别。

1)调用形式和实现方式不同;操作系统教程第 5 版部分习题答案(2)被调用的代码位置不同;(3)提供方式不同15. 什么是多道程序设计?多道程序设计有什么特点?多道程序设计是指允许多个作业 (程序)同时进入计算机系统内存并执行交替计算的方法。

从宏观上看是并行的,从微观上看是串行的。

(1)可以提高CPU内存和设备的利用率;( 2) 可以提高系统的吞吐率,使单位时间内完成的作业数目增加;( 3) 可以充分发挥系统的并行性,使设备和设备之间,设备和CPU 之间均可并行工作。

23. 现代操作系统具有哪些基本功能?请简单叙述之。

( 1 )处理器管理;( 2)存储管理;( 3)设备管理;操作系统教程第 5 版部分习题答案(4)文件管理;(5)联网与通信管理。

27. 什么是操作系统的内核?内核是一组程序模块,作为可信软件来提供支持进程并发执行的基本功能和基本操作,通常驻留在内核空间,运行于内核态,具有直接访问计算机系统硬件设备和所有内存空间的权限,是仅有的能够执行特权指令的程序。

35. 简述操作系统资源管理的资源复用技术。

系统中相应地有多个进程竞争使用资源,由于计算机系统的物理资源是xx 和稀有的,操作系统让众多进程共享物理资源,这种共享称为资源复用。

(1)时分复用共享资源从时间上分割成更小的单位供进程使用;(2)空分复用共享资源从空间上分割成更小的单位供进程使用。

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

第7章内存管理复习题:7.1.内存管理需要满足哪些需求?答:重定位、保护、共享、逻辑组织和物理组织。

7.2.为什么需要重定位进程的能力?答:通常情况下,并不能事先知道在某个程序执行期间会有哪个程序驻留在主存中。

此外还希望通过提供一个巨大的就绪进程池,能够把活动进程换入和换出主存,以便使处理器的利用率最大化。

在这两种情况下,进程在主存中的确切位置是不可预知的。

7.3.为什么不可能在编译时实施内存保护?答:由于程序在主存中的位置是不可预测的,因而在编译时不可能检查绝对地址来确保保护。

并且,大多数程序设计语言允许在运行时进行地址的动态计算(例如,通过计算数组下标或数据结构中的指针)。

因此,必须在运行时检查进程产生的所有存储器访问,以便确保它们只访问了分配给该进程的存储空间。

7.4.允许两个或多个进程访问进程的某一特定区域的原因是什么?答:如果许多进程正在执行同一程序,则允许每个进程访问该程序的同一个副本要比让每个进程有自己单独的副本更有优势。

同样,合作完成同一任务的进程可能需要共享访问同一个数据结构。

7.5.在固定分区方案中,使用大小不等的分区有什么好处?答:通过使用大小不等的固定分区:1.可以在提供很多分区的同时提供一到两个非常大的分区。

大的分区允许将很大的进程全部载入主存中。

2.由于小的进程可以被放入小的分区中,从而减少了内部碎片。

7.6.内部碎片和外部碎片有什么区别?答:内部碎片是指由于被装入的数据块小于分区大小而导致的分区内部所浪费的空间。

外部碎片是与动态分区相关的一种现象,它是指在所有分区外的存储空间会变成越来越多的碎片的。

7.7.逻辑地址、相对地址和物理地址间有什么区别?答:逻辑地址是指与当前数据在内存中的物理分配地址无关的访问地址,在执行对内存的访问之前必须把它转化成物理地址。

相对地址是逻辑地址的一个特例,是相对于某些已知点(通常是程序的开始处)的存储单元。

物理地址或绝对地址是数据在主存中的实际位置。

7.8.页和帧之间有什么区别?答:在分页系统中,进程和磁盘上存储的数据被分成大小固定相等的小块,叫做页。

而主存被分成了同样大小的小块,叫做帧。

一页恰好可以被装入一帧中。

7.9.页和段之间有什么区别?答:分段是细分用户程序的另一种可选方案。

采用分段技术,程序和相关的数据被划分成一组段。

尽管有一个最大段长度,但并不需要所有的程序的所有段的长度都相等。

习题:7.1. 2.3节中列出了内存管理的5个目标,7.1节中列出了5中需求。

请说明它们是一致的。

答: 重定位≈支持模块化程序设计;保护≈保护和访问控制以及进程隔离;共享≈保护和访问控制;逻辑组织≈支持模块化程序设计;物理组织≈长期存储及自动分配和管理.7.2.考虑使用大小相等分区的固定分区方案。

分区大小为2e16字节,贮存的大小为2e24字节。

使用一个进程表来包含每一个进程对应的分区。

这个指针需要多少位?答:分区的数量等于主存的字节数除以每个分区的字节数:224/216 = 28. 需要8个比特来确定一个分区大小为28中的某一个位置。

7.3.考虑动态分区方案,说明平均内存中空洞的数量是段数量的一半。

答: 设n和h为断数量和空洞数量的个数.在主存中,每划分一个断产生一个空洞的概率是0.5,因为删除一个断和添加一个断的概率是一样的.假设s是内存中断的个数那么空洞的平均个数一定等于s/2.而导致空洞的个数一定小余断的数量的直接原因是相邻的两个断在删除是一定会产生一个空洞.7.4.在实现动态分区中的各种放置算法(见7.2节),内存中必须保留一个空闲块列表。

分别讨论最佳适配、首次适配、临近适配三种方法的平均查找长度。

答:通过上题我们知道,假设s是驻留段的个数,那么空洞的平均个数是s/2。

从平均意义上讲,平均查找长度是s/4。

7.5.动态分区的另一种放置算法是最坏适配,在这种情况下,当调入一个进程时,使用最大的空闲存储块。

该方法与最佳适配、首次适配、邻近适配相比,优点和缺点各是什么?它的平均查找长度是多少?答:一种对最佳适配算法的评价即是为固定分配一个组块后和剩余空间是如此小以至于实际上已经没有什么用处。

最坏适配算法最大化了在一次分配之后,剩余空间的大小仍足够满足另一需求的机率,同时最小化了压缩的概率。

这种方法的缺点是最大存储块最早被分配,因此大空间的要求可能无法满足。

7.6.如果使用动态分区方案,下图所示为在某个给定的时间点的内存配置:阴影部分为已经被分配的块;空白部分为空闲块。

接下来的三个内存需求分别为40MB,20MB和10MB。

分别使用如下几种放置算法,指出给这三个需求分配的块的起始地址。

a.首次适配b.最佳适配c.临近适配(假设最近添加的块位于内存的开始)d.最坏适配答:a.40M的块放入第2个洞中,起始地址是80M. 20M的块放入第一个洞中.起始地址是20M. 10M的块的起始地址是120M。

b.40M,20N,10M的起始地址分别为230M,20M和160M.c.40M,20M,10M的起始地址是80M,120160M.d.40M,20M,10M,的起始地址是80M,230M,360M.7.7.使用伙伴系统分配一个1MB的存储块。

a.利用类似于图7.6的图来说明按下列顺序请求和返回的结果:请求70;请求35;请求80;返回A;请求60;返回B;返回D;返回C。

b.给出返回B之后的二叉树表示。

答:7.8.考虑一个伙伴系统,在当前分配下的一个特定块地址为0.a.如果块大小为4,它的伙伴的二进制地址为多少?b.如果块大小为16,它的伙伴的二进制地址为多少?答:a.0b.07.9.令buddy k(x)为大小为2k、地址为x的块的伙伴的地址,写出buddy k(x)的通用表达式。

答:7.10.Fabonacci序列定义如下:F0=0,F1=1,F n+2=F n+1+F n,n≧0a.这个序列可以用于建立伙伴系统吗?b.该伙伴系统与本章介绍的二叉伙伴系统相比,有什么优点?答:a.是。

字区大小可以确定Fn = Fn-1 + Fn-2.。

b.这种策略能够比二叉伙伴系统提供更多不同大小的块,因而具有减少内部碎片的可能性。

但由于创建了许多没用的小块,会造成更多的外部碎片。

7.11.在程序执行期间,每次取指令后处理器把指令寄存器的内容(程序计数器)增加一个字,但如果遇到会导致在程序中其他地址继续执行的转跳或调用指令,处理器将修改这个寄存器的内容。

现在考虑图7.8。

关于指令地址有两种选择:●在指令寄存器中保存相对地址,并把指令寄存器作为输入进行动态地址转换。

当遇到一次成功的转跳或调用时,由这个转跳或调用产生的相对地址被装入到指令寄存器中。

●在指令寄存器中保存绝对地址。

当遇到一次成功的转跳或调用时,采用动态地址转换,其结果保存到指令寄存器中。

哪种方法更好?答:使用绝对地址可以减少动态地址转换的次数。

但是,我们希望程序能够被重定位。

因此,在指令寄存器中保存相对地址似乎就更好一些。

也可以选择在进程被换出主存时将指令寄存器中的地址转换为相对地址。

7.12.考虑一个简单分页系统,其物理存储器大小为232字节,页大小为210字节,逻辑地址空间为216个页。

a.逻辑地址空间包含多少位?b.一个帧中包含多少字节?c.在物理地址中指定帧需要多少位?d.在页表中包含多少个页表项?e.在每个页表项中包含多少位?(假设每个页表项中包含一个有效/无效位)答:a.物理地址空间的比特数是216*210=226b.一个帧包含的字节跟一个页是一样的,210比特.c.主存中帧的数量是232/210=222,所以每个帧的定位要22个比特d.在物理地址空间,每个页都有一个页表项,所以有216项e.加上有效/无效位,每个页表项包含23位。

7.13.分页系统中的虚地址a相当于一对(p,w),其中p是页号,w是页中的字节号。

令z是一页中的字节总数,请给出p和w关于z和a的函数。

答:关系是:a = pz + w,其中p = ∟a/z, a/z的整数部分。

w = Rz(a) ,a除以z的余数7.14.起始地址长度(字节)660 2481752 442222 198996 604a.0,198b.2,256c.1,530d.3,444e.0,222答:a.段0定位在660,所以我们有物理地址660+190=858.b. 222+156=378c.段1长度为422,所以会发生错误d.996+444=1440e.660+222=882.7.15.在内存中,存在连续的段S1,S2,…,S n按其创建顺序一次从一端放置到另一端,如下图所示:当段S n+1被创建时,尽管S1,S2,…,S n中的某些段可能已经被删除,段S n+1仍被立即放置在段S n之后。

当段(正在使用或已被删除)和洞之间的边界到达内存的另一端时,压缩正在使用的段。

a.说明花费在压缩上的时间F遵循以下的不等式:F≧(1-f)/1+kf), k=t/2s-1其中,s表示段的平均长度(以字为单位);l标识段的平均生命周期,按存储器访问;f表示在平衡条件下,未使用的内存部分。

提示:计算边界在内存中移动的平均速度,并假设复制一个字至少需要两次存储器访问。

b.当f=0.2,t=1000,s=50时,计算F。

答:a.很明显,在一个周期t内一些段会产生而一些段会被删除.因为系统是公平的,一个新的段会在t内被插入,此外,边界会医s/t的速度移动.假设t0是边界到达空洞的时间,t0=fmr/s, m=内存的长度,在对段进行压缩时会有(1-f)m个数被移动,压缩时间至少是2(1-f)m.则花在压缩上的时间F为F=1-t0/(t0+t c)。

b.K=(t/2s)-1=9;F≧(1-0.2)/(1+1.8)=0.29。

相关文档
最新文档