操作系統(tǒng)概念第七版答案_第1頁
操作系統(tǒng)概念第七版答案_第2頁
操作系統(tǒng)概念第七版答案_第3頁
操作系統(tǒng)概念第七版答案_第4頁
操作系統(tǒng)概念第七版答案_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、操作系統(tǒng)概念第七版答案 【篇一:操作系統(tǒng)概念第七版答案 (含編程代碼 )】 chapter 1 1.1 in a multiprogramming and time-sharing environment,several users share the system simultaneously. this situationcan result in various security problems. a. what are two suchproblems? b. can we ensure the same degree of security in a time-sharedmach

2、ine as in a dedicated machine? explain your answer.answer: a. stealing or copying one s programs or data; using systemresources (cpu, memory, disk space, peripherals) withoutproper accounting. b. probably not, since any protection scheme devised byhumans can inevitably be broken by a human, and the

3、morecomplex the scheme, the more difficult it is to feel confident ofits correct implementation. 1.2 the issue of resource utilization shows up in differentforms in different types of operating systems. list whatresources must be managed carefully in the following settings: a. mainframe orminicomput

4、er systems b. workstations connected to serversc.handheld computersanswer: a. mainframes:memory and cpu resources, storage, networkbandwidth. b. workstations: memory and cpu resouces c. handheld computers: power consumption, memoryresources. 1.3 under what circumstances would a user be better offusi

5、ng a timesharing system rather than a pc or single-userworkstation? answer: when there are few other users, the task is large, andthe hardware is fast, time-sharingmakes sense. the full powerof the system can be brought to bear on the user s problem.the problemcan be solved faster than on a personal

6、 computer.another case occurs when lots of other users need resourcesat the same time. a personal computer is best when the job is small enough tobe executed reasonably on it and when performance issufficient to execute the prog ram to the user s satisfaction. 1.4 which of the functionalities listed

7、 below need to besupported by the operating system for the following twosettings: (a) handheld devices and (b) real-time systems. a.batch programmingb. virtual memoryc. time sharing answer: for real-time systems, the operating system needs tosupport virtual memoryand time sharing in a fair manner. f

8、or handheld systems,theoperating system needs to provide virtual memory, but doesnot need to provide time-sharing. batch programming is notnecessary in both settings. 1.5 describe the differences between symmetric andasymmetric multiprocessing.what are three advantages andone disadvantage of multipr

9、ocessor systems? answer: symmetric multiprocessing treats all processors asequals, and i/o can be processed on any cpu. asymmetricmultiprocessing has one master cpu and the remainder cpusare slaves. the master distributes tasks among the slaves, andi/o is usually done by the master only. multiproces

10、sors can save money by not duplicating powersupplies,housings, and peripherals. they can executeprograms more quickly and can have increased reliability. theyare also more complex in both hardware and software thanuniprocessor systems. 1.6 how do clustered systems differ from multiprocessorsystems?

11、what is required for two machines belonging to acluster to cooperate to provide a highly available service? answer: clustered systems are typically constructed bycombining multiple computers into a single system to performa computational task distributed across the cluster.multiprocessor systems on

12、the other hand could be a singlephysical entity comprising of multiple cpus. a clusteredsystem is less tightly coupled than a multiprocessorsystem.clustered systems communicate using messages,while processors in a multiprocessor system couldcommunicate using shared memory. in order for twomachines t

13、o provide a highly available service,the state on the two machines should be replicated and shouldbe consistently updated. when one of the machines fail, theother could then take-over the functionality of the failedmachine. 1.7 distinguish between the client-server and peer-to-peermodels of distribu

14、ted systems. answer: the client-server model firmly distinguishes the rolesof the client and server. under this model, the client requestsservices that are provided by the server. the peer-to-peermodel doesn t have such strict roles. in fact, all nodes in thesystem are considered peers and thus may

15、act as either clientsor servers - or both. a node may request a service fromanother peer, or the node may in fact provide such a service toother peers in the system. for example, let s consider a system of nodes tha t sharecooking recipes.under the client-server model, all recipes arestored with the

