1. 程式人生 > >作業系統概念(Operating System Concepts Ninth Edition恐龍書)第二章課後題翻譯答案

作業系統概念(Operating System Concepts Ninth Edition恐龍書)第二章課後題翻譯答案

CHAPTER 2

Chapter 2 is concerned with the operating-system interfaces that users (or at least 
programmers) actually see:system calls. The treatment is somewhat vague since more 
detail requires picking a specific system to discuss.This chapter is best 
supplemented with exactly this detail for the specific system the students have at 
hand.Ideally they should study the system calls and write some programs making system 
calls. This chapter also ties together several important concepts including layered 
design, virtual machines, Java and the Java virtual machine, system design and 
implementation, system generation, and the policy/mechanism difference.
第2章是關於使用者(或者至少是程式設計師)實際看到的作業系統介面: 系統呼叫 需要選擇一個確切
的系統來分析否則有些含糊。這一章很好的補充了具體系統的一些細節,而這些作業系統是學生
手頭上有的。理想情況下,他們將學習系統呼叫並編寫一些系統呼叫程式。本章還將幾個重要的
概念聯絡在一起,包括分層設計、Java與Java虛擬機器、系統設計與實現、系統生成、系統策略
/機制的差異

Exercises
2.1 The services and functions provided by an operating system can be divided 
into two main categories.Briefly describe the two categories, and discuss how 
they differ.
作業系統提供的服務和功能可以劃分為兩大類。簡要描述這兩類,並討論如何他們的不同
Answer:
    One class of services provided by an operating system is to enforce 
protection between different processes running concurrently in the system. Processes 
are allowed to access only those memory locations that are associated with their 
address spaces. Also, processes are not allowed to corrupt files associated with other
users. A process is also not allowed to access devices directly without operating 
system intervention. The second class of services provided by an operating system is 
to provide new functionality that is not supported directly by the underlying hardware. 
Virtual memory and file systems are two such examples of new service sprovided by an 
operating system.
    作業系統提供的一類服務是在系統中不同併發執行的程序之間強制保護。程序只允許訪問
與它們關聯的記憶體位置。。此外,程序不允許損壞與其他程序相關聯的檔案。程序也不允許在沒
有作業系統介入的情況下直接訪問裝置。作業系統提供的第二類服務是提供低層硬體不能直接
支援的功能。虛擬記憶體和檔案系統就是作業系統提供的兩類服務的例子。


2.2 Describe three general methods for passing parameters to the operating system.
描述傳遞引數到作業系統的三種通用方法.
Answer: 
    a. Pass parameters in registers 
    a. 暫存器傳遞引數
    b. Registers pass starting addresses of blocks of parameters 
    b. 暫存器傳遞引數的起始地址
    c. Parameters can be placed, or pushed, onto the stack by the program, 
and popped off the stack by the operating system 
    c. 引數通過作業系統可以被程式放置,或者壓入棧,彈出棧


2.3 Describe how you could obtain a statistical profile of the amount of time spent 
by a program executing different sections of its code. Discuss the importance of 
obtaining such a statistical profile. 
描述如何獲得一個程式執行不同程式碼部分的花費時間統計表。討論獲得這種統計表的重要性
Answer: 
    One could issue periodic timer interrupts and monitor what instructions or 
what sections of code are currently executing when the interrupts are delivered. A 
statistical profile of which pieces of code were active should be consistent with 
the time spent by the program in different sections of its code. Once such a 
statistical profile has been obtained, the programmer could optimize those sections 
of code that are consuming more of the CPU resources. 
    可以發出週期性的定時器中斷,並且當中斷到達時監控程式碼正在執行的片段或指令。一個
活躍程式碼片段統計表與程式在不同程式碼片段的耗時一致。一旦獲得了統計表,程式設計師可以優化
消耗CPU資源較多的程式碼片段


2.4 What are the five major activities of an operating system in regard to file 
management?
作業系統檔案管理的5個主要功能是什麼?
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
在穩定(非易失性)儲存介質上備份檔案


2.5 What are the advantages and disadvantages of using the same system-call 
interface for manipulating both files and devices?
使用相同系統呼叫操作檔案和裝置的優點和缺點是什麼
Answer:
    Each device can be accessed as though it was a file in the file system. Since 
