用户工具

站点工具


01-基础学习:课程:操作系统:操作系统概念1-6章部分习题解答

操作系统习题

题目

第一章1.1 1.3 1.6
第二章2.2 2.3 2.5 2.8
第三章3.1 3.2 3.4 3.7 3.10 3.13
第四章4.2 4.4 4.7
第五章5.1 5.3 5.6
第六章6.1 6.3 6.4 6.7

第一章

1.1

What are the three main purposes of an operating system?

Answer:

  • To provide an environment for a computer user to execute programs on computer hardware in a convenient and efficient manner.
  • To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be as fair and efficient as possible.
  • As a control program it serves two major functions: (1) supervision of the execution of user programs to prevent errors and improper use of the computer, and (2) management of the operation and control of I/O devices.
  • 环境提供者,为计算机用户提供一个环境,使得能够在计算机硬件上方便、高效的执行程序
  • 资源分配者,为解决问题按需分配计算机的资源,资源分配需尽可能公平、高效
  • 控制程序,(1)监控用户程序的执行,防止出错和对计算机的不正当使用; (2)管理I/O设备的运行和控制

1.2

What is the main advantage of multiprogramming?

Answer: Multiprogramming makes efficient use of the CPU by overlapping 1) the demands 2) for the CPU and its I/O devices from various3) users. It attempts to increase CPU utilization4) by always having something for the CPU to execute.

1.6

Define the essential properties of the following types of operating systems:

a. Batch
b. Interactive
c. Time sharing
d. Real time
e. Network
f. Distributed

Answer: a. Batch. Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequencer. Performance is increased by attempting to keep CPU and I/O devices busy at all times through buffering, off-line operation, spooling, and multiprogramming. Batch is good for executing large jobs that need little interaction; it can be submitted and picked up later.
b. Interactive. This system is composed of many short transactions where the results of the next transactionmay be unpredictable. Response time needs to be short (seconds) since the user submits and waits for the result.
c. Time sharing. This systems uses CPU scheduling and multiprogramming to provide economical interactive use of a system. The CPU switches rapidly from one user to another. Instead of having a job defined by spooled card images, each program reads Answers to Exercises 3 its next control card from the terminal, and output is normally printed immediately to the screen.
d. Real time. Often used in a dedicated application, this system reads information from sensors and must respond within a fixed amount of time to ensure correct performance.
e. Network.
f. Distributed.This system distributes computation among several physical processors. The processors do not share memory or a clock. Instead, each processor has its own local memory. They communicate with each other through various communication lines, such as a high-speed bus or telephone line.

a. Batch
相似需求的Job分批、成组的在计算机上执行,Job由操作员或自动Job程序装置装载; 可以通过采用 buffering, off-line operation, spooling, multiprogramming 等技术使CPU 和 I/O不停忙来提高性能 批处理适合于需要极少用户交互的Job。
b. Interactive
由许多短交易组成,下一次交易的结果可能不可预知需要响应时间短
c. Time sharing
使用CPU调度和多道程序提供对系统的经济交互式使用,CPU快速地在用户之间切换
一般从终端读取控制,输出立即打印到屏幕
d. Real time
在专门系统中使用,从传感器读取信息,必须在规定时间内作出响应以确保正确的执行
e. Network
在通用OS上添加
联网、通信功能
远程过程调用
文件共享
f. Distributed
具有联网、通信功能
提供远程过程调用
提供多处理机的统一调度调度
统一的存储管理
分布式文件系统

第二章

2.2

Howdoes the distinction betweenmonitormode and usermode function as a rudimentary form of protection (security) system?

Answer: By establishing a set of privileged instructions that can be executed only when in the monitor mode, the operating system is assured of controlling the entire system at all times.
通过建立一组只能在monitor mode才能执行的特权指令集,OS能够确保总是能控制整个系统。

2.3

What are the differences between a trap and an interrupt? What is the use of each function?

Answer: An interrupt is a hardware-generated change-of-flow within the system. An interrupt handler is summoned to deal with the cause of the interrupt; control is then re- turned to the interrupted context and instruction. A trap is a software-generated interrupt. An interrupt can be used to signal the completion of an I/O to obviate the need for device polling. A trap can be used to call operating system routines or to catch arithmetic errors.

An interrupt是硬件产生的系统内的流的改变
A trap是软件产生的“中断”。
interrupt可以被I/O用来产生完成的信号,从而避免CPU对设备的轮询
A trap可以用来调用OS的例程或者捕获算术错误