16、 server. if a client wishes to access a recipe, itmust request the recipe from the specified server. using thepeer-to-peer model, a peer node could ask other peer nodesfor the specified recipe.the node (or perhaps nodes) with the requested recipe couldprovide it to the requesting node. notice how ea

17、ch peer mayact as both a client (i.e. it may request recipes) and as a server(it may provide recipes.) 1.8 consider a computing cluster consisting of twonodesrunning adatabase.describe two ways in which the clustersoftware can manage access to the data on the disk. discussthe benefits and disadvanta

18、ges of each. answer: consider the following two alternatives: asymmetricclustering and parallel clustering. with asymmetric clustering,one host runs the database application with the other hostsimply monitoring it. if the server fails, the monitoring hostbecomes the active server. this is appropriat

19、e for providingredundancy. however, it does not utilize the potentialprocessing power of both hosts. with parallel clustering, thedatabase application can run in parallel on both hosts. thedifficulty implementing parallel clusters is providing someform of distributed locking mechanism for files on t

20、he shareddisk. 1.9 how are network computers different from traditionalpersonal computers? describe some usage scenarios in whichit is advantageous to use network computers. answer: a network computer relies on a centralized computerfor most of its services. it can therefore have a minimaloperating

21、system to manage its resources. a personalcomputer on the other hand has to be capable of providing allof the required functionality in a standalonemanner withoutrelying on a centralized manner. scenarios where administrative costs are high and where sharing leads to moreefficient use of resources a

22、re precisely those settings wherenetwork computers are preferred. 1.10 what is the purpose of interrupts? what are thedifferences between a trap and an interrupt? can traps begenerated intentionally by a user program? if so, for whatpurpose? answer: an interrupt is a hardware-generated change-of-flo

23、wwithin the system. an interrupt handler is summoned to dealwith the cause of the interrupt; control is then returned to theinterrupted context and instruction. a trap is a software-generated interrupt. an interrupt can be used to signal thecompletion of an i/o to obviate the need for device polling

24、. atrap can be used to call operating system routines or to catcharithmetic errors. 1.11 direct memory access is used for high-speed i/o devicesin order to avoid increasing the cpu s execution load. a. how does the cpu interface with the device to coordinatethe transfer? b. how does the cpu know whe

25、n the memoryoperations are complete? c. the cpu is allowed to execute other programs while the dmacontroller istransferring data. does this process interfere with theexecution of the user programs? if so, describe what forms ofinterference are caused. answer: the cpu can initiate a dma operation by

26、writing valuesinto special registers that can be independently accessed bythe device.the device initiates the corresponding operationonce it receives a command from the cpu. when the device isfinished with its operation, it interrupts the cpu to indicate thecompletion of the operation. both the devi

27、ce and the cpu can be accessing memorysimultaneously.the memory controller provides access to thememory bus in a fair manner to these two entities. a cpu might therefore be unable to issue memory operationsat peak speeds since it has to compete with the device in orderto obtain access to the memory

28、bus. answer: an operating system for a machine of this type wouldneed to remain in control (or monitor mode) at all times. thiscould be accomplished by two methods: a. software interpretation of all user programs (like somebasic,java, and lisp systems, for example). the softwareinterpreter would pro

29、vide, in software, what the hardware doesnot provide. b. require meant that all programs be written in high-levellanguages so that all object code is compiler-produced. thecompiler would generate (either in-line or by function calls) theprotection checks that the hardware is missing. 1.13 give two r

30、easons why caches are useful.what problemsdo they solve? what problems do they cause? if a cache canbe made as large as the device for which it is caching (forinstance, a cache as large as a disk), why not make it that largeand eliminate the device? answer: caches are useful when two or more compone

31、ntsneed to exchange data, and the components perform transfersat differing speeds.caches solve the transfer problem byproviding a buffer of intermediate speed between thecomponents. if the fast device finds the data it needs in thecache, it need not wait for the slower device. the data in thecache m

32、ust be kept consistent with the data in the components. if a omponent has a data value change, and thedatum is also in the cache, the cache must also be updated.this is especially a problem on multiprocessor systemswheremore than one process may be accessing adatum.acomponent may be eliminated by an

