大连交大os第二章作业.doc
《大连交大os第二章作业.doc》由会员分享,可在线阅读,更多相关《大连交大os第二章作业.doc(3页珍藏版)》请在冰豆网上搜索。
第二章作业
14.What’sthebiggestadvantageofimplementingthreadinuserspace?
What’sthebiggestdisadvantage?
Solution:
Thefirstadvantageisthatauser-levelpackagecanbeimplementedonanoperatingsystemthatdoesnotsupportthreads.Thesecondadvantageisthattheyalloweachprocesstohaveitsowncustomizedschedulingalgorithm.
Thedisadvantageistheproblemofhowblockingsystemcallsareimplemented.Anotherproblemisthatifathreadstartsrunning,nootherthreadinthatprocesswilleverrununlessthefirstthreadvoluntarilygivesuptheCPU.
35.MeasurementsofcertainsystemhaveshownthattheaverageprocessrunsforatimeTbeforeblockingonI/O.AprocessswitchrequiresatimeS,whichiseffectivelywasted(overhead).Forround-robinschedulingwithquantumQ,giveaformulafortheCPUefficiencyforeachofthefollowing:
(a)Q=∞CPUefficiency=T/(T+S)
(b)Q>TCPUefficiency=T/(T+S)
(c)S(d)Q=SCPUefficiency=50%
(e)Qnearly0CPUefficiencyisnearly0
36.Fivejobsarewaitingtoberun.Theirexpectedruntimesare9,6,3,5,andX.Inwhatordershouldtheyberuntominimizeaverageresponsetime?
(YouranswerwilldependonX.)
Solution:
IF(X<=3):
X,3,5,6,9
IF(X>=3ANDX<=5):
3,X,5,6,9
IF(X>=5ANDX<=6):
3,5,X,6,9
IF(X>=6ANDX<=9):
3,5,6,X,9
IF(X>=9):
3,5,6,9,X
37.FivebatchjobsAthroughE,arriveatacomputercenteratalmostthesametime.Theyhaveestimatedrunningtimesof10,6,2,4,and8minutes.Their(externallydetermined)prioritiesare3,5,2,1,and4,respectively,with5beingthehighestpriority.Foreachofthefollowingschedulingalgorithms,determinethemeanprocessturnaroundtime.Ignoreprocessswitchingoverhead.
(a)Roundrobin
(b)Priorityscheduling
(c)First-come,first-served(runinorder10,6,2,4,8)
(d)Shortestjobfirst
For(a),assumethatthesystemismultiprogrammed,andthateachjobgetsitsfairshareoftheCPU.For(b)through(d)assumethatonlyonejobatatimeruns,untilitfinishes.AlljobsarecompletelyCPUbound.
Solution:
processes
Arrivaltime
Processingtime
priority
A
0
(1)
10
3
B
0
(2)
6
5(HIGH)
C
0(3)
2
2
D
0(4)
4
1
E
0(5)
8
4
(a)Roundrobin(quantum=2)
A
2
A
A
E
A
B
C
D
E
B
D
E
B
E
A
Turnaroundtime:
A:
10+6+2+4+8=30
B:
30-4*2=22
C:
2+2+2=6
D:
2*8=16
E:
30-2=28
Meanturnaroundtime=(30+22+6+16+28)/5=80/5=20.4
(b)priorityscheduling
6
A
C
B
E
D
8
10
2
4
Turnaroundtime:
A:
6+8+10=24
B:
6
C:
24+2=26
D:
26+4=30
E:
6+8=14
Meanturnaroundtime=(24+6+26+30+14)/5=100/5=20
(c)FCFS
10
C
D
A
B
E
6
2
4
8
Turnaroundtime:
A:
10
B:
10+6=16
C:
16+2=18
D:
18+4=22
E:
22+8=30
Meanturnaroundtime=(10+16+18+22+30)/5=96/5=19.2
(d)Shortedjobfirst
10
C
D
A
B
E
6
2
4
8
Turnaroundtime:
A:
2+4+6+8+10=30
B:
2+4+6=12
C:
2
D:
2+4=6
E:
2+4+6+8=20
Meanturnaroundtime=(30+12+2+6+20)/5=70/5=14
41.Asoftreal-timesystemhasfourperiodiceventswithperiodsof50,100,200,and250mseceach.Supposethatthefoureventsrequire35,20,10,andxmsecofCPUtime,respectively.Whatisthelargestvalueofxforwhichthesystemisschedulable?
Solution:
35/50+20/100+10/200+x/250<=1max(x)=12.5