2.5

Which of the following instructions should be privileged?

  • a. Set value of timer.
  • b. Read the clock.
  • c. Clear memory.
  • d. Turn off interrupts.
  • e. Switch from user to monitor mode.

Answer: The following instructions should be privileged:
a. Set value of timer.
b. Clear memory.
c. Turn off interrupts5).
d. Switch from user to monitor6) mode.

2.8

Protecting the operating system is crucial to ensuring that the computer system operates correctly. Provision of this protection is the reason behind dual-mode operation, memory protection, and the timer. To allow maximum flexibility, however, we would also like to place minimal constraints on the user. The following is a list of operations that are normally protected. What is the minimal set of instructions that must be protected?
a. Change to user mode.
b. Change to monitor mode.
c. Read from monitor memory.
d. Write into monitor memory.
e. Fetch an instruction from monitor memory.
f. Turn on timer interrupt.
g. Turn off timer interrupt.

Answer: The minimal set of instructions that must be protected are:
a. Change to monitor mode.
b. Read from monitor memory.
c. Write into monitor memory.
d. Turn off timer interrupt.

第三章

3.1

What are the fivemajor activities of an operating systemin regard to processmanagement?

Answer:

  • The creation and deletion of both user and system processes
  • The suspension and resumption of processes
  • The provision of mechanisms for process synchronization
  • The provision of mechanisms for process communication
  • The provision of mechanisms for deadlock handling

3.2

What are the three major activities of an operating system in regard to memory management?

Answer:

  • Keep track of which parts of memory are currently being used and by whom.
  • Decide which processes are to be loaded into memory when memory space becomes available.
  • Allocate and deallocate memory space as needed.

3.4

What are the five major activities of an operating system in regard to file management?

Answer:

  • The creation and deletion of files
  • The creation and deletion of directories
  • The support of primitives for manipulating files and directories
  • The mapping of files onto secondary storage
  • The backup of files on stable (nonvolatile) storage media

3.7

What is the purpose of system calls?

Answer: System calls allow user-level processes to request services of the operating system.
让用户级进程可以请求操作系统所提供的服务

3.10

What is the purpose of system programs?

Answer: System programs can be thought of as bundles of useful system calls. They provide basic functionality to users and so users do not need to write their own programs to solve common problems.
为程序开发和运行提供了方便的环境
给用户提供基本的公共功能函数,为用户在不用自己写代码的情况下解决公用问题

3.13

What is the main advantage for an operating-system designer of using a virtual-machine architecture? What is the main advantage for a user?

Answer: The system is easy to debug, and security problems are easy to solve. Virtual machines also provide a good platform for operating system research since many different operating systems may run on one physical system.

第四章

4.2

Describe the differences among short-term, medium-term, and long-term scheduling.

Answer:
Short-term(CPU scheduler)—selects from jobs in memory those jobs that are ready to execute and allocates the CPU to them.

  • Medium-term—used especially with time-sharing systems as an intermediate scheduling level. A swapping scheme is implemented to remove partially run programs from memory and reinstate them later to continue where they left off.
  • Long-term (job scheduler)—determines which jobs are brought into memory for processing.The primary difference is in the frequency of their execution. The short-term must select a new process quite often. Long-term is used much less often since it handles placing jobs in the system and may wait a while for a job to finish before it admits another one.

4.4

Describe the actions a kernel takes to context switch between processes.

Answer: In general, the operating system must save the state of the currently running process and restore the state of the process scheduled to be run next. Saving the state of a process typically includes the values of all the CPU registers in addition to memory allocation. Context switches must also performmany architecture-specific operations, including flushing data and instruction caches.

4.7

Consider the interprocess-communication scheme where mailboxes are used.

a. Suppose a process P wants to wait for two messages, one from mailbox A and one from mailbox B. What sequence of send and receive should it execute?
b. What sequence of send and receive should P execute if P wants to wait for one message either from mailbox A or from mailbox B (or from both)?
c. A receive operation makes a process wait until the mailbox is nonempty. Either devise a scheme that allows a process to wait until a mailbox is empty, or explain why such a scheme cannot exist.
Answer: No answer.

第五章

5.1

Provide two programming examples of multithreading giving improved performance over a single-threaded solution.