33、 equal-sized cache,but only if: (a) the cache and the component have equivalentstate-saving capacity (that is,if the component retains its datawhen electricity is removed, the cache must retain data aswell), and (b) the cache is affordable, because faster storagetends to be more expensive. 1.14 disc

34、uss, with examples, how the problem of maintainingcoherence of cached data manifests itself in the followingprocessing environments:a. single-processor systems b. multiprocessor systemsc. distributed systems answer: in single-processor systems, the memory needs tobe updated when a processor issues u

35、pdates to cached values.these updates can be performed immediately or in a lazymanner. in amultiprocessor system,different processors mightbe caching the same memory location in its local caches. whenupdates are made, the other cached locations need to beinvalidated or updated. in distributed system

36、s, consistency ofcached memory values is not an issue. however, consistencyproblems might arise when a client caches file data. 1.15 describe a mechanism for enforcing memory protectionin order to prevent a program from modifying the memoryassociated with other programs. answer: the processor could

37、keep track of what locations areassociated with each process and limit access to locationsthat are outside of a program s extent. informatnioregardingthe extent of a program s memory could be maintained byusing base and limits registers and by performing a check forevery memory access. 1.16 what net

38、work configuration would best suit the followingenvironments? a. a dormitory floorb. a university campus c. a state d. a nationanswer:a. a dormitory floor - a lan. b. a university campus - a lan, possible a wan for very largecampuses. c. a state - awan.d. a nation - a wan. 1.17 define the essential

39、properties of the following types ofoperating systems: a. batchb. interactivec. time sharing d. real time e. networkf. parallelg. distributedh. clusteredi. handheld【篇二:操作系統(tǒng)概念第七版 4-6 章課后題答案 (中文版)】舉兩個多線程程序設(shè)計的例子來說明多線程不比單線程方案提高性能答:1)任何形式的順序程序?qū)€程來說都不是一個好的形式。例如一個計算個人報酬的程序。2)另外一個例子是一個 “空殼 ”程序,如 c-shell 和 k

40、orn shell 。這種程序必須密切檢測其本身的工作空間。如打開的文件、環(huán)境變量和當(dāng)前工作目錄。4.2 描述一下線程庫采取行動進(jìn)行用戶級線程上下文切換的過程答:用戶線程之間的上下文切換和內(nèi)核線程之間的相互轉(zhuǎn)換是非常相似的。但它依賴于線程庫和怎樣把用戶線程指給內(nèi)核程序。一般來說,用戶線程之間的上下文切換涉及到用一個用戶程序的輕量級進(jìn)程( lwp )和用另外一個線程來代替。這種行為通常涉及到寄存器的節(jié)約和釋放。4.3 在哪些情況下使用多內(nèi)核線程的多線程方案比單處理器系統(tǒng)的單個線程方案提供更好的性能。 答:當(dāng)一個內(nèi)核線程的頁面發(fā)生錯誤時,另外的內(nèi)核線程會用一種有效的方法被轉(zhuǎn)換成使用交錯時間。另一方

41、面,當(dāng)頁面發(fā)生錯誤時,一個單一線程進(jìn)程將不能夠發(fā)揮有效性能。因此,在一個程序可能有頻繁的頁面錯誤或不得不等待其他系統(tǒng)的事件的情況下,多線程方案會有比單處理器系統(tǒng)更好的性能。 4.4 以下程序中的哪些組成部分在多線程程序中是被線程共享的? a.寄存值 b. 堆內(nèi)存 c.全局變量d.棧內(nèi)存 答:一個線程程序的線程共享堆內(nèi)存和全局變量,但每個線程都有屬于自己的一組寄存值和棧內(nèi)存。45 一個采用多用戶線程的多線程方案在多進(jìn)程系統(tǒng)中能夠取得比在單處理器系統(tǒng)中更好的性能嗎?答:一個包括多用戶線程的多線程系統(tǒng)無法在多處理系統(tǒng)上同時使用不同的處理器。操作系統(tǒng)只能看到一個單一的進(jìn)程且不會調(diào)度在不同處理器上的不同

