作者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
1F:→ ybite:关键似乎在mutex lock上? 01/17 19:35
2F:→ dacvidania:我有注意到mutex,应该是一次只能1 process block的意思 01/17 19:52
3F:→ dy957:我觉得题目意思是lock被process占用,还没用完时就算时间到了 01/17 20:05
4F:→ dy957:被换成其他process也不能执行吧@@ 01/17 20:06
5F:→ dy957:所以顺序可能是P1 P2 P3 P1 P2(不能执行)P3(不能执行)... 01/17 20:06
6F:→ dacvidania:楼上的意思是某Pi blocks resource时 其他process此时 01/17 20:34
7F:→ dacvidania:就无法得到CPU吗? 01/17 20:34
8F:→ dy957:应该是可以得到CPU 但是没办法得到那个resource 所以不能往 01/17 20:49
9F:→ dy957:下执行吧 要等到process释放那个资源 其他process才能执行 01/17 20:51
10F:→ dacvidania:那我的算法跟你的一样...不过不会没办法执行耶 01/17 21:01
※ 编辑: dacvidania 来自: 114.34.133.127 (01/17 21:06)
11F:→ dacvidania:还是我哪里算错... 01/17 21:19
12F:推 aoqq12:我一开始也用你的算法 01/17 22:29
13F:→ aoqq12:不过後来试另外个方法 我也不知道正不正确啦 01/17 22:29
14F:→ aoqq12:就 R(3)的意思应该是持有资源还是要用CPU去执行 01/17 22:30
15F:→ aoqq12:所以P2执行完 他要等到下次拿到CPU才会占用resource 01/17 22:31
16F:→ aoqq12:试一试结果是对的 01/17 22:31
17F:→ aoqq12:所以这题应该是考观念 不能跟I/O混淆 他只是拿共享资料 01/17 22:32
18F:→ aoqq12:不是发出block 01/17 22:33
19F:→ dacvidania:了解了~~谢谢 不过那个resource题目也没说是什麽... 01/17 22:40
20F:→ dacvidania:如果是印表机之类那就是IO了 01/17 22:42
21F:→ aoqq12:对= = 所以看到交大的排班先直接跳过写下一题 01/17 22:44
22F:→ aoqq12:有时间再回来写好了。。 01/17 22:44
23F:→ dacvidania:总觉得他是故意要让人家以为是IO... 01/17 22:44
24F:→ aoqq12:不过他其实有提到是lock的 so...还是细心!!跟英文好 01/17 22:46
※ 编辑: dacvidania 来自: 114.34.133.127 (01/17 23:18)