Answer:
(1) A Web server that services each request in a separate thread.
(2) A parallelized application such as matrix multiplication where different parts of the matrix may be worked on in parallel.
(3) An interactive GUI program such as a debugger where a thread is used to monitor user input, another thread represents the running application, and a third threadmonitors performance.

可以并发的多任务
Web浏览器,数据可并行处理

5.3

What are two differences between user-level threads and kernel-level threads? Underwhat circumstances is one type better than the other?

Answer: (1) User-level threads are unknown by the kernel, whereas the kernel is aware of kernel threads. (2) User threads are scheduled by the thread library and the kernel schedules kernel threads. (3) Kernel threads need not be associatedwith a process whereas every user thread belongs to a process.
内核可知与不可知
调度者不同
与进程的关系

5.6

What resources are used when a thread is created? How do they differ from those used when a process is created?

Answer: Because a thread is smaller than a process, thread creation typically uses fewer resources than process creation. Creating a process requires allocating a process control block (PCB), a rather large data structure. The PCB includes a memory map, list of open files, and environment variables. Allocating and managing the memory map is typically the most time-consuming activity. Creating either a user or kernel thread involves allocating a small data structure to hold a register set, stack, and priority.

第六章

6.1

A CPU scheduling algorithm determines an order for the execution of its scheduled processes.Given n processes to be scheduled on one processor, how many possible different schedules are there? Give a formula in terms of n.

Answer: n! (n factorial = n * (n – 1) * (n – 2) * cdots *2*1)

6.3

Consider the following set of processes, with the length of the CPU-burst time given in milliseconds:

Process Burst Time Priority
P1 10 3
P2 1 1
P3 2 3
P4 1 4
P5 5 2

The processes are assumed to have arrived in the order P1, P2, P3, P4, P5, all at time 0.
a. Draw four Gantt charts illustrating the execution of these processes using FCFS, SJF, a nonpreemptive priority (a smaller priority number implies a higher priority), and RR (quantum = 1) scheduling.
b. What is the turnaround time of each process for each of the scheduling algorithms in part a?
c. What is the waiting time of each process for each of the scheduling algorithms in part a?
d. Which of the schedules in part a results in the minimal average waiting time (over all processes)?

答案: 6.3答案

6.4

Suppose that the following processes arrive for execution at the times indicated. Each process will run the listed amount of time. In answering the questions, use nonpreemptive scheduling and base all decisions on the information you have at the time the decision must be made.

Process Arrival Time Burst Time
P1 0.0 8
P2 0.4 4
P3 1.0 1

a. What is the average turnaround time for these processes with the FCFS scheduling algorithm?
b. What is the average turnaround time for these processes with the SJF scheduling algorithm?
c. The SJF algorithm is supposed to improve performance, but notice that we chose to run process P1 at time 0 because we did not know that two shorter processes would arrive soon. Compute what the average turnaround time will be if the CPU is left idle for the first 1 unit and then SJF scheduling is used. Remember that processes P1 and P2 are waiting during this idle time, so their waiting time may increase. This algorithm could be known as future-knowledge scheduling.

Answer:
a. 10.53
b. 9.53
c. 6.86
Remember that turnaround time is finishing time minus arrival time, so you have to subtract the arrival times to compute the turnaround times. FCFS is 11 if you forget to subtract arrival time.
a. 10.53 ((8-0)+(12-0.4)+(13-1.0))/3 = 10.53
b. 9.53 ((8-0)+(13-0.4)+(9-1.0))/3 = 9.53
c. 6.86 ((14-0)+(6-0.4)+(2-1.0))/3 = 6.87

6.7

Consider the following preemptive priority-scheduling algorithm based on dynamically changing priorities. Larger priority numbers imply higher priority. When a process is waiting for the CPU (in the ready queue but not running), its priority changes at a rate alpha; when it is running, its priority changes at a rate beta. All processes are given a priority of 0 when they enter the ready queue. The parameters alpha and beta can be set to givemany different scheduling algorithms.
a. What is the algorithm that results from beta>alpha>0?
b. What is the algorithm that results from alpha<beta<0?
Answer:
a. FCFS
b. LIFO

1)
v. 与…重叠;盖过(overlap的ing形式)adj. 重叠;覆盖
2)
请求,查询
3)
不同的
4)
利用率
5)
中断
6)
监视
01-基础学习/课程/操作系统/操作系统概念1-6章部分习题解答.txt · 最后更改: 2020/04/07 06:34 由 annhe