42、進(jìn)程的線程。因此,多處理器系統(tǒng)執(zhí)行多個用戶線程是沒有性能優(yōu)勢的。4.6 就如 4.5.2 章節(jié)描述的那樣, linux 沒有區(qū)分進(jìn)程和線程的能力。且 linux 線程都 是用相同的方法:允許一個任務(wù)與一組傳遞給 clone() 系統(tǒng)調(diào)用的標(biāo)志的進(jìn)程或線程。但許多操作系統(tǒng),例如 windows xp 和 solaris , 對進(jìn)程和線程都是一視同仁?;旧希@種使用 notation 的系統(tǒng),一個進(jìn)程的數(shù)據(jù)結(jié)構(gòu)包括一個指向?qū)儆谶M(jìn)程的不同線程的指針。區(qū)別建模過程和在內(nèi)核中線程的兩種方法。答:一方面,進(jìn)程和線程被視為相似實體的系統(tǒng)中,有些系統(tǒng)代碼可以簡化。例如,一個調(diào)度器可以在平等的基礎(chǔ)上考慮不同的

43、進(jìn)程和線程,且不需要特殊的代碼,在調(diào)度中審查有關(guān)線程的進(jìn)程。另一方面,這種統(tǒng)一會使進(jìn)程資源限制更加困難。相反,一些額外的復(fù)雜性被需要,用來確定哪個線程與哪個進(jìn)程一致和執(zhí)行重復(fù)的計數(shù)任務(wù)。4.7 由 4.11 給出的程序使用了 pthread 的應(yīng)用程序編程接口( api ),在程序的第 c 行和第 p 行分別會輸出什么? 答:c 行會輸出 5,p 行會輸出 0.4.8 考慮一個多處理器系統(tǒng)和用多線程對多線程模式編寫的多線程程序。讓程序中的用戶線程數(shù)量多于系統(tǒng)中的處理器的數(shù)量,討論下列情況下的性能意義: a.由程序分配的內(nèi)核線程的數(shù)量比處理器少b. 由程序分配的內(nèi)核線程的數(shù)量與處理器相同c. 由

44、程序分配的內(nèi)核線程的數(shù)量大于處理器數(shù)量但少于用戶線程的數(shù)量答:當(dāng)內(nèi)核線程的數(shù)量少于處理器時,一些處理器將仍然處于空閑狀態(tài)。因為,調(diào)度圖中只有內(nèi)核線程的處理器,而不是用戶線程的處理器。當(dāng)程序分配的內(nèi)核線程的數(shù)量與處理器相同時,那么有可能所有處理器將同時使用。然而,當(dāng)一個內(nèi)核塊內(nèi)的內(nèi)核(因頁面錯誤或同時援引系統(tǒng)調(diào)用)相應(yīng)的處理器將閑置。當(dāng)由程序分配的內(nèi)核線程的數(shù)量大于處理器數(shù)量時,封鎖一個內(nèi)核線程并調(diào)出,換入另一個準(zhǔn)備執(zhí)行的內(nèi)核線程。因此,增加多處理器系統(tǒng)的利用率。第五章 cpu 調(diào)度5.1 為什么對調(diào)度來說,區(qū)分 i/0 限制的程序和 cpu 限制的程序是重要的?答:i/0 限制的程序有在運(yùn)行

45、i/o 操作前只運(yùn)行很少數(shù)量的計算機(jī)操作的性質(zhì)。這種 程序一般來說不會使用很多的 cpu 。另一方面, cpu 限制的程序利用整個的時間片,且不做任何阻礙 i/o 操作的工作。因此,通過給i/o 限制的程序優(yōu)先權(quán)和允許在 cpu 限制的程序之前運(yùn)行,可以很好的利用計算機(jī)資源。 5.2 討論以下各對調(diào)度標(biāo)準(zhǔn)在某種背景下會有的沖突 a.cpu 利用率和響應(yīng)時間 b.平均周轉(zhuǎn)時間和最大等待時間 c.i/o 設(shè)備利用率和 cpu 利用率 答:a.cpu 利用率和響應(yīng)時間:當(dāng)經(jīng)常性的上下文切換減少到最低時,cpu 利用率增加。通過減少使用上下文切換程序來降低經(jīng)常性的上下文切換。但這樣可能會導(dǎo)致進(jìn)程響應(yīng)時

