Investigating Process Scheduling
Investigating Process Scheduling
LearningObjectives
Attheendofthislabyoushouldbeableto:
1. Describefirstcomefirstserved(FCFS)processschedulingmethod
2. Describeprioritybasedprocessschedulingmethod
3. Explainthedifferencebetweennonpreemptiveandpreemptivepriorityscheduling
mechanisms
4. DemonstratetheuseofroundrobinprocessschedulingmethodinsharingtheCPU
betweendifferentprocesses
TutorialExercises
InitialPreparation
CPUOSSimulatorsimulatesthefunctionsofatypicalmodernCPUandatypicalOperating
System(OS)bothofwhicharesupportedbytheinbuiltassemblerandcompiler.Tostartthe
simulator,doubleclickonthesimulatoricon.ThisstartsuptheCPUsimulatorsmainwindow.
Inordertobeabletodothefollowingexercises,youneedtoenteraprogramwhichtheOS
simulatorcanrun.TodothisyouneedtogotothecompilerbyclickingontheCOMPILER
buttonintheAdvancedtab.Enterthefollowingprogramintheeditwindowandcompile.
pr ogr amSi mpl eLoop
f or n = 1 t o 40
p = p + 1
next
end
WhentheaboveprogramissuccessfullycompiledyoullneedtoloaditintheCPUsmemory.
YoudothisbyclickingontheLOADINMEMORYbutton.Thiswillthentakeyoubacktothe
CPUsimulator.ToviewtheOSsimulatorsmainwindowfirstselecttheAdvancedtabandthen
clickontheOS0button.
LO1:Describefirstcomefirstserved(FCFS)processschedulingmethod.
Nowthattheprogramcodeisinsimulatorsmemoryitcanberun.Todothisyouneedto
manuallycreateoneormoreinstancesofit(realOSdoesthisautomatically).Firstmakesure
theFCFSschedulingmethodisselectedinthePoliciestab.NextselecttheProcesstaband
usingtheCREATENEWPROCESSbuttoncreatetheprocessesinTable1,intheordertheyare
listed,makingsurecorrectprioritiesareselected:
1
ProcessId Priority
P1 2
P2 4
P3 3
Table1
YoushouldseetheprocesseslistedintheREADYPROCESSESview.Thisviewrepresentsthe
ReadyQueue.Theprocessatthetopofthelististheheadofthequeueandthelastprocessin
thelististhetailofthequeue.
Now,OSsimulatorisreadytoruntheprocesses.TodothisfirstdragtheCPUSpeedslidertoa
positionaround60(thenumberisdisplayedasyoudragtheslider).Thisisrequiredsothatthe
processesrunslowlyinordertoalloweasyobservations.ClickontheSTARTbutton.You
shouldnowseeaprocessintheRUNNINGPROCESSESview.Thisviewshowsthecurrently
runningprocess.
Next,createafourthprocess,P4,withpriority1andoncethisprocessiscreatedfillinthe
requiredinformationinTable2below:
Table2
MovetheCPUSpeedslidertotheFastposition(i.e.topoftheslider)andwaituntilALL
processesruntonormalcompletion(thismaytakefewseconds).
MakeabriefcommentinthespacebelowregardingthewayFCFSschedulingworks:
Running
Process
WaitingProcesses
(firstentryisthe
headofthequeue)
2
LO2:Describeprioritybasedprocessschedulingmethod.
Forthisexerciseyouneedtoselectadifferentschedulingmethod.TodothisselectthePolicies
tab.ThenselectthePriority(static)optionandtheNonpreemptiveoption.Next,usingthe
CREATENEWPROCESSbuttoncreatethefourprocesseslistedintheTable1,oneafterthe
other,makingsurecorrectprioritiesareselected.
NowrepeatthesameprocedureasinthefirstexerciseandentertheresultsintheTable3
below:
Running
Process
WaitingProcesses
(firstentryisthe
headofthequeue)
Table3
MovetheCPUSpeedslidertotheFastposition(i.e.topoftheslider)andwaituntilALL
processesruntonormalcompletion(thismaytakefewseconds).
Makeabriefcommentinthespacebelowregardingthewaynonpreemptivepriority
schedulingworks:
LO3:Explainthedifferencebetweennonpreemptiveandpreemptivepriorityscheduling
mechanisms.
Inthisexerciseyoullagainusepriorityschedulingmethodasintheaboveexercisebutthis
timeyouneedtoselectthePreemptiveoptioninthePoliciestab.Onceagain,usingthe
CREATENEWPROCESSbuttoncreatethefourprocesseslistedintheTable1,oneafterthe
other,makingsurecorrectprioritiesareselected.
NowrepeatthesameprocedureasinthefirstexerciseandentertheresultsintheTable4
below:
3
Running
Process
WaitingProcesses
(firstentryisthe
headofthequeue)
Table4
MovetheCPUSpeedslidertotheFastposition(i.e.topoftheslider)andwaituntilall
processesruntonormalcompletion(thismaytakefewseconds).
Makeabriefcommentinthespacebelowregardingthewaypreemptivepriorityscheduling
workssummarisinghowthetwopriorityschedulingmethodsdiffer:
LO4:DemonstratetheuseofroundrobinprocessschedulingmethodinsharingtheCPU
betweendifferentprocesses.
ForthisexerciseyouneedtochangetheschedulingmethodtoRoundRobin(RR)inthePolicies
tab.AlsoselectthepriorityoptionNonemeaningprocessprioritieswillnotbeused.Nextyou
needtoselectRRTimeSliceof5ticksfromthedropdownlist.ThisisusedbytheOSsimulator
todecidehowlongaprocesswillbeallowedtorunbeforeitisreturnedtothereadyqueue.
Finally,ticktheSuspendonstatechangecheckboxundertheRUNNINGPROCESSESview.This
suspendstheprocessassoonasitisputintotherunningstatetofacilitateobservations.
NowcreatetheprocessesasspecifiedinTable5below(Tospecifyprocesslifetimeselectthe
SecsoptionandenterthetimeinsecondsintheLifetimebox.Youneedtodothisbefore
creatingtheprocessbyclickingontheCREATENEWPROCESSbutton)
ProcessId Processlifetimein
ticks
P1 10
P2 7
P3 20
Table5
4
MovetheCPUSpeedslidertotheFastposition(i.e.topoftheslider)andclicktheSTART
button.AstheprocessesmovefromReadytoRunningstatetheyaresuspended.Makeanote
oftherunningprocessandclickontheRESUMEbuttontorestartthesuspendedrunning
process.Repeatthiseachtimemakingnoteofthenextrunningprocessuntilallprocessesrun
tonormalcompletion.EnterthesequenceoftherunningprocessesinTable6below:
Elapsed
tick
count
Process
Id
Table6
Makeabriefcommentinthespacebelowregardingthewayroundrobinschedulingworks:
Note:TheOSsimulatormaintainsarunninglogwhichcanbeviewedtoobtaininformationon
thehistoryofprocessstates.ToviewthislogselecttheViewtabintheOSsimulatorwindow
andclickontheVIEWLOGbutton.Thisisforyourinformationonly.
5