作業系統概念(Operating System Concepts Ninth Edition恐龍書)第一章課後題翻譯答案
CHAPTER 1
Chapter 1 introduces the general topic of operating systems and a handful of important
concepts (multiprogramming, time sharing, distributed system, and so on). The purpose is
to show why operating systems are what they are by showing how they developed. In
operatingsystems, as in much of computer science, we are led to the present by the paths
we took in the past, and we can better understand both the present and the future by
understanding the past.
第一章介紹了作業系統的一般主題和一些重要的內容概念(多程式設計、分時、分散式系統等)。這樣
做的目的是通過展示作業系統是如何發展的,來展示它是什麼。在作業系統,正如在許多計算機
科學中一樣,我們是由過去的發展引導到現在。我們可以通過了解過去更好的瞭解現在和未來。
Additional work that might be considered is learning about the particular systems that
the students will have access to at your institution. This is still just a general
overview, as specific interfaces are considered in Chapter 3.
需要額外考慮的工作是瞭解學生可以在機構訪問的特定系統。這仍然只是一個一般的概述,具體的
介面將在第3章討論。
Exercises
1.1 In a multiprogramming and time-sharing environment, several users share the system
simultaneously. This situation can result in various security problems.
在多道程式和分時環境中,多個使用者同時共享一個系統。這種情況可能導致各種安全問題。
a. What are two such problems?
a. 列出兩個這類問題
b. Can we ensure the same degree of security in a time-shared machine as
in a dedicated machine? Explain your answer.
b. 我們是否能夠確保分時系統達到如同專用系統一樣的安全程度?請解釋你的答案
Answer:
a. Stealing or copying one’s
programs or data; using system resources (CPU, memory, disk space, peripherals) without
proper accounting.
a. 偷竊或抄襲某人的程式或資料(資料安全,程式碼漏洞等等);沒有統計下地使用系統資源
(CPU,記憶體,磁碟空間,外設)
b. Probably not, since any protection scheme devised by humans can
inevitably be broken by a human, and the more complex the scheme, the more difficult
it is to feel confident of its correct implementation.
b.可能不會,因為任何由人類設計的保護方案都不可避免的被人打破,方案越複雜,就越
難以對其正確實施感到自信(漏洞是存在的,只不過沒有被發現0day漏洞)
1.2 The issue of resource utilization shows up in different forms in different types of
operating systems. List what resources must be managed carefully in the following
settings:
對於資源利用問題,不同型別的作業系統具有不同的處理方式。列出下列情況,哪些應對資源認
真管理:
a. Mainframe or minicomputer systems
a.大型機或小型機
b. Workstations connected to servers
b. 連線伺服器的工作站
c. Handheld computers
c.掌上電腦
Answer:
a. Mainframes: memory and CPU resources, storage, network
bandwidth
a. 大型機: 記憶體和CPU資源、儲存、網路頻寬
b. Workstations: memory and CPU resources
b. 工作站: 記憶體和CPU資源
c. Handheld computers: power
consumption, memory resources
c. 掌上電腦: 電源消耗,記憶體資源
1.3 Under what circumstances would a user be better off using a timesharing system
rather than a PC or a single-user workstation?
在何種環境下,分時系統優於PC或單使用者工作站?
Answer:
When there are few other users, the task is large, and the hardware is fast, time-sharing
makes sense. The full power of the system can be brought to bear on the user’s problem.
The problem can be solved faster than on a personal computer. Another case occurs when
lots of other users need resources at the same time. A personal computer is best when the
job is small enough to be executed reasonably on it and when performance is sufficient to
execute the program to the user’s satisfaction.
當其他使用者很少時,任務很大,硬體速度塊,分時是有意義的。系統的全部功能可以解決
使用者的問題。這個問題比在個人PC解決更快速。另一種情況發生在許多其他使用者同時需要資源。
當作業足夠小,能夠在其上合理地執行,個人電腦是最好的,並且效能足夠執行令使用者滿意
的程式。
1.4 Describe the differences between symmetric and asymmetric multiprocessing. What are t
hree advantages and one disadvantage of multiprocessor systems?
描述對稱多處理和非對稱多處理的區別。多處理系統有哪三個優點和哪一個缺點?
Answer:
Symmetric multiprocessing treats all processors as equals, and I/O can be processed on
any CPU. Asymmetric multiprocessing has one master CPU and the remainder CPUs are slaves.
The master distributes tasks among the slaves, and I/O is usually done by the master only.
Multiprocessors can save money by not duplicating power supplies, housings, and
peripherals. They can execute programs more quickly and can have increased reliability.
They are also more complex in both hardware and software than uniprocessor systems.
對稱多處理將所有處理器視為對等的,並且I/O操縱可以在任何CPU上執行。非對稱多處理
器具有一個主CPU,其餘CPU為從CPU。主處理器負責分發給從處理器任務,並且I/O通常只由主
處理器完成。多處理器可以共享電源,外殼和其他裝置來節省金錢。它們可以更塊地執行程式,
提高可靠性。它們在硬體和軟體方面也比單處理器系統複雜。
1.5 How do clustered systems differ from multiprocessor systems? What is required for two
machines belonging to a cluster to cooperate to provide a highly available service?
集群系統與多處理器系統有何不同?如何讓同一叢集的兩個機器互相協作以便提供高可用性服務?
Answer:
Clustered systems are typically constructed by combining multiple computers into a single
system to perform a computational task distributed across the cluster. Multiprocessor
systems on the other hand could be a single physical entity comprising of multiple CPUs.
A clustered system is less tightly coupled than a multiprocessor system. Clustered
systems communicate using messages, while processors in a multiprocessor system could
communicate using shared memory. In order for two machines to provide a highly available
service, the state on the two machines should be replicated and should be consistently
updated. When one of the machines fails, the other could then takeover the functionality
of the failed machine.
集群系統通常是通過將多臺計算機組合成一臺計算機來構建系統執行分佈在叢集中的計算
任務。另一方面,系統可以是由多個cpu組成的單一物理實體。集群系統的耦合沒有多處理器系
統緊密。集群系統使用訊息進行通訊,而多處理器系統中的處理器可以使用共享記憶體進行通訊。
為了給兩個機器提供一個高可用性服務時,應該複製兩臺機器上的狀態並保持一致更新。當其
中一臺機器出現故障時,另一臺機器就可以接管該故障的機器的工作。
(如zookeeper框架就是來協調分散式各個節點的服務的,大家有興趣玩玩)
1.6 Consider a computing cluster consisting of two nodes running a database. Describe two
ways in which the cluster software can manage access to the data on the disk. Discuss the
benefits and disadvantages of each.
現有一個執行資料庫的兩個節點叢集。給出兩種方法,以便叢集軟體管理磁碟資料訪問。討論每
種方法的優點和缺點
Answer:
Consider the following two alternatives: asymmetric clustering and parallel clustering.
With asymmetric clustering, one host runs the database application with the other host
simply monitoring it. If the server fails, the monitoring host becomes the active server.
This is appropriate for providing redundancy. However, it does not utilize the potential
processing power of both hosts. With parallel clustering, the database application can
run in parallel on both hosts. The difficulty in implementing parallel clusters is
providing some form of distributed locking mechanism for files on the shared disk.
考慮一下兩種選擇: 非對稱叢集和並行叢集。使用非對稱叢集,一個主機與另一個主機一
起執行資料庫應用程式並簡單的監控。如果伺服器失敗,監視主機將成為活動伺服器。這適用於
提供冗餘,然而,它並沒有充分利用兩個主機的處理能力。通過並行聚集,可以實現資料庫應用
在兩臺主機上並行執行。實現並行叢集的困難在於為共享磁碟上的檔案提供某種形式的分散式鎖
定機制。(redis分散式鎖,zookeeper瞬時有序結點實現的分散式鎖)
1.7 How are network computers different from traditional personal computers? Describe
some usage scenarios in which it is advantageous to use network computers.
網路計算機與傳統計算機有何不同?討論在那些情況下采用網路計算機更為有利?
Answer:
A network computer relies on a centralized computer for most of its services. It
can therefore have a minimal operating system to manage its resources. A personal
computer on the other hand has to be capable of providing all of the required
functionality in a stand-alone manner without relying on a centralized manner. Scenarios
where administrative costs are high and where sharing leads to more efficient use of
resources are precisely those settings where network computers are preferred.
網路計算機的大部分服務依賴於中央計算機。它可以使用最小的作業系統來管理其資源。(可
以聯想智慧電錶)個人電腦另一方面可以提供所有需要的獨立的功能,而不依賴於集中的方式。
管理成本高、共享可以更有效地使用資源的場景是首選網路計算機
1.8 What is the purpose of interrupts? What are the differences between a trap and an
interrupt? Can traps be generated intentionally by a user program? If so, for what purpose?
中斷有何用途?中斷和陷阱的不同?使用者程式能否有意產生陷阱?如果能,為什麼?
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 returned
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
中斷是系統中由硬體產生的流變化。呼叫中斷處理程式來解決造成中斷的原因;控制返回到
中斷的上下文和指令處。陷阱是由軟體產生的中斷,中斷可以用來發出I/O完成的訊號,以消除
對裝置輪詢。陷阱可以用來呼叫作業系統例程或捕獲算數錯誤。
1.9 Direct memory access is used for high-speed I/O devices in order to avoid
increasing the CPU’s execution load.
直接記憶體訪問(DMA)用於高速I/O裝置來避免CPU增加執行負荷。
a. How does the CPU interface with the device to coordinate the transfer?
a. CPU與裝置如何協作傳遞?
b. How does the CPU know when the memory operations are complete?
b. CPU如何得知記憶體操作何時結束?
c. The CPU is allowed to execute other programs while the DMA controller is
transferring data. Does this process interfere with the execution of the user
programs? If so, describe what forms of interference are caused.
c. 當DMA控制傳遞資料時,允許CPU執行使用者程式。這兩者會不會衝突? 如果會,討論會產生
何種衝突?
Answer:
The CPU can initiate a DMA operation by writing values into special registers
that can be independently accessed by the device. The device initiates the corresponding
operation once it receives a command from the CPU. When the device is finished with its
operation, it interrupts the CPU to indicate the completion of the operation. Both the
device and the CPU can be accessing memory simultaneously. The memory controller provides
access to the memory bus in a fair manner to these two entities. A CPU might therefore be
unable to issue memory operations at peak speeds since it has to compete with the device
in order to obtain access to the memory bus.
CPU 可以通過將值寫入可以被裝置獨立訪問的特殊暫存器來啟動DMA操作。當它從CPU接收
到命令後,裝置開始相應的操作。當裝置執行完操作後,它發出中斷請求CPU指示操作完成。裝置
和CPU可能同時訪問記憶體,記憶體控制器提供以公平的方式訪問這兩個實體的記憶體匯流排。因此,
CPU可能是無法在峰值速度下發出記憶體操作,因為它必須與裝置競爭以便獲得對記憶體匯流排的
訪問權(地址匯流排、控制匯流排、資料匯流排)。
1.10 Some computer systems do not provide a privileged mode of operation in hardware.
Is it possible to construct a secure operating system for these computer systems? Give
arguments both that it is and that it is not possible.
有些計算機系統不支援硬體執行的特權操作模式。能否為這些計算機系統構建一種安全操作系
統?給出理由。
Answer:
An operating system for a machine of this type would need to remain in control (or
monitor mode) at all times. This could be accomplished by two methods:
這類機器的作業系統需要時刻保持受控制和受到監視。這可以通過兩種方法來實現:
a. Software interpretation of all user programs (like some BASIC, Java, and LISP
systems, for example). The software interpreter would provide, in software, what the
hardware does not provide.
a. 為所有使用者程式提供軟體直譯器(Basic, java, Lisp系統等)。軟體直譯器將在軟
件中提供,硬體不提供
b. Require that all programs be written in high-level languages so that all object
code is compilerproduced. The compiler would generate (either in-line or by function
calls) the protection checks that the hardware is missing.
b. 要求所有的程式用高階語言編寫,所有的物件程式碼可以被編譯生成。編譯器可以產生
(內聯或者函式呼叫方式)保護檢查硬體是否丟失。
1.11 Many SMP systems have different levels of caches; one level is local to each
processing core, and another level is shared among all processing cores. Why are caching
systems designed this way?
許多SMP系統有不同層次的快取,有的快取是為了單個處理核專用的,而有的快取是為所有處
理核共用的。為什麼這麼設計快取系統?
Answer:
The different levels are based on access speed as well as size. In general, the
closer the cache is to the CPU, the faster the access. However, faster caches are
typically more costly. Therefore, smaller and faster caches are placed local to each CPU,
and shared caches that are larger, yet slower, are shared among several different
processors.
不同層次是基於訪問速度和大小。一般來說,快取離CPU越近,訪問速度越快(越近實際上
容量也越小)。然而,更快的快取通常更昂貴.因此更小更快的快取被放置在每個CPU的本地,
較大但較慢的共享快取在幾個不同的快取之間共享處理器。
1.12 Consider an SMP system similar to the one shown in Figure 1.6. Illustrate with an
example how data residing in memory could in fact have a different value in each of the
local caches.
類似圖1-6的SMP系統,舉例說明為什麼記憶體資料有可能不同於本地快取資料。
Answer:
Say processor 1 reads data A with value 5 from main memory into its local cache.
Similarly, processor 2 reads data A into its local cache as well. Processor 1 then
updates A to 10. However, since A resides in processor 1’s local cache, the update only
occurs there and not in the local cache for processor 2.
處理器1從主記憶體讀取A的值是5,儲存到本地快取中.相似的,處理器2從主記憶體也讀取A
的值。處理器1然後將A更改成10.然而,因為A在處理器1的本地快取中,更新只在這裡而不再
處理器2的本地快取。(這裡實際上有兩個問題,一個是處理器1更新時再自己本地快取更新,
一個是處理器2的值就是舊值,得不到最新的A值。大家可以閱讀快取一致性的文章,但是還不
保證變數的可見性,詳見Java volatile)
1.13 Discuss, with examples, how the problem of maintaining coherence of cached data
manifests itself in the following processing environments:
舉例說明在下列環境下,如何維護告訴快取的資料一致性:
a. Single-processor systems
a. 單處理器系統
b. Multiprocessor systems
b. 多處理器系統
c. Distributed systems
c. 分散式系統
Answer:
In single-processor systems, the memory needs to be updated when a processor issues
updates to cached values. These updates can be performed immediately or in a lazy manner.
In a multiprocessor system, different processors might be caching the same memory location
in its local caches. When updates are made, the other cached locations need to be
invalidated or updated. In distributed systems, consistency of cached memory values is
not an issue. However, consistency problems might arise when a client caches file data.
在單處理器系統中,當處理器發出對快取值的更新時,需要更新記憶體。這些更新可以
立即執行,也可以延遲執行。在多處理器系統中,不同的處理器可能快取相同的記憶體位置
在它的本地快取中。當進行更新時,其他位置的快取需要失效或者更新。在分散式系統中
,快取記憶體值的一致性不是問題。但是,當客戶機快取檔案資料時,可能會出現一致性問題。
1.14 Describe a mechanism for enforcing memory protection in order to prevent a program
from modifying the memory associated with other programs.
請描述一種機制以加強記憶體保護,防止一個程式修改與其他程式相關的記憶體
Answer:
The processor could keep track of what locations are associated with each process and
limit access to locations that are outside of a program’s extent. Information regarding
the extent of a program’s memory could be maintained by using base and limits registers
and by performing a check for every memory access.
處理器可以跟蹤與每個程序相關聯的位置,限制對程式範圍之外的位置的訪問。關於程
序記憶體範圍的資訊可以通過使用基本暫存器和限制暫存器來維護並通過對每個記憶體地址的訪
問執行檢查。這裡有一個簡潔介紹這兩個暫存器(http://www.answers.com/Q/Base_limit_register)
1.15 Which network configuration—LAN or WAN—would best suit the following environments?
有些題有些挑戰,這道題很簡單。下面情景中適合什麼樣的網路?
a. A campus student union
a. 大學校園的學生會
b. Several campus locations across a statewide university system
b. 一個大學的多個省內校園
c. A neighborhood
c. 鄰里之間
Answer:
a. LAN
b. WAN
c. LAN or WAN
1.16 Describe some of the challenges of designing operating systems for mobile devices
compared with designing operating systems for traditional PCs.
描述為移動裝置設計作業系統與傳統pc作業系統設計相比的一些挑戰
Answer:
The greatest challenges in designing mobile operating systems include: Less storage
capacity means the operating system must manage memory carefully. The operating system
must also manage power consumption carefully. Less processing power plus fewer
processors mean the operating system must carefully apportion processors to applications.
在設計移動作業系統最大的挑戰包括: 更少的儲存容量意味著作業系統必須仔細管
理記憶體。(塞班系統Leave機制導致記憶體洩露)。作業系統還必須認真管理用電。更少的電
能和更少的處理器意味著作業系統必須更小心的分配處理器給應用
1.17 What are some advantages of peer-to-peer systems over client-server systems?
與c/s系統相比,對等系統有何優點?
Answer:
Peer-to-peer is useful because services are distributed across a collection of peers,
rather than having a single, centralized server. Peer-to-peer provides fault tolerance
and redundancy. Also, because peers constantly migrate, they can provide a level of
security over a server that always exists at a known location on the Internet.
Peer-to-peer systems can also potentially provide higher network bandwidth because you
can collectively use all the bandwidth of peers, rather than the single bandwidth that
is available to a single server.
對等系統很有用,因為服務分佈在一組對等點上,而不是擁有一個單一的集中的
伺服器。對等提供容錯功能和冗餘。而且,由於對等點不斷遷移,他們可以通過始終唯一Internet
上已知位置的伺服器提供一定級別的安全性。對等系統還可以潛在地提供更高的網路頻寬,因為你
可以集體使用所有的頻寬的對等點,而不是單一服務的。
1.18 Describe some distributed applications that would be appropriate for a
peer-to-peer system.
描述一些適合對等系統的分散式應用
Answer:
Essentially anything that provides content, in addition to existing services such
as file services, distributed directory services such as domain name services, and
distributed e-mail services.
本質上任何提供內容的東西,此外存在一些服務如檔案服務,分散式目錄服務(域名伺服器
,分散式郵箱伺服器,如POP3/IMAP伺服器等)
1.19 Identify several advantages and several disadvantages of open-source operating
systems. Include the types of people who would find each aspect to be an advantage or
a disadvantage.
確定開源作業系統的優缺點
Answer:
Open source operating systems have the advantages of having many people working
on them, many people debugging them, ease of access and distribution, and rapid update
cycles. Further, for students and programmers, there is certainly an advantage to being
able to view and modify the source code. Typically open source operating systems are
free for some forms of use, usually just requiring payment for support services.
Commercial operating system companies usually do not like the competition that open source
operating systems bring because these features are difficult to compete against. Some
open source operating systems do not offer paid support programs. Some companies avoid
open source projects because they need paid support, so that they have some entity to
hold accountable if there is a problem or they need help fixing an issue. Finally,
some complain that a lack of discipline in the coding of open source operating systems
means that backward compatibility is lacking making upgrades difficult, and that the
release cycle exacerbates these issues by forcing users to upgrade frequently.
開源作業系統的優點是開發者共同開發、除錯、易於訪問和分發、並快速更新迭代。此外,對於
學生和程式設計師來說,可以檢視和修改原始碼。典型的開源作業系統是免費提供一些形式的使用,
通常只需要為服務付費。商業作業系統公司通常不喜歡開源的競爭作業系統帶來了這些特性,
因為這些特性很難與之競爭。一些開源作業系統不提供付費的支援程式。一些公司避免開源專案
因為他們需要付費的支援,所以他們有了一些實體來如果有問題或他們需要幫助解決問題,要
否則。最後,一些人抱怨開源作業系統的編碼缺乏紀律這意味著向後相容性不足,難以進行升
級釋出週期迫使使用者頻繁升級,從而加劇了這些問題