46、間的增加。 b.平均周轉(zhuǎn)時間和最大等待時間:通過最先執(zhí)行最短任務(wù)可以使平均周轉(zhuǎn)時間最短。然而,這種調(diào)度策略可能會使長時間運(yùn)行的任務(wù)永遠(yuǎn)得不到調(diào)度且會增加他們的等待時間。c.i/o 設(shè)備利用率和 cpu 利用率: cpu 利用率的最大化可以通過長時間運(yùn)行 cpu 限制的任務(wù)和同時不實行上下文切換。 i/o 設(shè)備利用率的最大化可以通過盡可能調(diào)度已經(jīng)準(zhǔn)備好的 i/o 限制的任務(wù)。因此,導(dǎo)致上下文切 換 。5.3 考慮指數(shù)平均公式來預(yù)測下一次 cpu 區(qū)間的長度,使用以下參數(shù)值會有什么影響? a.a=0 和 t=100 毫秒 b.a=0.99 和 t=10 毫秒答:當(dāng) a=0 和 t=100 毫秒時,

47、公式總是會預(yù)測下一次的 cpu 區(qū)間為100 毫秒。當(dāng)a=0.99 和 t=10 毫秒時,進(jìn)程最近的行為是給予更高的重量和過去的就能成相比。因此,調(diào)度算法幾乎是無記憶的,且簡單預(yù)測未來區(qū)間的長度為下一次的 cpu 執(zhí)行的時間片。 5.4 考慮下列進(jìn)程集,進(jìn)程占用的 cpu 區(qū)間長度以毫秒來計算:進(jìn)程 區(qū)間時間 優(yōu)先級 p1 10 3 p2 1 1 p3 2 3 p4 1 4 p5 5 2假設(shè)在時刻 0 以進(jìn)程 p1,p2,p3,p4,p5 的順序到達(dá)。 a.畫出 4 個 gantt 圖分別演示用 fcfs 、sjf 、非搶占優(yōu)先級(數(shù)字小代表優(yōu)先級高)和 rr (時間片 1)算法調(diào)度時進(jìn)程的執(zhí)

48、行過程。b.在 a 里每個進(jìn)程在每種調(diào)度算法下的周轉(zhuǎn)時間是多少?c. 在 a 里每個進(jìn)程在每種調(diào)度算法下的等待時間是多少?d.在 a 里哪一種調(diào)度算法的平均等待時間對所有進(jìn)程而言最小? 答:a.甘特圖略 b. 周轉(zhuǎn)時間d.sjf5.5 下面哪些算法會引起饑餓a.先來先服務(wù)b.最短工作優(yōu)先調(diào)度c. 輪換法調(diào)度 d.優(yōu)先級調(diào)度答:最短工作優(yōu)先調(diào)度和優(yōu)先級調(diào)度算法會引起饑餓 5.6 考慮 rr 調(diào)度算法的一個變種,在這個算法里,就緒隊列里的項是指向 pcb 的指針。 a.如果把兩個指針指向就緒隊列中的同一個進(jìn) 程,會有什么效果? b. 這個方案的主要優(yōu)點和缺點是什么?c. 如何修改基本的 rr 調(diào)度

49、算法,從而不用兩個指針達(dá)到同樣的效果?答.a.實際上,這個過程將會增加它的優(yōu)先權(quán),因為通過經(jīng)常得到時間它能夠優(yōu)先得以運(yùn)行。b.優(yōu)點是越重要的工作可以得到更多的時間。也就是說,優(yōu)先級越高越先運(yùn)行。然而,結(jié)果將由短任務(wù)來承擔(dān)。c.分配一個更長的時間給優(yōu)先級越高的程序。換句話說,可能有兩個或多個時間片在rr 調(diào)度中。 5.7 考慮一個運(yùn)行十個 i/o 限制任務(wù)和一個 cpu 限制任務(wù)的系統(tǒng)。假設(shè),i/o 限制任務(wù)一次分配給一個 i/o 操作 1 毫秒的 cpu 計算,但 每個 i/o 操作的完成需要 10 毫秒。同時,假設(shè)間接的上下文切換要0.1 毫秒,所有的進(jìn)程都是長進(jìn)程。對一個 rr 調(diào)度來說,