most of the kernel deals with devices through this file interface, it is relatively
easy to add a new device driver by implementing the hardware-specific code to support 
this abstract file interface. Therefore, this benefits the development of both user 
program code, which can be written to access devices and files in the same manner, 
and device driver code, which can be written to support a well-defined API. The
disadvantage with using the same interface is that it might be difficult to capture 
the functionality of certain devices within the context of the file access API, 
thereby resulting in either a loss of functionality or a loss of performance. Some 
of this could be overcome by the use of the ioctl operation that provides a 
general-purpose interface for processes to invoke operations on devices
可以像訪問檔案系統中的檔案一樣訪問每個裝置。因為大多數核心都是通過檔案介面來處理
裝置的,所以相對容易通過實現具體硬體的程式碼來支援抽象的檔案介面來增加一個新的裝置
驅動器。因此,這個有利於雙方使用者程式碼的發展, 它可以以同樣的方式來訪問裝置和檔案,
並且裝置驅動程式碼可以支援一個定義明確的API。使用相同的介面的弊端在於它可能很難捕捉
在檔案訪問API上下文中某些裝置的功能,從而導致功能損失或效能損失。

2.6 Would it be possible for the user to develop a new command interpreter using 
the system-call interface provided by the operating system?
採用作業系統提供的系統呼叫介面,使用者是否能夠開發一個新的命令解釋程式?
Answer:
    An user should be able to develop a new command interpreter using the system-call 
interface provided by the operating system. The command interpreter allows an user to 
create and manage processes and also determine ways by which they communicate (such 
as through pipes and files). As all of this functionality could be accessed by an 
user-level program using the system calls, it should be possible for the user to 
develop a new command-line interpreter
使用者應該能夠使用系統提供的系統呼叫開發新的命令直譯器。命令直譯器允許使用者這樣建立和
管理程序並且確定它們的通訊方式(通過管道和檔案)。由於所有這些功能都可以被使用者級的程
序進行系統呼叫,因此使用者可以開發出一個新的命令列直譯器。


2.7 What are the two models of interprocess communication? What are the strengths 
and weaknesses of the two approaches?
程序間通訊的兩種模式是什麼? 優點缺點各是什麼?
Answer:
The two models of interprocess communication are message-passing model and the 
shared-memory model. Message passing is useful for exchanging smaller amounts of 
data, because no conflicts need be avoided. It is also easier to implement than 
is shared memory for intercomputer communication. Shared memory allows maximum 
speed and convenience of communication, since it can be done at memory transfer 
speeds when it takes place within a computer. However, this method compromises on 
protection and synchronization between the processes sharing memory
程序間通訊的兩種模型是訊息傳遞模型和共享記憶體模型。訊息傳遞對於交換小數量的訊息非常
有用,因為不需要避免衝突。它的實現要比共享記憶體簡單。當它在一臺計算機中發生的時候,
共享記憶體允許最大速度並且方便通訊,因為它可以在記憶體傳輸。然而,這種方法在共享記憶體的
程序之間的保護和同步方面做出了妥協


2.8 Why is the separation of mechanism and policy desirable?
為什麼機制和策略分離是可取的?
Answer:
Mechanism and policy must be separate to ensure that systems are easy to modify. No 
two system installations are the same, so each installation may want to tune the 
operating system to suit its needs. With mechanism and policy separate, the policy 
may be changed at will while the mechanism stays unchanged. This arrangement provides 
a more flexible system.
機制和策略必須分離,以確保系統方便更改。沒有兩個系統安裝是相同的,因此每個安裝要讓
作業系統配合它的需要。機制和策略分離下,策略在機制不變的情況下,可以隨意更改,這樣的
安排提供一個更靈活的系統。


2.9 It is sometimes difficult to achieve a layered approach if two components of 
the operating system are dependent on each other. Identify a scenario in which it is
unclear how to layer two system components that require tight coupling of their 
functionalities.
如果作業系統的兩個元件相互依賴,那麼採用分層法有時很難。找一個這樣的場景: 有兩個
系統元件的功能是緊密耦合的,但如何對它們分層卻並不清楚。
Answer:
    The virtual memory subsystem and the storage subsystem are typically tightly 
coupled and requires careful design in a layered system due to the following 
interactions. Many systems allow files to be mapped into the virtual memory space of 
an executing process. On the other hand, the virtual memory subsystem typically uses 
the storage system to provide the backing store for pages that do not currently 
reside in memory. Also, updates to the file system are sometimes buffered in physical 
memory before it is flushed to disk, thereby requiring careful coordination of the 
usage of memory between the virtual memory subsystem and the file system.
    虛擬記憶體子系統和儲存子系統通常是緊密連線的,由於下面的互動,需要在分層系統中仔細
