作者dacvidania (妖精鄉騎士)
看板Grad-ProbAsk
標題[理工] [OS] 99交大資聯OS第19題
時間Mon Jan 17 18:56:49 2011
19.Consider that a system scheduls three processes P1,P2,P3 using Round-robin
with time quantum=2 units of time. These three processes arrive in the order
P1,P2,P3, all ready at time 0. The three processes share a resource R, which
is protected by a mutex lock. The first process P1 runs 3 units of time, block
the resource R 3 units of time,unlocks this resource,and then runs 1 unit of
time before it completes. Let this execution of P1 be denoted by {3,R(3),1}.
The execution of the second process P2 and the third process P3 are denoted by
{2,R(1),3} and {2,R(2),2}, respectively. Let waiting queues be FIFO. which
one(s) of the following is(are) true?
A. The total number of context switches is not less than 9.
B. T2 has the longest turnaround time.
C. Decreasing P1's execution time from {3,R(3),1} to {3,R(1),1} reduces P2's
turnaround time.
D. Increasing P1's execution time from {3,R(3),1} to {4,R(3),1} reduces P2's
turnaround time.
答案給ACD
但我自己算是只有A對 @@
原本:
| P1 | P2 | P3 | P1 | P2 | P3 | P2 | P1 |
time 0 2 4 5 6 7 8 9 11 12 13
^^^ ^^^^^^^^^^^^^^^^
R(1) R(2) R(3)
time4~5 P2執行R(1)
time6~8 P3執行R(2)
time8~11 P1執行R(3)
(C)選項的結果和原本一樣,P2的turnaround time沒變
(D)選項: P2的turnaround time增加
| P1 | P2 | P3 | P1 | P2 | P3 | P2 | P1 |
time 0 2 4 6 8 10 12 13 14
不知道我哪裡算錯..
有高手可以幫我解答嗎...
感恩
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.133.127
→ ybite:關鍵似乎在mutex lock上? 01/17 19:35
→ dacvidania:我有注意到mutex,應該是一次只能1 process block的意思 01/17 19:52
→ dy957:我覺得題目意思是lock被process佔用,還沒用完時就算時間到了 01/17 20:05
→ dy957:被換成其他process也不能執行吧@@ 01/17 20:06
→ dy957:所以順序可能是P1 P2 P3 P1 P2(不能執行)P3(不能執行)... 01/17 20:06
→ dacvidania:樓上的意思是某Pi blocks resource時 其他process此時 01/17 20:34
→ dacvidania:就無法得到CPU嗎? 01/17 20:34
→ dy957:應該是可以得到CPU 但是沒辦法得到那個resource 所以不能往 01/17 20:49
→ dy957:下執行吧 要等到process釋放那個資源 其他process才能執行 01/17 20:51
→ dacvidania:那我的算法跟你的一樣...不過不會沒辦法執行耶 01/17 21:01
※ 編輯: dacvidania 來自: 114.34.133.127 (01/17 21:06)
→ dacvidania:還是我哪裡算錯... 01/17 21:19
推 aoqq12:我一開始也用你的算法 01/17 22:29
→ aoqq12:不過後來試另外個方法 我也不知道正不正確啦 01/17 22:29
→ aoqq12:就 R(3)的意思應該是持有資源還是要用CPU去執行 01/17 22:30
→ aoqq12:所以P2執行完 他要等到下次拿到CPU才會佔用resource 01/17 22:31
→ aoqq12:試一試結果是對的 01/17 22:31
→ aoqq12:所以這題應該是考觀念 不能跟I/O混淆 他只是拿共享資料 01/17 22:32
→ aoqq12:不是發出block 01/17 22:33
→ dacvidania:了解了~~謝謝 不過那個resource題目也沒說是什麼... 01/17 22:40
→ dacvidania:如果是印表機之類那就是IO了 01/17 22:42
→ aoqq12:對= = 所以看到交大的排班先直接跳過寫下一題 01/17 22:44
→ aoqq12:有時間再回來寫好了。。 01/17 22:44
→ dacvidania:總覺得他是故意要讓人家以為是IO... 01/17 22:44
→ aoqq12:不過他其實有提到是lock的 so...還是細心!!跟英文好 01/17 22:46
※ 編輯: dacvidania 來自: 114.34.133.127 (01/17 23:18)