50、以下情況時cpu 的利用率是多少: a.時間片是 1 毫秒 b.時間片是 10 毫秒 答:a.時間片是 1 毫秒:不論是哪個進(jìn)程被調(diào)度,這個調(diào)度都會為每一次的上下文切換花費(fèi)一個 0.1 毫秒的上下文切換。 cpu 的利用率是 1/1.1*100=92% 。b.時間片是 10 毫秒:這 i/o 限制任務(wù)會在使用完 1 毫秒時間片后進(jìn)行一次上下文切換。這個時間片要求在所有的進(jìn)程間都走一遍,因此,10*1.1+10.1( 因為每個 i / o 限定任務(wù)執(zhí)行為 1 毫秒,然后承擔(dān)上下文切換的任務(wù),而 cpu 限制任務(wù)的執(zhí)行 10 毫秒在承擔(dān)一個上下文切換之前 ) 。因此, cpu 的利用率是 20、2

51、1.1*100=94% 。5.8 考慮一個實施多層次的隊列調(diào)度系統(tǒng)。什么策略能夠使一個計算機(jī)用戶使用由用戶進(jìn)程分配的最大的 cpu 時間片。答:這個程序可以使分配給它的沒有被完全利用的 cpu 時間最大化。它可以使用分配給它的時間片中的絕大部分,但在時間片結(jié)束前放棄 cpu ,因此提高了與進(jìn)程有關(guān)的優(yōu)先級。5.10 解釋下面調(diào)度算法對短進(jìn)程編程度上的區(qū)別: a.fcfs b.rrc多級反饋隊列 答:a.fcfs- 區(qū)別短任務(wù)是因為任何在長任務(wù)后到達(dá)的短任務(wù)都將會有很長的等待時間。 b.rr- 對所有的任務(wù)都是能夠相同的(給它們 相同的 cpu 時間區(qū)間),所以,短任務(wù)可以很快的離開系統(tǒng),只要它

52、們可以先完成。 c. 多級反饋隊列和 rr調(diào)度算法相似 它們不會先選擇短任務(wù)。5.11 用 window xp 的調(diào)度算法,下列什么是數(shù)字優(yōu)先的線程。a.相對優(yōu)先級的值為 realtime_priority_class 的屬于實體優(yōu)先類型的線程 b.相對優(yōu)先級的值為 normal_priority_class 的屬于 normal類型的線程 c.相對優(yōu)先級的值為 high_priority_class 的屬于above_normal 類型的線程 答:a.26 b.8 c.14512 考慮在 solaris 操作系統(tǒng)中的為分時線程的調(diào)度算法:a:一個優(yōu)先權(quán)是 10 的線程的時間片是多少?優(yōu)先權(quán)是

53、 55 的呢?b: 假設(shè)優(yōu)先權(quán)是 35 的一個線程用它所有的時間片在沒有任何阻止的情況下,這調(diào)度算法將會分配給這個線程什么樣新的優(yōu)先權(quán)?c: 假設(shè)一個優(yōu)先權(quán)是 35 的線程在時間片結(jié)束前阻止 i/o 操作。這調(diào)度算法將會分配給這個線程什么樣新的優(yōu)先權(quán)?答:a:160 和 40 b:35 c :545.13 傳統(tǒng) unix 調(diào)度在優(yōu)先數(shù)和優(yōu)先級間成反比關(guān)系:數(shù)字越高,優(yōu)先權(quán)越低。該調(diào)度進(jìn)程利用下面的方程重新計算進(jìn)程的優(yōu)先權(quán)一次一秒: 優(yōu)先權(quán) = (最近 cpu 使用率 / 2 ) +基本數(shù) 這里的基本數(shù) = 60,最近的 cpu 使用率是指一個表明優(yōu)先權(quán)從上一次重新計算后開始進(jìn)程被 cpu 使用

