操作系统课后练习答案解析
操作系统课后答案详解
![操作系统课后答案详解](https://img.taocdn.com/s3/m/060b2588caaedd3382c4d37d.png)
第一章操作系统引论思考与练习题1.什么是操作系统?它的主要功能是什么?2.什么是多道程序设计技术?多道程序设计技术的主要特点是什么?3.批处理系统是怎样的一种操作系统?它的特点是什么?4.什么是分时系统?什么是实时系统?试从交互性,及时性,独立性,多路性,可靠性等几个方面比较分时系统和实施系统。
5.实时系统分为哪俩种类型?6.操作系统主要特征是什么?7.操作系统也用户的接口有几种?它们各自用在什么场合?8.“操作系统是控制硬件的软件”这一说法确切吗?为什么?9.设内存中有三道程序,A,B,C,它们按A~B~C的先后顺序执行,它们进行“计算”和“I/o操作”的时间如表1-2所示,假设三道程序使用相同的I/O设备。
(1)试画出单道运行时三道程序的时间关系图,并计算完成三道程序要花多少时间。
(2)试画出多道运行时三道程序的时间关系图,并计算完成三道程序要花多少时间。
10.将下列左右两列词连接起来形成意义最恰当的5对。
DOS 网络操作系统OS/2 自由软件UNIX 多任务Linux 单任务Windows NT 为开发操作系统而设计 C语言11.选择一个现代操作系统,查找和阅读相关的技术资料,写一篇关于操作系统如何进行内存管理、存储管理、设备管理和文件管理的文章。
答案1.答:操作系统是控制和管理计算机的软、硬件资源,合理地组织计算机的工作流程,以方便用户使用的程序集合。
2.答:把多个独立的程序同时放入内存,使她们共享系统中的资源。
1)多道,即计算机内存中同时放多道相互独立的程序。
2)宏观上并行,是指共识进入系统的多道程序都处于运行过程。
3)微观上串行,是指在单道处理机环境下,内存中的多道程序轮流地占有CPU,交替执行。
3.答:批处理操作系统是一种基本的操作系统类型。
在该系统中用户的作业被成批地输入到计算机中,然后在操作系统的控制下,用户的作业自动的执行。
特点是:资源利用率高。
系统吞吐量大。
平均周转时间长。
(完整版)操作系统课后题答案
![(完整版)操作系统课后题答案](https://img.taocdn.com/s3/m/31027340240c844769eaeefe.png)
2.OS的作用可表现在哪几个方面?答:(1)OS作为用户与计算机硬件系统之间的接口;(2)OS作为计算机系统资源的管理者;(3)OS实现了对计算机资源的抽象。
5.何谓脱机I/O和联机I/O?答:脱机I/O 是指事先将装有用户程序和数据的纸带或卡片装入纸带输入机或卡片机,在外围机的控制下,把纸带或卡片上的数据或程序输入到磁带上。
该方式下的输入输出由外围机控制完成,是在脱离主机的情况下进行的。
而联机I/O方式是指程序和数据的输入输出都是在主机的直接控制下进行的。
11.OS有哪几大特征?其最基本的特征是什么?答:并发性、共享性、虚拟性和异步性四个基本特征;最基本的特征是并发性。
20.试描述什么是微内核OS。
答:(1)足够小的内核;(2)基于客户/服务器模式;(3)应用机制与策略分离原理;(4)采用面向对象技术。
25.何谓微内核技术?在微内核中通常提供了哪些功能?答:把操作系统中更多的成分和功能放到更高的层次(即用户模式)中去运行,而留下一个尽量小的内核,用它来完成操作系统最基本的核心功能,称这种技术为微内核技术。
在微内核中通常提供了进程(线程)管理、低级存储器管理、中断和陷入处理等功能。
第二章进程管理2. 画出下面四条语句的前趋图:S1=a:=x+y; S2=b:=z+1; S3=c:=a – b;S4=w:=c+1;答:其前趋图为:7.试说明PCB 的作用,为什么说PCB 是进程存在的惟一标志?答:PCB 是进程实体的一部分,是操作系统中最重要的记录型数据结构。
作用是使一个在多道程序环境下不能独立运行的程序,成为一个能独立运行的基本单位,成为能与其它进程并发执行的进程。
OS是根据PCB对并发执行的进程进行控制和管理的。
11.试说明进程在三个基本状态之间转换的典型原因。
答:(1)就绪状态→执行状态:进程分配到CPU资源;(2)执行状态→就绪状态:时间片用完;(3)执行状态→阻塞状态:I/O请求;(4)阻塞状态→就绪状态:I/O完成.19.为什么要在OS 中引入线程?答:在操作系统中引入线程,则是为了减少程序在并发执行时所付出的时空开销,使OS具有更好的并发性,提高CPU的利用率。
操作系统第五版费祥林-课后习题答案参考
![操作系统第五版费祥林-课后习题答案参考](https://img.taocdn.com/s3/m/9a1cf363302b3169a45177232f60ddccdb38e656.png)
操作系统第五版费祥林-课后习题答案参考1. 习题一a) 内容描述:- 系统调用是操作系统提供给用户程序的一组接口,用于访问操作系统的功能和服务。
- 系统调用是以进程的方式运行的,通过软中断或硬中断触发,并返回一个状态值,表示系统调用的执行结果。
b) 答案:系统调用的主要目的是提供一种安全的方式,让用户程序能够访问操作系统的特权功能。
通过系统调用,用户程序可以进行文件操作、网络通信、进程管理等功能。
2. 习题二a) 内容描述:- 进程是计算机中正在运行的程序的实例。
- 进程由程序代码、相关数据和执行上下文组成。
- 进程拥有自己的虚拟内存空间、寄存器状态和资源。
- 进程可以通过操作系统的调度机制进行切换和调度。
b) 答案:进程的主要特征包括并发性、独立性和随机性。
并发性指的是多个进程可以同时存在和执行;独立性指的是进程拥有独立的资源和执行上下文;随机性指的是进程的执行顺序和时间不确定。
3. 习题三a) 内容描述:- 死锁是指两个或多个进程因为竞争有限的资源而无法继续执行的状态。
- 死锁发生的原因包括互斥、占有且等待、不可抢占和循环等待。
b) 答案:死锁的预防和避免是操作系统中重要的问题。
预防死锁的方法包括破坏死锁产生的条件,如破坏互斥条件、破坏占有且等待条件等;避免死锁的方法包括资源分配图和银行家算法。
4. 习题四a) 内容描述:- 页面置换算法是操作系统中用于管理虚拟内存的重要手段。
- 页面置换算法的目标是在有限的物理内存空间中有效地管理大量的进程和页面。
- 常见的页面置换算法有FIFO、LRU和LFU等。
b) 答案:页面置换算法的选择依赖于系统的具体需求和资源限制。
FIFO算法是最简单的页面置换算法,它总是选择最先进入内存的页面进行置换;LRU算法则是根据页面最近被访问的频率进行置换;LFU算法是根据页面被访问的次数进行置换。
5. 习题五a) 内容描述:- 文件系统是操作系统中负责管理文件和目录的一组服务和数据结构。
计算机操作系统(第3版)课后习题答案(完整版)【精选文档】
![计算机操作系统(第3版)课后习题答案(完整版)【精选文档】](https://img.taocdn.com/s3/m/d0b549134afe04a1b171defc.png)
第一章1.设计现代OS的主要目标是什么?答:(1)有效性(2)方便性(3)可扩充性(4)开放性2.OS的作用可表现在哪几个方面?答:(1)OS作为用户与计算机硬件系统之间的接口(2)OS作为计算机系统资源的管理者(3)OS实现了对计算机资源的抽象3.为什么说OS实现了对计算机资源的抽象?答:OS首先在裸机上覆盖一层I/O设备管理软件,实现了对计算机硬件操作的第一层次抽象;在第一层软件上再覆盖文件管理软件,实现了对硬件资源操作的第二层次抽象。
OS 通过在计算机硬件上安装多层系统软件,增强了系统功能,隐藏了对硬件操作的细节,由它们共同实现了对计算机资源的抽象。
4.试说明推动多道批处理系统形成和发展的主要动力是什么?答:主要动力来源于四个方面的社会需求与技术发展:(1)不断提高计算机资源的利用率;(2)方便用户;(3)器件的不断更新换代;(4)计算机体系结构的不断发展。
5.何谓脱机I/O和联机I/O?答:脱机I/O 是指事先将装有用户程序和数据的纸带或卡片装入纸带输入机或卡片机,在外围机的控制下,把纸带或卡片上的数据或程序输入到磁带上。
该方式下的输入输出由外围机控制完成,是在脱离主机的情况下进行的。
而联机I/O方式是指程序和数据的输入输出都是在主机的直接控制下进行的。
6.试说明推动分时系统形成和发展的主要动力是什么?答:推动分时系统形成和发展的主要动力是更好地满足用户的需要。
主要表现在:CPU 的分时使用缩短了作业的平均周转时间;人机交互能力使用户能直接控制自己的作业;主机的共享使多用户能同时使用同一台计算机,独立地处理自己的作业.7.实现分时系统的关键问题是什么?应如何解决?答:关键问题是当用户在自己的终端上键入命令时,系统应能及时接收并及时处理该命令,在用户能接受的时延内将结果返回给用户.解决方法:针对及时接收问题,可以在系统中设置多路卡,使主机能同时接收用户从各个终端上输入的数据;为每个终端配置缓冲区,暂存用户键入的命令或数据。
(完整版)操作系统第五版费祥林_课后习题答案解析参考
![(完整版)操作系统第五版费祥林_课后习题答案解析参考](https://img.taocdn.com/s3/m/c8c230cda8956bec0975e3ce.png)
第一章操作系统概论1、有一台计算机,具有IMB 内存,操作系统占用200KB ,每个用户进程各占200KB 。
如果用户进程等待I/O 的时间为80 % ,若增加1MB 内存,则CPU 的利用率提高多少?答:设每个进程等待I/O 的百分比为P ,则n 个进程同时等待刀O 的概率是Pn ,当n 个进程同时等待I/O 期间CPU 是空闲的,故CPU 的利用率为1-Pn。
由题意可知,除去操作系统,内存还能容纳4 个用户进程,由于每个用户进程等待I/O的时间为80 % , 故:CPU利用率=l-(80%)4 = 0.59若再增加1MB 内存,系统中可同时运行9 个用户进程,此时:cPu 利用率=l-(1-80%)9 = 0.87故增加IMB 内存使CPU 的利用率提高了47 % :87 %/59 %=147 %147 %-100 % = 47 %2 一个计算机系统,有一台输入机和一台打印机,现有两道程序投入运行,且程序A 先开始做,程序B 后开始运行。
程序A 的运行轨迹为:计算50ms 、打印100ms 、再计算50ms 、打印100ms ,结束。
程序B 的运行轨迹为:计算50ms 、输入80ms 、再计算100ms ,结束。
试说明(1 )两道程序运行时,CPU有无空闲等待?若有,在哪段时间内等待?为什么会等待?( 2 )程序A 、B 有无等待CPU 的情况?若有,指出发生等待的时刻。
答:画出两道程序并发执行图如下:(1)两道程序运行期间,CPU存在空闲等待,时间为100 至150ms 之间(见图中有色部分)(2)程序A 无等待现象,但程序B 有等待。
程序B 有等待时间段为180rns 至200ms 间(见图中有色部分)3 设有三道程序,按A 、B 、C优先次序运行,其内部计算和UO操作时间由图给出。
试画出按多道运行的时间关系图(忽略调度执行时间)。
完成三道程序共花多少时间?比单道运行节省了多少时间?若处理器调度程序每次进行程序转换化时lms , 试画出各程序状态转换的时间关系图。
操作系统第二版课后习题答案
![操作系统第二版课后习题答案](https://img.taocdn.com/s3/m/f69d6e506fdb6f1aff00bed5b9f3f90f76c64da0.png)
操作系统第二版课后习题答案操作系统第二版课后习题答案操作系统是计算机科学中的重要领域,它负责管理计算机硬件和软件资源,为用户提供良好的使用体验。
在学习操作系统的过程中,课后习题是巩固和深化知识的重要方式。
本文将为大家提供操作系统第二版课后习题的答案,帮助读者更好地理解和掌握操作系统的知识。
第一章:引论1. 操作系统的主要功能包括进程管理、内存管理、文件系统管理和设备管理。
2. 进程是指正在执行的程序的实例。
进程控制块(PCB)是操作系统用来管理进程的数据结构,包含进程的状态、程序计数器、寄存器等信息。
3. 多道程序设计是指在内存中同时存放多个程序,通过时间片轮转等调度算法,使得多个程序交替执行。
4. 异步输入输出是指程序执行期间,可以进行输入输出操作,而不需要等待输入输出完成。
第二章:进程管理1. 进程调度的目标包括提高系统吞吐量、减少响应时间、提高公平性等。
2. 进程调度算法包括先来先服务(FCFS)、最短作业优先(SJF)、优先级调度、时间片轮转等。
3. 饥饿是指某个进程长时间得不到执行的情况,可以通过调整优先级或引入抢占机制来解决。
4. 死锁是指多个进程因为争夺资源而陷入无限等待的状态,可以通过资源预分配、避免环路等方式来避免死锁。
第三章:内存管理1. 内存管理的主要任务包括内存分配、内存保护、地址转换等。
2. 连续内存分配包括固定分区分配、可变分区分配和动态分区分配。
3. 分页和分段是常见的非连续内存分配方式,分页将进程的地址空间划分为固定大小的页,分段将进程的地址空间划分为逻辑段。
4. 页面置换算法包括最佳置换算法、先进先出(FIFO)算法、最近最久未使用(LRU)算法等。
第四章:文件系统管理1. 文件是操作系统中用来存储和组织数据的逻辑单位,可以是文本文件、图像文件、音频文件等。
2. 文件系统的主要功能包括文件的创建、删除、读取、写入等操作。
3. 文件系统的组织方式包括层次目录结构、索引结构、位图结构等。
操作系统教程第五版费翔林课后答案
![操作系统教程第五版费翔林课后答案](https://img.taocdn.com/s3/m/26e246805ebfc77da26925c52cc58bd631869305.png)
操作系统教程第五版费翔林课后答案本文是针对操作系统教程第五版费翔林书籍中的课后题目提供的答案解析。
在这个教程中,费翔林教授详细介绍了操作系统的基本概念、原理和实践,涵盖了进程管理、内存管理、文件系统、设备管理等各个方面。
通过对这些课后题目的解答,可以更好地理解和巩固操作系统的知识。
第一章:引论1.什么是操作系统?它的主要目标是什么?–答案:操作系统是一种控制和管理计算机硬件和软件资源的系统软件。
操作系统的主要目标是为用户提供一个方便、高效、安全的计算机环境。
2.请简要描述操作系统的角色和功能。
–答案:操作系统有几个角色和功能:•资源管理:操作系统管理计算机的各种硬件资源,包括处理器、内存、存储设备和输入输出设备。
•进程管理:操作系统创建、调度和终止进程,以及处理进程间的通信和同步。
•内存管理:操作系统分配和回收内存,管理虚拟内存,以及处理内存的保护和共享机制。
•文件系统:操作系统管理文件和目录的存储和访问,提供文件的创建、读取、写入和删除等操作。
•设备管理:操作系统管理计算机的输入输出设备,包括键盘、鼠标、显示器、打印机等。
•用户接口:操作系统提供了与计算机交互的界面,包括命令行界面和图形用户界面等。
第二章:进程管理1.什么是进程?进程的状态有哪些?–答案:进程是指在计算机中正在运行的程序的实例。
进程的状态包括:•就绪:进程已经准备好执行,但是还没有被分配到处理器。
•运行:进程正在处理器上执行。
•阻塞:进程由于某些原因不能继续执行,需要等待某个事件的发生。
•终止:进程已经完成或被终止,等待被操作系统回收。
2.请简要描述进程的创建、终止和状态切换的过程。
–答案:进程的创建是通过调用系统调用来完成的,系统为新进程分配资源,并设置进程的初始状态。
进程的终止可以是正常终止(调用系统调用进行退出)或异常终止(例如发生错误)。
进程状态之间的切换通过操作系统的调度算法来实现,例如从就绪状态切换到运行状态,或从运行状态切换到阻塞状态。
计算机操作系统课后习题答案第四版
![计算机操作系统课后习题答案第四版](https://img.taocdn.com/s3/m/a3671788b04e852458fb770bf78a6529657d3540.png)
计算机操作系统课后习题答案第四版计算机操作系统课后习题答案(第四版)计算机操作系统是计算机系统中至关重要的组成部分,它负责管理和控制计算机的硬件和软件资源,为用户提供一个方便、高效、可靠的工作环境。
下面是对计算机操作系统第四版课后习题的答案解析。
一、操作系统的概念1、什么是操作系统?它的主要功能有哪些?操作系统是管理计算机硬件与软件资源的程序,是计算机系统的内核与基石。
它的主要功能包括处理机管理、存储器管理、设备管理、文件管理和用户接口管理等。
处理机管理负责合理分配和调度 CPU 资源,提高 CPU 利用率;存储器管理负责管理内存空间的分配、回收和保护;设备管理负责对外部设备进行有效管理和控制;文件管理负责对文件的存储、检索、共享和保护;用户接口管理则为用户提供了方便的操作界面。
2、操作系统有哪些分类?操作系统可以按照不同的标准进行分类。
按照用户数量,可分为单用户操作系统和多用户操作系统;按照任务数,可分为单任务操作系统和多任务操作系统;按照系统功能,可分为批处理操作系统、分时操作系统、实时操作系统、网络操作系统和分布式操作系统等。
1、什么是进程?进程和程序有什么区别?进程是程序在一个数据集合上的一次执行过程,是系统进行资源分配和调度的基本单位。
进程与程序的区别在于:程序是静态的指令集合,而进程是动态的执行过程;程序可以长期保存,进程具有生命周期;进程具有并发性,而程序没有;进程由程序、数据和进程控制块(PCB)组成。
2、进程的三种基本状态是什么?它们之间是如何转换的?进程的三种基本状态是就绪状态、执行状态和阻塞状态。
当进程已获得除CPU 以外的所有必要资源,只要再获得CPU 便可立即执行时,处于就绪状态;当进程正在 CPU 上运行时,处于执行状态;当进程因等待某一事件而暂时无法继续执行时,处于阻塞状态。
就绪状态到执行状态是通过进程调度实现的;执行状态到就绪状态是时间片用完或出现更高优先级的进程;执行状态到阻塞状态是进程因等待某事件而主动放弃 CPU;阻塞状态到就绪状态是等待的事件发生。
操作系统第九版部分课后作业习题答案解析
![操作系统第九版部分课后作业习题答案解析](https://img.taocdn.com/s3/m/5ea1eee387c24028915fc3f8.png)
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.。
操作系统第九版部分课后作业习题答案分析解析
![操作系统第九版部分课后作业习题答案分析解析](https://img.taocdn.com/s3/m/9e18bba451e79b89680226ae.png)
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.。
操作系统(第二版)课后习题答案
![操作系统(第二版)课后习题答案](https://img.taocdn.com/s3/m/c6ec9bffb0717fd5360cdc74.png)
故需要一次间接寻址,就可读出该数据
如果要求读入从文件首到263168Byte处的数据(包括这个数据),读岀过程:首先根据直接寻
址读出前10块;读出一次间接索引指示的索引块1块;将索引下标从0〜247对应的数据块全部 读入。即可。共读盘块数10+1+248=259块
3.某文件系统采用索引文件结构,设文件索引表的每个表目占用3Byte,存放盘块的块号,盘块 的大小为512Byte。此文件系统采用直接、一次间接、二次间接、三次间接索引所能管理的最大
(1)|100-8|+|18-8|+|27-18|+|129-27|+|110-129|+|186-110|+|78-186|+|147-78|+|41-147|+ |10-47|+|64-10|+|12-64|=728
8:00
10:00
120mi n
1
2
8:50
50min
10:00
10:50
120mi n
3
9:00
10mi n
10:50
11:00
120mi n
12
4
9:50
20mi n
11:00
11:20
90mi n
平均周转时间T=,平均带权周转时间W=
②SJF短作业优先法)
作业
到达时间
运行时间
开始时间
完成时间
周转时间
页面长度为4KB,虚地址空间共有土)个页面
3.某计算机系统提供24位虚存空间,主存空间为218Byte,采用请求分页虚拟存储管理,页面尺
寸为1KB。假定应用程序产生虚拟地址(八进制),而此页面分得的块号为100(八进制),说明
(完整版)操作系统教程第5版课后答案解析
![(完整版)操作系统教程第5版课后答案解析](https://img.taocdn.com/s3/m/828e574105087632311212cd.png)
操作系统教程第5版课后答案费祥林、骆斌编著第一章操作系统概论习题一一、思考题1.简述现代计算机系统的组成及层次结构。
答:现代计算机系统由硬件和软件两个部分组成。
是硬件和软件相互交织形成的集合体,构成一个解决计算问题的工具。
硬件层提供基本可计算的资源,包括处理器、寄存器、内存、外存及I/O设备。
软件层由包括系统软件、支撑软件和应用软件。
其中系统软件是最靠近硬件的。
2、计算机系统的资源可分成哪几类?试举例说明。
答:包括两大类,硬件资源和信息资源。
硬件资源分为处理器、I/O设备、存储器等;信息资源分为程序和数据等。
3.什么是操作系统?操作系统在计算机系统中的主要作用是什么?答:操作系统是一组控制和管理计算机硬件和软件资源,合理地对各类作业进行调度,以及方便用户使用的程序的集合。
操作系统在计算机系统中主要起4个方面的作用。
(1)服务用户观点——操作系统提供用户接口和公共服务程序(2)进程交互观点——操作系统是进程执行的控制者和协调者(3)系统实现观点——操作系统作为扩展机或虚拟机(4)资源管理观点——操作系统作为资源的管理者和控制者4.操作系统如何实现计算与操作过程的自动化?答:大致可以把操作系统分为以下几类:批处理操作系统、分时操作系统、实时操作系统、网络操作系统和分布式操作系统。
其中批处理操作系统能按照用户预先规定好的步骤控制作业的执行,实现计算机操作的自动化。
又可分为批处理单道系统和批处理多道系统。
单道系统每次只有一个作业装入计算机系统的主存储器运行,多个作业可自动、顺序地被装入运行。
批处理多道系统则允许多个作业同时装入主存储器,中央处理器轮流地执行各个作业,各个作业可以同时使用各自所需的外围设备,这样可以充分利用计算机系统的资源,缩短作业时间,提高系统的吞吐率5.操作系统要为用户提供哪些基本的和共性的服务?答:(1)创建程序和执行程序;(2)数据I/O和信息存取;(3)通信服务;(4)差错检测和处理。
操作系统课后习题答案
![操作系统课后习题答案](https://img.taocdn.com/s3/m/aaa8c77e0622192e453610661ed9ad51f11d5449.png)
操作系统课后习题答案问题一:简述进程和线程的区别。
进程是操作系统进行资源分配和调度的一个独立单位,它是程序在数据集上的一次动态执行过程。
线程是进程中的一个实体,是CPU调度和分派的基本单位,比进程更小的能独立运行的基本单位。
线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如执行栈),但它可以与同属一个进程的其他线程共享进程所拥有的全部资源。
问题二:什么是死锁?如何避免死锁?死锁是指两个或两个以上的进程在执行过程中,因争夺资源而造成的一种僵局,若无外力作用,这些进程都将无法向前推进。
避免死锁的方法包括:1. 互斥条件:确保系统资源足够,以避免多个进程争夺同一资源。
2. 请求和保持条件:设计资源分配策略,确保进程不会在请求新资源的同时保持已分配的资源。
3. 不剥夺条件:一旦资源被分配给某进程,除非该进程自愿释放资源,否则系统不应强制剥夺。
4. 循环等待条件:通过资源分配图检测循环等待并进行处理。
问题三:描述操作系统中的分页和分段机制。
分页机制是操作系统用来实现虚拟内存的一种技术,它将物理内存分割成固定大小的页,并将这些页与进程的虚拟地址空间中的页表项关联起来。
当进程访问一个不在物理内存中的虚拟地址时,操作系统会触发一个缺页中断,将所需的页从辅助存储器加载到物理内存中。
分段机制则是将程序的地址空间划分为多个段,每个段可以是不同的大小,并且可以独立地被加载和链接。
段表项包含了段的基地址和段的长度信息。
当程序访问一个段内的地址时,操作系统将虚拟地址转换为物理地址。
问题四:什么是文件系统?它有什么作用?文件系统是操作系统用于有效地存储、组织、管理和访问磁盘上的数据的一种系统。
它的作用包括:1. 数据持久性:确保即使在系统崩溃或电源故障后,数据也不会丢失。
2. 数据共享:允许多个用户或进程访问和共享数据。
3. 抽象:为用户和应用程序提供统一的接口来访问存储在磁盘上的数据。
4. 安全性:通过权限控制保护数据不被未授权访问。
操作系统课后习题1-9答案
![操作系统课后习题1-9答案](https://img.taocdn.com/s3/m/ca428b1c77c66137ee06eff9aef8941ea76e4b95.png)
操作系统课后习题1-9答案练习11.1-1.10题解见书1.11 有⼀台输⼊设备和⼀台输出设备的计算机系统上,运⾏有两道程序。
两道程序投⼊运⾏情况如下:程序1先开始运⾏,其运⾏轨迹为:计算50ms、输出100ms、计算50ms、输出100ms,结束;程序2后开始运⾏,其运⾏轨迹为:计算50ms、输⼊100ms、计算100ms、结束。
1. 忽略调度时间,指出两道程序运⾏时,CPU是否有空闲?在哪部分空闲?指出程序1和程序2. 有⽆等待CPU的情况?如果有,发⽣在哪部分?题解:由题画出CPU利⽤图如下:由图可知,1.CPU有空闲,在100ms~150ms时间段是空闲的。
2.程序1⽆等待时间,⽽程序2在⼀开始的0ms~50ms时间段会等待。
1.12 在计算机系统上运⾏三道程序,运⾏次序为程序1、程序2、程序3。
程序3的运⾏轨迹为:计算60ms、输⼊30ms、计算20ms。
忽略调度时间,画出三道程序运⾏的时间关系图;完成三道程序共花多少时间?与单道程序⽐较,节省了多少时间?解答:三道程序运⾏,完成三道程序共花170ms。
与单道程序(260ms)⽐较,节省了90ms。
(始终按照1-2-3的次序,即程序1→程序2→程序3→程序1→程序2→(在程序3运⾏前会停10ms等待输⼊完成)程序3。
(如果不是按照程序1、2、3的次序完成则会有多种情况。
)1.13 在计算机系统上有两台输⼊/输出设备,运⾏两道程序。
程序1的运⾏轨迹为:计算10ms、输⼊5ms、计算5ms、输出10ms、计算10ms。
程序2的运⾏轨迹为:输⼊10ms、计算10ms、输出5ms、计算5ms、输出10ms。
在顺序环境下,先执⾏程序1,再执⾏程序2,求总的CPU利⽤率为多少?题解:由题画出CPU利⽤图如下:由图可知,在总共80ms的时间⾥,CPU空闲时间为40ms,即:CPU利⽤率=40ms/80ms*100%=50%1.14 ⼀个计算机系统有⾜够的内存空间存放3道程序,这些程序有⼀半的时间在空闲等待I/O操作。
操作系统课后习题答案第三版
![操作系统课后习题答案第三版](https://img.taocdn.com/s3/m/d3a0fa08a66e58fafab069dc5022aaea998f413f.png)
一、名词解释1、操作系统:是位于硬件层之上,所有其它软件之下的一个系统软件,是管理系统中的软硬资源,使其得以充分利用并方便用户使用的程序集合。
2、进程:具有一定独立功能的程序关于一个数据集合的一次运行活动。
3、线程:也称轻进程,是进程内的一个相对独立的执行流。
4、设备无关性:用户在使用设备时,选用逻辑设备,而不必面对一种设备一种接口.设备管理实现逻辑设备到物理设备的映射,这就是设备无关性.5、数组多路通道:是指连接多台设备.同时为多台设备服务,每次输入/输出一个数据块.这样的通道叫数组多路通道.6、死锁:一组并发进程,因争夺彼此占用的资源而无法执行下去,这种僵局叫死锁.7、文件系统:是指与文件管理有关的那部分软件,被管理的文件及管理所需的数据结构的总体.8、并发进程:进程是一个程序段在其数据集合上的一次运行过程,而并发进程是可以与其它进程并发运行的.9、临界区:是关于临界资源访问的代码段.10、虚拟存储器:是一种扩大内存容量的设计技术,它把辅助存储器作为计算机内存储器的后援,实际上不存在的扩大的存储器叫虚拟存储器.11、动态重定位:在程序运行时,将逻辑地址映射为物理地址的过程叫动态重定位.12、作业:用户要求计算机系统为其完成的计算任务的集合。
13、中断:在程序运行过程中,出现的某种紧急事件,必须中止当前正在运行的程序,转去处理此事件,然后再恢复原来运行的程序,这个过程称为中断。
14、文件:具有符号名而且在逻辑上具有完整意义的信息项的有序序列。
15、进程互斥:两个或两个以上的进程,不同时进入关于同一组共享变量的临界区域,否则可能发生与时间有关的错误,这种现象叫互斥。
16、系统开销:指运行操作系统程序,对系统进行管理而花费的时间和空间。
操作系统第二版课后习题答案
![操作系统第二版课后习题答案](https://img.taocdn.com/s3/m/eebcef7cc950ad02de80d4d8d15abe23482f0305.png)
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 300⑴cpu有空闲等待,在100ms~150ms的时候.⑵ 程序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);隹票•口xK;P(s2);开车门;上下乘客;))2.设有三个进程P、Q、R共享一个缓冲区,该缓冲区一次只能存放一个数据,P进程负责循环地从磁带机读入数据并放入缓冲区,Q进程负责循环地从缓冲区取出P进程放入的数据进行加工处理,并把结果放入缓冲区,R进程负责循环地从缓冲区读出Q进程放入的数据并在打印机上打印。
请用信号量和P、V操作,写出能够正确执行的程序。
semaphore sp,sq,sr;int buf;sp=1;sq=0;sr=0;cobeginprocess P()(while(true)(从磁带读入数据;P(sp);Buf=data;V(sq);))process Q()(while(true)(P(sq);data=buf;力口工data;buf=data;V(sr);))process R()(while(true)(P(sr);data=buf;V(sp);打印数据;coend.3.简述计数信号量的值与资源使用情况的关系。
(完整版)操作系统课后题答案
![(完整版)操作系统课后题答案](https://img.taocdn.com/s3/m/d627cd8fbed5b9f3f90f1cc9.png)
第一章1.设计现代OS的主要目标是什么?答:(1)有效性(2)方便性(3)可扩充性(4)开放性2.OS的作用可表现在哪几个方面?答:(1)OS作为用户与计算机硬件系统之间的接口(2)OS作为计算机系统资源的管理者(3)OS实现了对计算机资源的抽象3.为什么说OS实现了对计算机资源的抽象?答:OS首先在裸机上覆盖一层I/O设备管理软件,实现了对计算机硬件操作的第一层次抽象;在第一层软件上再覆盖文件管理软件,实现了对硬件资源操作的第二层次抽象。
OS 通过在计算机硬件上安装多层系统软件,增强了系统功能,隐藏了对硬件操作的细节,由它们共同实现了对计算机资源的抽象。
4.试说明推动多道批处理系统形成和发展的主要动力是什么?答:主要动力来源于四个方面的社会需求与技术发展:(1)不断提高计算机资源的利用率;(2)方便用户;(3)器件的不断更新换代;(4)计算机体系结构的不断发展。
5.何谓脱机I/O和联机I/O?答:脱机I/O 是指事先将装有用户程序和数据的纸带或卡片装入纸带输入机或卡片机,在外围机的控制下,把纸带或卡片上的数据或程序输入到磁带上。
该方式下的输入输出由外围机控制完成,是在脱离主机的情况下进行的。
而联机I/O方式是指程序和数据的输入输出都是在主机的直接控制下进行的。
6.试说明推动分时系统形成和发展的主要动力是什么?答:推动分时系统形成和发展的主要动力是更好地满足用户的需要。
主要表现在:CPU 的分时使用缩短了作业的平均周转时间;人机交互能力使用户能直接控制自己的作业;主机的共享使多用户能同时使用同一台计算机,独立地处理自己的作业。
7.实现分时系统的关键问题是什么?应如何解决?答:关键问题是当用户在自己的终端上键入命令时,系统应能及时接收并及时处理该命令,在用户能接受的时延内将结果返回给用户。
解决方法:针对及时接收问题,可以在系统中设置多路卡,使主机能同时接收用户从各个终端上输入的数据;为每个终端配置缓冲区,暂存用户键入的命令或数据。
操作系统课后习题答案
![操作系统课后习题答案](https://img.taocdn.com/s3/m/897db8217275a417866fb84ae45c3b3567ecdd06.png)
操作系统课后习题答案第一章o引论1.设计现代OS的主要目标是什么方便性,有效性,可扩充性和开放性.2.OS的作用可表现为哪几个方面a.OS作为用户与计算机硬件系统之间的接口;b.OS作为计算机系统资源的管理者;c.OS作为扩充机器.4.试说明推动多道批处理系统形成和发展的主要动力是什么不断提高计算机资源利用率和系统吞吐量的需要;5.何谓脱机I/O和联机I/Oa.脱机输入输出方式(Off-LineI/O)是为了解决人机矛盾及CPU和I/O设备之间速度不匹配而提出的.它减少了CPU的空闲等待时间,提高了I/O速度.具体内容是将用户程序和数据在一台外围机的控制下,预先从低速输入设备输入到磁带上,当CPU需要这些程序和数据时,在直接从磁带机高速输入到内存,从而大大加快了程序的输入过程,减少了CPU等待输入的时间,这就是脱机输入技术;当程序运行完毕或告一段落,CPU需要输出时,无需直接把计算结果送至低速输出设备,而是高速把结果输出到磁带上,然后在外围机的控制下,把磁带上的计算结果由相应的输出设备输出,这就是脱机输出技术.b.若这种输入输出操作在主机控制下进行则称之为联机输入输出方式.6.试说明推动分时系统形成和发展的主要动力是什么用户的需要.即对用户来说,更好的满足了人-机交互,共享主机以及便于用户上机的需求.7.实现分时系统的关键问题是什么应如何解决a.关键问题:及时接收,及时处理;b.对于及时接收,只需在系统中设置一多路卡,多路卡作用是使主机能同时接收用户从各个终端上输入的数据;---对于及时处理,应使所有的用户作业都直接进入内存,在不长的时间内,能使每个作业都运行一次.8为什么要引入实时操作系统更好地满足实时控制领域和实时信息处理领域的需要.12试从交互性,及时性和可靠性方面,将分时系统与实时系统进行比较.a.分时系统是一种通用系统,主要用于运行终端用户程序,因而它具有较强的交互能力;而实时系统虽然也有交互能力,但其交互能力不及前者.b.实时信息系统对实用性的要求与分时系统类似,都是以人所能接收的等待时间来确定;而实时控制系统的及时性则是以控制对象所要求的开始截止时间和完成截止时间来确定的.c.实时系统对系统的可靠性要求要比分时系统对系统的可靠性要求高.13OS具有哪几大特征它的最基本特征是什么a.并发(Concurrence),共享(Sharing),虚拟(Virtual),异步性(Aynchronim).b.其中最基本特征是并发和共享.14处理机管理具有哪些功能它们的主要任务是什么a.进程控制,进程同步,进程通信和调度.b.进程控制的主要任务是为作业创建进程,撤销已结束的进程,以及控制进程在运行过程中的状态转换.---进程同步的主要任务是对诸进程的运行进行调节.---进程通信的任务是实现在相互合作进程之间的信息交换.---调度分为作业调度和进程调度.作业调度的基本任务是从后备队列中按照一定的算法,选择出若干个作业,为它们分配必要的资源;而进程调度的任务是从进程的就绪队列中,按照一定的算法选出一新进程,把处理机分配给它,并为它设置运行现场,是进程投入运行.15内存管理有哪些主要功能它们的主要任务是什么a.主要功能:内存分配,内存保护,地址映射和内存扩充等.b.内存分配的主要任务是为每道程序分配内存空间,提高存储器利用率,以减少不可用的内存空间,允许正在运行的程序申请附加的内存空间,以适应程序和数据动态增长的需要.---内存保护的主要任务是确保每道用户程序都在自己的内存空间中运行,互不干扰.---地址映射的主要任务是将地址空间中的逻辑地址转换为内存空间中与之对应的物理地址.---内存扩充的主要任务是借助虚拟存储技术,从逻辑上去扩充内存容量.16设备管理有哪些主要功能其主要任务是什么a.主要功能:缓冲管理,设备分配和设备处理,以及虚拟设备等.b.主要任务:完成用户提出的I/O请求,为用户分配I/O设备;提高CPU和I/O设备的利用率;提高I/O速度;以及方便用户使用I/O设备.17文件管理有哪些主要功能其主要任务是什么a.主要功能:对文件存储空间的管理,目录管理,文件的读,写管理以及文件的共享和保护.b.主要任务:对用户文件和系统文件进行管理,以方便用户使用,并保证文件的安全性.18是什么原因使操作系统具有异步性特征a.程序执行结果是不确定的,即程序是不可再现的.b.每个程序在何时执行,多个程序间的执行顺序以及完成每道程序所需的时间都是不确定的,即不可预知性.第二章2.试画出下面条语句的前趋图:S1:a=5-某;S2:b=a某某;S3:c=4某某;S4:d=b+c;S5:e=d+3.S1->S2->S4->S5......../......S33.程序并发执行为什么会产生间断性因为程序在并发执行过程中存在相互制约性.4.程序并发执行为什么会失去封闭性和可再现性因为程序并发执行时,多个程序共享系统中的各种资源,资源状态需要多个程序来改变,即存在资源共享性使程序失去封闭性;而失去了封闭性导致程序失去可再现性.5.在操作系统中为什么要引入进程概念它会产生什么样的影响为了使程序在多道程序环境下能并发执行,并能对并发执行的程序加以控制和描述,而引入了进程概念.影响:使程序的并发执行得以实行.6.试从动态性,并发性和独立性上比较进程和程序a.动态性是进程最基本的特性,可表现为由创建而产生,由调度而执行,因得不到资源而暂停执行,以及由撤销而消亡,因而进程由一定的生命期;而程序只是一组有序指令的集合,是静态实体.b.并发性是进程的重要特征,同时也是OS的重要特征.引入进程的目的正是为了使其程序能和其它进程的程序并发执行,而程序是不能并发执行的.c.独立性是指进程实体是一个能独立运行的基本单位,同时也是系统中独立获得资源和独立调度的基本单位.而对于未建立任何进程的程序,都不能作为一个独立的单位参加运行.7.试说明PCB的作用为什么说PCB是进程存在的唯一标志a.PCB是进程实体的一部分,是操作系统中最重要的记录型数据结构.PCB中记录了操作系统所需的用于描述进程情况及控制进程运行所需的全部信息.因而它的作用是使一个在多道程序环境下不能独立运行的程序(含数据),成为一个能独立运行的基本单位,一个能和其它进程并发执行的进程.b.在进程的整个生命周期中,系统总是通过其PCB对进程进行控制,系统是根据进程的PCB而不是任何别的什么而感知到该进程的存在的,所以说,PCB是进程存在的唯一标志.8.试说明进程在三个基本状态之间转换的典型原因.a.处于就绪状态的进程,当进程调度程序为之分配了处理机后,该进程便由就绪状态变为执行状态.b.当前进程因发生某事件而无法执行,如访问已被占用的临界资源,就会使进程由执行状态转变为阻塞状态.c.当前进程因时间片用完而被暂停执行,该进程便由执行状态转变为就绪状态.9.为什么要引入挂起状态该状态具有哪些性质a.引入挂起状态处于5中需要:终端用户的需要,父进程的需要,操作系统的需要,对换的需要和负荷调节的需要.b.处于挂起状态的进程不能接收处理机调度.10在进行进程切换时,所要保存的处理机状态信息主要有哪些a.进程当前暂存信息;b.下一条指令地址信息;c.进程状态信息;d.过程和系统调用参数及调用地址信息.11试说明引起进程创建的主要事件.a.用户登陆;b.作业调度;c.提供服务;d.应用请求.12试说明引起进程撤消的主要事件.a.正常结束;b.异常结束;c.外界干预;13在创建一个进程时,需完成的主要工作是什么a.操作系统发现请求创建新进程事件后,调用进程创建原语Creat();b.申请空白PCB;c.为新进程分配资源;d.初始化进程控制块;e.将新进程插入就绪队列.14在撤消一个进程时,需完成的主要工作是什么a.OS调用进程终止原语;b.根据被终止进程的标志符,从PCB集合中检索出该进程的PCB,从中读出该进程的状态;c.若被终止进程正处于执行状态,应立即中止该进程的执行,并设置调度标志为真;d.若该进程还有子孙进程,还应将其所有子孙进程予以终止;e.将该进程所拥有的全部资源,或者归还给其父进程,或者归还给系统;f.将被终止进程(它的PCB)从所在队列(或链表)中移出,等待其它程序来搜集信息.15试说明引起进程阻塞或被唤醒的主要事件是什么a.请求系统服务;b.启动某种操作;c.新数据尚未到达;d.无新工作可做.17.为什么进程在进入临界区之前,应先执行"进入区"代码,在退出临界区后又执行"退出区"代码为了实现多个进程对临界资源的互斥访问,必须在临界区前面增加一段用于检查欲访问的临界资源是否正被访问的代码,如果未被访问,该进程便可进入临界区对资源进行访问,并设置正被访问标志,如果正被访问,则本进程不能进入临界区,实现这一功能的代码成为"进入区"代码;在退出临界区后,必须执行"退出区"代码,用于恢复未被访问标志.18.同步机构应遵循哪些基本准则为什么a.空闲让进.b.忙则等待.c.有限等待.d.让权等待.20.你认为整型信号量机制和记录型信号量机制,是否完全遵循了同步机构的四条准则a.在整型信号量机制中,未遵循"让权等待"的准则.b.记录型信号量机制完全遵循了同步机构的"空闲让进,忙则等待,有限等待,让权等待"四条准则.23.在生产者-消费者问题中,如果缺少了ignal(full)或ignal(empty),对执行结果会有何影响生产者-消费者问题可描述如下: varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat.produceaniteminne某tp;..wait(empty);wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;ignal(mute某);/某某某某某某某某某某某某某某某某/ ignal(full);/某某某某某某某某某某某某某某某某/ untilfale;endconumer:beginrepeatwait(full);wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);/某某某某某某某某某某某某某某某某/ ignal(empty);/某某某某某某某某某某某某某某某某/conumetheiteminne某tc;untilfale;endparendend可见,生产者可以不断地往缓冲池送消息,如果缓冲池满,就会覆盖原有数据,造成数据混乱.而消费者始终因wait(full)操作将消费进程直接送入进程链表进行等待,无法访问缓冲池,造成无限等待.24.在生产者-消费者问题中,如果将两个wait操作即wait(full)和wait(mute某)互换位置;或者是将ignal(mute某)与ignal(full)互换位置结果会如何varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat..produceaniteminne某tp;.wait(empty);wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;/某某某某某某某某某某某某某某某某某某某/ ignal(full);ignal(mute某);/某某某某某某某某某某某某某某某某某某某/ untilfale;endconumer:beginrepeat/某某某某某某某某某某某某某某某某某某/ wait(mute某);wait(full);/某某某某某某某某某某某某某某某某某某/ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);conumetheiteminne某tc;untilfale;endparendendwait(full)和wait(mute某)互换位置后,因为mute某在这儿是全局变量,执行完wait(mute某),则mute某赋值为0,倘若full也为0,则该生产者进程就会转入进程链表进行等待,而生产者进程会因全局变量mute某为0而进行等待,使full始终为0,这样就形成了死锁.而ignal(mute某)与ignal(full)互换位置后,从逻辑上来说应该是一样的.25.我们为某临界区设置一把锁W,当W=1时,表示关锁;W=0时,表示锁已打开.试写出开锁原语和关锁原语,并利用它们去实现互斥.开锁原语:unlock(W):W=0;关锁原语:lock(W);if(W==1)dono_op;W=1;利用开关锁原语实现互斥:varW:emaphore:=0;beginparbeginproce:repeatlock(W);criticalectionunlock(W);remainderectionuntilfale;endparend26.试修改下面生产者-消费者问题解法中的错误: producer:beginrepeat..produceraniteminne某tp;wait(mute某);wait(full);/某应为wait(empty),而且还应该在wait(mute某)的前面某/buffer(in):=ne某tp;/某缓冲池数组游标应前移:in:=(in+1)modn;某/ignal(mute某);/某ignal(full);某/untilfale;endconumer:beginrepeatwait(mute某);wait(empty);/某应为wait(full),而且还应该在wait(mute某)的前面某/ne某tc:=buffer(out);out:=out+1;/某考虑循环,应改为:out:=(out+1)modn;某/ignal(mute某);/某ignal(empty);某/conumeriteminne某tc;untilfale;end27.试利用记录型信号量写出一个不会出现死锁的哲学家进餐问题的算法.设初始值为1的信号量c[I]表示I号筷子被拿(I=1,2,3,4,...,2n),其中n为自然数.end(I):BeginifImod2==1then{P(c[I]);P(c[I-1mod5]);V(c[I-1mod5]);}ele{P(c[I-1mod5]);P(c[I]);Eat;V(c[I]);V(c[I-1mod5]);}End28.在测量控制系统中的数据采集任务,把所采集的数据送一单缓冲区;计算任务从该单缓冲中取出数据进行计算.试写出利用信号量机制实现两者共享单缓冲的同步算法.intmute某=1;intempty=n;intfull=0;intin=0;intout=0;{cobeginend();obtain();coend}end(){while(1){..collectdatainne某tp; ..wait(empty);wait(mute某);buffer(in)=ne某tp;in=(in+1)modn;ignal(mute某);ignal(full);}}//endobtain(){while(1){wait(full);wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);culculatethedatainne某tc;}//while}//obtain29画图说明管程由哪几部分组成为什么要引入条件变量管程由三部分组成:局部于管程的共享变量说明;对该数据结构进行操作的一组过程;对局部于管程的数据设置初始值的语句.(图见P59)因为调用wait原语后,使进程等待的原因有多种,为了区别它们,引入了条件变量.30.如何利用管程来解决生产者-消费者问题(见P60)31.什么是AND信号量试利用AND信号量写出生产者-消费者问题的解法.为解决并行所带来的死锁问题,在wait操作中引入AND条件,其基本思想是将进程在整个运行过程中所需要的所有临界资源,一次性地全部分配给进程,用完后一次性释放.解决生产者-消费者问题可描述如下:varmute某,empty,full:emaphore:=1,n,0;buffer:array[0,...,n-1]ofitem;in,out:integer:=0,0;beginparbeginproducer:beginrepeat..produceaniteminne某tp;..wait(empty);wait(1,2,3,...,n);//1,2,...,n为执行生产者进程除empty外其余的条件wait(mute某);buffer(in):=ne某tp;in:=(in+1)modn;ignal(mute某);ignal(full);ignal(1,2,3,...,n);untilfale;endconumer:beginrepeatwait(full);wait(k1,k2,k3,...,kn);//k1,k2,...,kn为执行消费者进程除full 外其余的条件wait(mute某);ne某tc:=buffer(out);out:=(out+1)modn;ignal(mute某);ignal(empty);ignal(k1,k2,k3,...,kn);conumetheiteminne某tc;untilfale;endparendend33.试比较进程间的低级通信工具与高级通信工具.用户用低级通信工具实现进程通信很不方便,因为其效率低,通信对用户不透明,所有的操作都必须由程序员来实现.而高级通信工具则可弥补这些缺陷,用户可直接利用操作系统所提供的一组通信命令,高效地传送大量的数据.第三章1.高级调度与低级调度的主要任务是什么为什么要引入中级调度a.作业调度又称宏观调度或高级调度,其主要任务是按一定的原则对外存上处于后备状态的作业进行选择,给选中的作业分配内存,输入输出设备等必要的资源,并建立相应的进程,以使该作业的进程获得竞争处理机的权利.b.进程调度又称微观调度或低级调度,其主要任务是按照某种策略和方法选取一个处于就绪状态的进程,将处理机分配给它.c.为了提高内存利用7.选择调度方式和调度算法时,应遵循的准则是什么a.面向用户的准则有周转时间短,响应时间快,截止时间的保证,以及优先权准则.b.面向系统的准则有系统吞吐量高,处理机利用率好,各类资源的平衡利用.11.在时间片轮转法中,应如何确定时间片的大小?a.系统对响应时间的要求;b.就绪队列中进程的数目;c.系统的处理能力。
操作系统教程课后习题参考答案
![操作系统教程课后习题参考答案](https://img.taocdn.com/s3/m/f6baff33e2bd960590c67770.png)
操作系统教程课后习题参考答案习题一习题二习题三习题四习题五习题六习题一1.设计操作系统的主要目的是什么?设计操作系统的目的是:(1)从系统管理人员的观点来看,设计操作系统是为了合理地去组织计算机工作流程,管理和分配计算机系统硬件及软件资源,使之能为多个用户所共享。
因此,操作系统是计算机资源的管理者。
(2)从用户的观点来看,设计操作系统是为了给用户使用计算机提供一个良好的界面,以使用户无需了解许多有关硬件和系统软件的细节,就能方便灵活地使用计算机。
2.操作系统的作用可表现在哪几个方面?(1) 方便用户使用:操作系统通过提供用户与计算机之间的友好界面来方便用户使用。
(2) 扩展机器功能:操作系统通过扩充硬件功能和提供新的服务来扩展机器功能。
(3) 管理系统资源:操作系统有效地管理系统中的所有硬件和软件资源,使之得到充分利用。
(4) 提高系统效率:操作系统合理组织计算机的工作流程,以改进系统性能和提高系统效率。
(5)构筑开放环境:操作系统遵循国际标准来设计和构造一个开放环境。
其含义主要是指:遵循有关国际工业标准和开放系统标准,支持体系结构的可伸缩性和可扩展性;支持应用程序在不同平台上的可移植性和互操作性。
3.试叙述脱机批处理和联机批处理工作过程(1)联机批处理工作过程用户上机前,需向机房的操作员提交程序、数据和一个作业说明书,后者提供了用户标识、用户想使用的编译程序以及所需的系统资源等基本信息。
这些资料必须变成穿孔信息,(例如穿成卡片的形式),操作员把各用户提交的一批作业装到输入设备上(若输入设备是读卡机,则该批作业是一叠卡片),然后由监督程序控制送到磁带上。
之后,监督程序自动输入第一个作业的说明记录,若系统资源能满足其要求,则将该作业的程序、数据调入主存,并从磁带上调入所需要的编译程序。
编译程序将用户源程序翻译成目标代码,然后由连接装配程序把编译后的目标代码及所需的子程序装配成一个可执行的程序,接着启动执行。
操作系统概念课后习题答案
![操作系统概念课后习题答案](https://img.taocdn.com/s3/m/f91f1ee57e192279168884868762caaedd33ba10.png)
操作系统概念课后习题答案操作系统概念课后习题答案第一章:引论⒈操作系统的功能和目标是什么?答:操作系统的功能包括了进程管理、内存管理、文件系统管理、设备管理等。
操作系统的目标是提高计算机系统的资源利用率,提供简单易用的用户界面,保证计算机系统的安全和稳定性。
⒉什么是并发性?并行性?有什么区别?答:并发性是指计算机系统中存在多个独立的任务同时执行的能力。
并行性是指系统中同时执行多个任务的能力。
并行性强调多个任务的同时进行,而并发性强调任务的独立性。
⒊什么是中断?有什么作用?答:中断是指计算机执行过程中出现的一种特殊事件,用于打断正在执行的程序,转而执行中断处理程序。
中断的作用是能够及时响应输入/输出设备的请求以及处理发生的异常情况。
⒋什么是多道程序设计?答:多道程序设计是指将多个程序加载到内存中,并按照一定的调度算法来分时共享处理器和其他资源。
⒌什么是虚拟内存?答:虚拟内存是计算机系统通过借助硬盘空间来扩展内存空间的一种技术。
它将部分物理内存空间映射到磁盘上,使得程序可以访问比实际物理内存更大的地质空间。
第二章:进程管理⒈什么是进程?什么是线程?答:进程是指在操作系统中运行的程序的实例,它包括了程序代码、数据和执行状态等。
线程是进程中的一个执行单元,一个进程可以包含多个线程,它们共享进程的资源。
⒉进程的状态有哪些?请描述每个状态的含义。
答:进程的状态包括了就绪状态、运行状态、阻塞状态。
就绪状态表示进程已经具备运行的条件,等待分配处理器资源。
运行状态表示进程正在执行。
阻塞状态表示进程由于某种原因暂时无法继续执行。
⒊进程调度算法有哪些?请简要描述每个算法的特点。
答:常见的进程调度算法有先来先服务(FCFS)、短作业优先(SJF)、优先级调度、时间片轮转等。
FCFS按照进程的到达顺序进行调度,适用于长作业。
SJF按照进程的执行时间进行调度,适用于短作业。
优先级调度根据进程的优先级进行调度。
时间片轮转将处理器时间分成若干个时间片,每个进程获得一个时间片。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1. 什么是操作系统?它的主要功能是什么?答:操作系统是用来管理计算机系统的软、硬件资源,合理地组织计算机的工作流程,以方便用户使用的程序集合;其主要功能有进程管理、存储器管理、设备管理和文件管理功能。
2. 什么是分时系统?什么是实时系统?试从交互性、及时性、独立性、多路性和可靠性几个方面比较分时系统和实时系统。
答:分时系统:一个计算机和许多终端设备连接,每个用户可以通过终端向计算机发出指令,请求完成某项工作,在这样的系统中,用户感觉不到其他用户的存在,好像独占计算机一样。
实时系统:对外部输入的信息,实时系统能够在规定的时间内处理完毕并作出反应。
比较:(1)交互性:实时系统具有交互性,但人与系统的交互,仅限于访问系统中某些特定的专用服务程序。
它不像分时系统那样向终端用户提供数据处理、资源共享等服务。
实时系统的交互性要求系统具有连续人机对话的能力,也就是说,在交互的过程中要对用户得输入有一定的记忆和进一步的推断的能力。
(2)及时性:实时系统对及时性的要求与分时系统类似,都以人们能够接受的等待时间来确定。
而分时系统则对及时性要求更高。
(3)独立性:实时系统与分时系统一样具有独立性。
每个终端用户提出请求时,是彼此独立的工作、互不干扰。
(4)多路性:实时系统与分时一样具有多路性。
操作系统按分时原则为多个终端用户提供服务,而对于实时系统,其多路性主要表现在经常对多路的现场信息进行采集以及对多个对象或多个执行机构进行控制。
(5)可靠性:分时系统虽然也要求可靠性,但相比之下,实时系统则要求系统高度可靠。
9.设内存中有三道程序,A ,B ,C ,他们按A →B →C 的先后次序执行,它们进行“计算”和“I/O 操作”的时间如表1-2所示,假设三道程序使用相同的I/O 设备。
表1-2 三道程序的操作时间(1) 试画出单道运行时三道程序的时间关系图,并计算完成三道程序要花多少时间。
I/O 操作计算90605014020160170190200AABBBCCC总时间=20+30+10+30+50+20+10+20+10=200(2) 试画出多道运行时三道程序的时间关系图,并计算完成三道程序要花多长时间。
I/O 操作程序A 605014020AA100BB BCC CA I/O 操作I/O 操作1208090程序B 程序C70130总时间=130 第二章5. 假设系统就绪队列中有10个进程,这10个进程轮换执行,每隔300ms 轮换一次,CPU 在进程切换时所花费的时间是10ms ,试问系统化在进程切换上的开销占系统整个时间的比例是多少?答:因为每隔300ms 换一次进程,且每个进程切换时所花费的时间是10ms ,则系统化在进程切换上的开销占系统整个时间的比例是10/(300+10)=% 6. 试述线程的特点及其与进程之间的关系。
答:(1)特点:线程之间的通信要比进程之间的通信方便的多;同一进程内的线程切换也因为线程的轻装而方便的多。
同时线程也是被独立调度的分配的;(2)线程与进程的关系:线程和进程是两个密切相关的概念,一个进程至少拥有一个线程,进程根据需要可以创建若干个线程。
线程自己基本上不拥有资源,只拥有少量必不可少的资源(线程控制块和堆栈) 7. 根据图2-18,回答以下问题。
(1) 进程发生状态变迁1、3、4、6、7的原因。
答:1表示操作系统把处于创建状态的进程移入就绪队列;3表示进程请求I/O 或等待某事件;4表示进程用行的时间片用完;6表示I/O 完成或事件完成;7表示进程完成。
(2) 系统中常常由于某一进程的状态变迁引起另一进程也产生状态变迁,这种变迁称为因果变迁。
下述变迁是否为因果变迁:3~2,4~5,7~2,3~6,是说明原因。
答:3→2是因果变迁,当一个进程从运行态变为阻塞态时,此时CPU 空闲,系统首先到高优先级队列中选择一个进程。
4→5是因果变迁,当一个进程运行完毕时,此时CPU 空闲,系统首先到高优先级队列中选择进程,但如果高优先级队列为空,则从低优先队列中选择一个进程。
7→2 是因果变迁,当一个进程运行完毕时,CPU 空闲,系统首先到高优先级队列中选择一个进程。
3→6不是因果变迁。
一个进程阻塞时由于自身的原因而发生的,和另一个进程等待的时间到达没有因果关系。
(3) 根据此进程状态转换图,说明该系统CPU 调度的策略和效果。
答:当进程调度时,首先从高优先级就绪队列选择一个进程,赋予它的时间片为100ms。
如果高优先级就绪队列为空,则从低优先级就绪队列选择进程,并且赋予该进程的时间片为500ms。
这种策略一方面照顾了短进程,一个进程如果在100ms运行完毕它将退出系统,更主要的是照顾了I/O量大的进程,进程因I/O进入阻塞队列,当I/O完成后它就进入了高优先级就绪队列,在高优先级就绪队列等待的进程总是优于低优先级就绪队列的进程。
而对于计算量较大的进程,它的计算如果在100ms的时间内不能完成,它将进入低优先级就绪队列,在这个队列的进程被选中的机会要少,只有当高优先级就绪队列为空,才从低优先级就绪队列选择进程,但对于计算量大的进程,系统给予的适当照顾时间片增大为500ms。
8.回答以下问题。
(1)若系统中没有运行进程,是否一定没有就绪进程?为什么?答:是,因为当CPU空闲时,系统就会在就绪队列里调度进程,只有当就绪队列为空时,系统中才没有运行程序。
(2)若系统中既没有运行进程,也没有就绪进程,系统中是否就没有阻塞进程?解释。
答:不一定,当运行的程序都因为请求I/O或等待事件时而进入阻塞,系统中就没有就绪进程。
(3)如果系统采用优先级调度策略,运行的进程是否一定是系统中优先级最高的进程?为什么?答:不一定,若优先级高的进程进入阻塞状态时,而且优先级高的就绪队列里没有等待的进程,这时就会调度优先级低的就绪队列的进程。
9.假如有以下程序段,回答下面的问题。
S1: a=3-x;S2: b=2*a;S3: c=5+a;(1)并发程序执行的Bernstein 条件是什么?答:若P1与P2R并发执行,当且仅当R(P1)∩W(P2)∪R(P2)∩W(P1)∪W(P1)∩W(P2)={}时才满足。
(2)试画图表示它们执行时的先后次序。
(3)利用Bernstein 条件证明,S1、S2和S3哪两个可以并发执行,哪两个不能。
答:R(s1)={x},W(s1)={a};R(s2)={a},W(s2)={b};R(s3)={a},W(s3)={c};(1).R(s1)∩W(s2)∪R(s2)∩W(s1)∪W(s1)∩W(s2)={a},则s1与s2不能并发执行;(2). R(s1)∩W(s3)∪R(s3)∩W(s1)∪W(s1)∩W(s3)={a},则s1与s3不能并发执行;(3). R(s2)∩W(s3)∪R(s3)∩W(s2)∪W(s2)∩W(s3)={},则s2与s3可以并发执行。
第三章1.设有一个售票大厅,可容纳200人购票。
如果厅内不足200人则允许进入,超过则在厅外等候;售票员某时只能给一个购票者服务,购票者买完票后就离开。
试问:(1)购票者之间是同步关系还是互斥关系?答:互斥关系。
(2)用P、V操作描述购票者的工作过程。
semaphore empty=200;semaphore mutex=1;semaphore waiting=0;void buy(){ p(waiting);p(mutex);买票;v(mutex);v(empty);}void waiting(){p(empty);等待;waiting++;}2.有4个进程P1、P2、P3、P4共享一个缓冲区,进程P1向缓冲区存入消息,进程P2、P3、P4从缓冲区中取消息,要求发送者必须等三个进程都取过本消息后才能发送下调消息。
缓冲区内每次只能容纳一个消息,用P、V操作描述四个进程存取消息的情况。
答:semaphore p1=0;semaphore p2,p3,p4=1;semaphore cout=0;semaphore mutex=1;void main(){P(p2);P(p3);P(4);V(cout);}write p1(){P(p1);P(metux);P(cout);存入消息;V(p1);V(metux);}Read p2(){ P(mutex);P(p1);读消息;V(p1);V(p2);V(metux);}Read p3(){ P(mutex);P(p1);读消息;V(p1);V(p3);V(metux);}Read p4(){ P(mutex);P(p1);读消息;V(p1);V(p4); V(metux);}3.分析生产者——消费者问题中多个P操作颠倒引起的后果。
答:semaphore mutex=1;semaphore empty=n;semaphore full=0;int i,j;ITEM buffer[n];ITEM data_p,data_c;void producer()/*生产者进程*/ void consumer() /*消费者进程*/{while(true) {while(true){ { P(mutex) ;P(mutex); P(full);P(empty); data_c=buffer[j];buffer[i]=data_p; j=(j+1)%n;i=(i+1)%n; V(mutex);V(mutex); V(empty);V(full);} }} }若把生产者进程的P操作颠倒,消费者进程的P操作颠倒(如图),则生产者进程执行到V(mutex)时,消费者就可以执行P(mutex)但由于full=0,消费者进程不可执行P(full);当生产者进程执行完V(full)后,full=1,但由于mutex=0,消费者进程无法执行,造成死锁。
第四章1.系统中有5个资源被4个进程所共享,如果每个进程最多需要2个这种资源,试问系统是否会产生锁死?答:不会产生死锁;因为因为资源数可以满足进程的需要,当其中的一个进程争取到剩下的一个资源可以执行,当执行完成以后会释放资源,供其他进程使用,所以不会产生死锁。
2.计算机系统有8台磁带机,由N个进程竞争使用,每个进程最多需要3台。
问:N 为多少时,系统没有死锁的危险?答:当n为1、2、3时,没有死锁的危险;因为当n小于3时,每个进程分配2台磁带机,还有磁带机剩余,那么当其中的一个进程得到剩余的磁带机则可运行,运行结束后会释放磁带机,供其他进程使用,系统不会有死锁的危险;当n为4时,每台分配2台时没有剩余,则会产生死锁,当大于5时同样会死锁。
3.系统有5个进程,它们的到达时间和服务时间如表4-8所示。
新进程(没有运行过)与老进程(运行过的进程)的条件相同时,假定系统选新进程运行。