設計。許多系統允許將檔案對映成執行的程序的虛擬記憶體空間。另一方面,虛擬記憶體子系統通常
使用儲存系統為當前不再記憶體中的頁提供儲存。此外,對檔案系統的更新有時在重新整理到磁碟中前
會在實體記憶體緩衝,因此,需要仔細協調虛擬記憶體子系統和檔案系統之間記憶體的使用。


2.10 What is the main advantage of the microkernel approach to system design? How do 
user programs and system services interact in a microkernel architecture? What are 
the disadvantages of using the microkernel approach?
微核心方法在系統設計上的主要優點是什麼?使用者程式和系統服務如何在微核心架構中互動?微
核心方法的缺點是什麼?
Answer:
    Benefits typically include the following: 
    優點通常包括以下幾點:
(a) adding a new service does not require modifying the kernel, 
(a) 新增新服務不需要修改核心
(b) it is more secure as more operations are done in user mode than in kernel mode, and 
(b) 由於在使用者模式下進行的操作比在核心模式下進行的操作多,因此更安全
(c) a simpler kernel design and functionality typically results in a more reliable 
operating system. User programs and system services interact in a microkernel 
architecture by using interprocess communication mechanisms such as messaging. These 
messages are conveyed by the operating system. The primary disadvantages of the 
microkernel architecture are the overheads associated with interprocess communication 
and the frequent use of the operating system’s messaging functions in order to enable 
the user process and the system service to interact with each other.
更簡單的核心設計和功能通常會帶來更可靠的結果系統。使用者程式和系統服務在微核心架構中
通常使用程序間通訊機制例如訊息傳遞來互動。這些訊息由作業系統傳遞。微核心架構的主要
缺點是與程序間通訊相關的開銷有關,並且頻繁的使用作業系統訊息傳遞功能來使使用者程序和
系統服務可以彼此互動。


2.12 How are iOS and Android similar? How are they different?
iOS和Android有何相似之處?它們有什麼不同?
Answer:
Similarities
• Both are based on existing kernels (Linux and Mac OS X).
• Both have architecture that uses software stacks.
• Both provide frameworks for developers.
相似之處
兩者都基於現有核心(Linux和Mac OS X)
兩者都有使用軟體棧的架構
兩者都為開發人員提供了框架
Differences
• iOS is closed-source, and Android is open-source.
• iOS applications are developed in Objective-C, Android in Java.
• Android uses a virtual machine, and iOS executes code natively.
差異
IOS是封閉原始碼的,Android是開源的
IOS應用程式是用用Objective-C開發的, Android是用Java開發的。
Android使用虛擬機器,IOS本地執行程式碼


2.13 Explain why Java programs running on Android systems do not use the standard 
Java API and virtual machine.
解釋為何在安卓系統中執行的Java程式不使用Java API和虛擬機器。
Answer:
    It is because the standard API and virtual machine are designed for desktop and 
server systems, not mobile devices. Google developed a separate API and virtual 
machine for mobile devices.
    因為標準API和虛擬機器是為桌面和伺服器系統設計的,而不是為移動系統設計的裝置。谷歌
移動裝置開發了單獨的API和虛擬機器。


2.14 The experimental Synthesis operating system has an assembler incorporated in 
the kernel. To optimize system-call performance, the kernel assembles routines within 
kernel space to minimize the path that the system call must take through the kernel. 
This approach is the antithesis of the layered approach, in which the path through the 
kernel is extended to make building the operating system easier. Discuss the pros and 
cons of the Synthesis approach to kernel design and optimization of system performance.
實驗作業系統Synthesis在核心裡集成了一個彙編器。為了優化系統呼叫效能,通過在核心空
間內彙編程式,可縮短系統呼叫在核心中經過的路徑。這與分層法相反,這種方法包括了在核心
中經過的路徑,以使作業系統構建更加簡單。討論Synthesis方法對核心設計和效能優化有什麼
好處與壞處。

Answer:
    Synthesis is impressive due to the performance it achieves through on-the-fly 
compilation. Unfortunately, it is difficult to debug problems within the kernel due 
to the fluidity of the code. Also, such compilation is system specific, making 
Synthesis difficult to port (a new compiler must be written for each architecture).
    Synthesis因為動態編譯而令人印象深刻,不幸的是,在核心中除錯問題是很困難的,由於
程式碼的流動性。而且,這樣的編譯是系統特有的,使Synthesis難以移植(必須為每個架構編寫
新的編譯器)