54、的情況。假設(shè)最近進(jìn)程 p1 的 cpu 使用率是 40 個,p2 是 18 ,p3 是 10。當(dāng)優(yōu)先權(quán)重新計算后這三個進(jìn)程的新的優(yōu)先權(quán)是什么?在此信息的基礎(chǔ)上,傳統(tǒng) unix 的調(diào)度會不會提高或降低 cpu 限制的進(jìn)程的相對優(yōu)先權(quán)?答 : 分配給這些進(jìn)程的優(yōu)先權(quán)分別是 80,69 和 65.這調(diào)度降低了cpu 限制的進(jìn)程的相對優(yōu)先權(quán)?!酒翰僮飨到y(tǒng)概念第七版 7-9 章課后題答案 (中文版)】.1 所示的交通死鎖。a. 證明這個例子中實際上包括了死鎖的四個必要條件。 b. 給出一個簡單的規(guī)則用來在這個系統(tǒng)中避免死鎖。a. 死鎖的四個必要條件 : (1)互斥;( 2)占有并等待;( 3)非搶占

55、;(4)循環(huán)等待。 互斥的條件是只有一輛車占據(jù)道路上的一個空間位置。占有并等待表示一輛車占據(jù)道路上的位置并且等待前進(jìn)。一輛車不能從道路上當(dāng)前的位置移動開(就是非搶占)。最后就是循環(huán)等待,因為每個車正等待著隨后的汽車向前發(fā)展。循環(huán)等待的條件也很容易從圖形中觀察到。 b. 一個簡單的避免這種的交通死鎖的規(guī)則是,汽車不得進(jìn)入一個十字路口如果明確地規(guī)定,這樣就不會產(chǎn)生相交。 7.2考慮如下的死鎖可能發(fā)生在哲學(xué)家進(jìn)餐中,哲學(xué)家在同個時間獲得筷子。討論此種情況下死鎖的四個必要條件的設(shè)置。討論如何在消除其中任一條件來避免死鎖的發(fā)生。死鎖是可能的,因為哲學(xué)家進(jìn)餐問題是以以下的方式滿足四個必要條件:1)相斥所需

56、的筷子, 2 )哲學(xué)家守住的筷子在手,而他們等待其他筷子, 3 )沒有非搶占的筷子,一個筷子分配給一個哲學(xué)家不能被強(qiáng)行拿走, 4 )有可能循環(huán)等待。死鎖可避免克服的條件方式如下: 1 )允許同時分享筷子, 2 )有哲學(xué)家放棄第一雙筷子如果他們無法獲得其他筷子, 3 )允許筷子被強(qiáng)行拿走如果筷子已經(jīng)被一位哲學(xué)家了占有了很長一段時間 4 )實施編號筷子,總是獲得較低編號的筷子,之后才能獲得較高的編號的筷子。7.3一種可能以防止死鎖的解決辦法是要有一個單一的,優(yōu)先于任何其他資源的資源。例如,如果多個線程試圖訪問同步對象 a?e ,那么就可能發(fā)生死鎖。(這種同步對象可能包括互斥體,信號量,條件變量等)

57、,我們可以通過增加第六個對象來防止死鎖。每當(dāng)一個線程希望獲得同步鎖定給對象 a? ? ?e ,它必須首先獲得對象 f 的鎖.該解決方案被稱為遏制:對象 a? ? ?e 的鎖內(nèi)載對象 f 的鎖。 對比此方案的循環(huán)等待和 section7.4.4 的循環(huán)等待。這很可能不是一個好的解決辦法,因為它產(chǎn)生過大的范圍。盡可能在狹隘的范圍內(nèi)定義死鎖政策會更好。7.4對下列問題對比循環(huán)等待方法和死鎖避免方法 (例如銀行家算法 ): a.運(yùn)行費(fèi)用b.系統(tǒng)的吞吐量死鎖避免方法往往會因為追蹤當(dāng)前資源分配的成本從來增加了運(yùn)行費(fèi)用。然而死鎖避免方法比靜態(tài)地防止死鎖的形成方法允許更多地并發(fā)使用資源。從這個意義上說,死鎖避免方案可以增加系統(tǒng)的吞吐量。7.5在一個真實的計算機(jī)系統(tǒng)中,可用的資源和進(jìn)程命令對資源的要求都不會持續(xù)很久是一致的長期(幾個月)。資源會損壞或被替換,新的進(jìn)程會進(jìn)入和離開系統(tǒng),新的資源會被購買和添加到系統(tǒng)中。如果用銀行

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論