CITS2002SystemsProgramming
1 next→ CITS2002 CITS2002schedule
ProcessesThefundamentalactivityofanoperatingsystemisthecreation,management,andterminationofprocesses.
Whatisaprocess?Naively:
aprogramunderexecution,the"animated"existenceofaprogram,anidentifiableentityexecutedonaprocessorbytheoperatingsystem.
Moreparticularly,weconsiderhowtheoperatingsystemitselfviewsaprocess:
asanexecutableinstanceofaprogram,astheassociateddataoperateduponbytheprogram(variables,temporaryresults,external(file)storage,...),andastheprogram'sexecutioncontext.
Itisaclearrequirementofmodernoperatingsystemsthattheyenablemanyprocessestoexecuteefficiently,bymaximisingtheiruseoftheprocessor,bysupportinginter-processcommunication,andbymaintainingreasonableresponsetime.
Thisisanongoingchallenge:ashardwareimproves,itis"consumed"bylarger,"hungrier"piecesofinterlinkedsoftware.
CITS2002SystemsProgramming,Lecture7,p1,16thAugust2021.
CITS2002SystemsProgramming
←prev 2 next→ CITS2002 CITS2002schedule
ProcessStatesWecanviewtheprocessfromtwopointsofview:thatoftheprocessor,andthatoftheprocessitself.
Theprocessor'sviewissimple:theprocessor'sonlyroleistoexecutemachineinstructionsfrommainmemory.Overtime,theprocessorcontinuallyexecutesthesequenceofinstructionsindicatedbytheprogramcounter(PC).
Theprocessorisunawarethatdifferentsequencesofinstructionshavealogicalexistence,thatdifferentsequencesunderexecutionarereferredtoasprocessesortasks.
Fromtheprocess'spointofview,itiseitherbeingexecutedbytheprocessor,oritiswaitingtobeexecuted(forsimplicityhere,weconsiderthataterminatedprocessnolongerexists).
We'veidentifiedtwopossibleprocessstatesthataprocessmaybeinatanyonetime:RunningandReady.
Question:Canaprocessdetermineinwhatstateitis?
CITS2002SystemsProgramming,Lecture7,p2,16thAugust2021.
CITS2002SystemsProgramming
←prev 3 next→ CITS2002 CITS2002schedule
ProcessTransitionsTheoperatingsystem'sroleistomanagetheexecutionofexistingandnewlycreatedprocessesbymovingthembetweenthetwostatesuntiltheyfinish.
Sowehaveasimplemodelconsistingoftworecurringsteps:
1. NewlycreatedprocessesarecreatedandmarkedasReady,andarequeuedtorun.
2. ThereisonlyeverasingleprocessintheRunningstate.Itwilleither:
completeitsexecutionandterminate(exit),or
besuspended(byitselforbytheoperatingsystem),bemarkedasReady,andbeagainqueuedtorun.
OneoftheotherReadyprocessesisthencommenced(orresumed).
Heretheoperatingsystemhastheroleofadispatcher-dispatchingworkfortheprocessoraccordingtosomedefinedpolicyaddressingacombinationoffairness,priority,apparent"interactivity",...
___________Forsimplicity(ofbothunderstandingandimplementation)modernoperatingsystemssupporttheidleprocesswhichisalwaysreadytorun,andneverterminates.
CITS2002SystemsProgramming,Lecture7,p3,16thAugust2021.
CITS2002SystemsProgramming
←prev 4 next→ CITS2002 CITS2002schedule
TheSimple2-stateProcessModelAswegenerallyhavemorethantwoprocessesavailable,theReadystateisimplementedasaqueueofavailableprocesses:
Whenschedulingisdiscussed,wewillintroduceprocessprioritieswhendecidingwhichReadyprocessshouldbethenexttoexecute.
CITS2002SystemsProgramming,Lecture7,p4,16thAugust2021.
CITS2002SystemsProgramming
←prev 5 next→ CITS2002 CITS2002schedule
ProcessCreationInsupportingthecreationofanewprocess,theoperatingsystemmustallocateresourcesbothfortheprocessandtheoperatingsystemitself.
Theprocess(programunderexecution)willrequireaportionoftheavailablememorytocontainits(typically,read-only)instructionsandinitialdatarequirements.Astheprocessexecutes,itwilldemandadditionalmemoryforitsexecutionstackanditsheap.
Theoperatingsystem(asdispatcher)willneedtomaintainsomeinternalcontrolstructurestosupportthemigrationoftheprocessbetweenstates.
Wheredonewprocessescomefrom?
an"under-burdened"operatingsystemmaytakenewprocessrequestsfromabatchqueue.auserloggingonataterminalusuallycreatesaninteractivecontrolorencapsulatingprocess(shellorcommandinterpreter).anexistingprocessmayrequestanewprocess,theoperatingsystemitselfmaycreateaprocessafteranindirectrequestforservice(tosupportnetworking,printing,...)
Differentoperatingsystemssupportprocesscreationindifferentways.
byrequestingthatanexistingprocessbeduplicated(alafork()callinLinuxandmacOS),byinstantiatingaprocess'simagefromanamedlocation,typicallytheprogram'simagefromadiskfile(alathespawn()callin(old)DEC-VMSandtheCreateProcess()callinWindows).
CITS2002SystemsProgramming,Lecture7,p5,16thAugust2021.
CITS2002SystemsProgramming
←prev 6 next→ CITS2002 CITS2002schedule
ProcessTerminationStallingssummarisestypicalreasonswhyaprocesswillterminate:
normaltermination,executiontime-limitexceeded,aresourcerequestedisunavailable,anarithmeticerror(divisionbyzero),amemoryaccessviolation,aninvalidrequestofmemoryoraheldresource,anoperatingsystemorparentprocessrequest,oritsparentprocesshasterminated.
Theseandmanyothereventsmayeitherterminatetheprocess,orsimplyreturnanerrorindicationtotherunningprocess.Inallcases,theoperatingsystemwillprovideadefaultactionwhichmayormaynotbeprocesstermination.
Itisclearthatprocessterminationmayberequested(oroccur)whenaprocessiseitherRunningorReady.Theoperatingsystem(dispatcher)musthandlebothcases.
Ifaprocessisconsideredasa(mathematical)function,itsreturnresult,consideredasaBooleanorintegralresult,isgenerallymadeavailableto(some)otherprocesses.
CITS2002SystemsProgramming,Lecture7,p6,16thAugust2021.
CITS2002SystemsProgramming
←prev 7 next→ CITS2002 CITS2002schedule
TimerInterruptsWhydoesaprocessmovefromRunningtoReady?
Theoperatingsystemmustmeetthetwogoalsoffairnessamongstprocessesandmaximaluseofresources(here,theprocessorand,soon,memory).
Thefirstiseasilymet:enableeachprocesstoexecuteforapredeterminedperiodbeforemovingtheRunningprocesstotheReadyqueue.
Ahardwaretimerwillperiodicallygenerateaninterrupt(say,every10milliseconds).Betweentheexecutionofanytwoinstructions,theprocessorwill"lookfor"interrupts.Whenthetimerinterruptoccurs,theprocessorwillbeginexecutionoftheinterrupthandler.
Thehandlerwillincrementandexaminetheaccumulatedtimeofthecurrentlyexecutingprocess,andeventuallymoveitfromRunningtoReady.
Themaximumtimeaprocessispermittedtorunisoftentermedthetimequantum.
CITS2002SystemsProgramming,Lecture7,p7,16thAugust2021.
CITS2002SystemsProgramming
←prev 8 next→ CITS2002 CITS2002schedule
TheBlockingofProcessesTheabovescenarioissimpleandfairifallReadyprocessesarealwaystrulyreadytoexecute.
However,theexistenceofprocesseswhichcontinuallyexecutetotheendoftheirtimequanta,oftentermedcompute-boundprocesses,israre.
Moregenerally,aprocesswillrequestsomeinputoroutput(I/O)fromacomparativelyslowsource(suchasadiskdrive,tape,keyboard,mouse,orclock).Evenifthe"reply"totherequestisavailableimmediately,asynchronouscheckofthiswilloftenexceedtheremainderoftheprocess'stimequantum.Ingeneraltheprocesswillhavetowaitfortherequesttobesatisfied.
TheprocessshouldnolongerbeRunning,butitisnotReadyeither:atleastnotuntilitsI/Orequestcanbesatisfied.
Wenowintroduceanewstatefortheoperatingsystemtosupport,Blocked,todescribeprocesseswaitingforI/Orequeststobesatisfied.AprocessrequestingI/Owill,ofcourse,requesttheoperatingsystemtoundertaketheI/O,buttheoperatingsystemsupportsthisasthreeactivities:
1. requestingI/Otoorfromthedevice,2. movingtheprocessfromRunningtoBlocked,3. preparingtoacceptaninterruptwhenI/Ocompletes.
(Verysimply)whentheI/Ocompletioninterruptoccurs,therequestingprocessismovedfromBlockedtoReady.
Adegeneratecaseofblockingoccurswhenaprocesssimplywishestosleepforagivenperiod.Weconsidersucharequestas"blockinguntilatimerinterrupt",andhavetheoperatingsystemhandleitthesameway.
CITS2002SystemsProgramming,Lecture7,p8,16thAugust2021.
CITS2002SystemsProgramming
←prev 9 next→ CITS2002 CITS2002schedule
The5-StateModelofProcessExecutionAtthispoint,Stallingsintroduceshis5-statemodel:
Thisincludestwonewstates:
Newfornewlycreatedprocesseswhichhaven'tyetbeenadmittedtotheReadyqueueforresourcingreasons;Exitforterminatedprocesseswhosereturnresultorresourcesmayberequiredbyotherprocesses,e.g.forpost-processaccounting.
Eachofthesestates,exceptforRunning,islikelyto'hold'morethanoneprocess(i.e.theremaybemorethanoneprocessinoneofthesestates).
Ifaqueueofprocessesisnotalwaysorderedinafirst-come-first-served(FCFS)manner,thenapriorityorschedulingmechanismisnecessary.
CITS2002SystemsProgramming,Lecture7,p9,16thAugust2021.
CITS2002SystemsProgramming
←prev 10 next→ CITS2002 CITS2002schedule
SupportingMultipleBlockedStatesWhennotificationofanI/Oortimercompletionoccurs,thesimplestqueuingmodelrequirestheoperatingsystemtoscanitsBlockedqueuetodeterminewhichprocess(es)requested,orareinterestedin,theevent:
CITS2002SystemsProgramming,Lecture7,p10,16thAugust2021.
CITS2002SystemsProgramming
←prev 11 next→ CITS2002 CITS2002schedule
SupportingMultipleBlockedStates,continuedAbetterschemeistomaintainaqueueforeachpossibleeventtype.Whenaneventoccurs,its(shorter)queueisscannedmorequickly:
Atypicalexamplewouldhaveonequeueforprocessesblockedondisk-drive-1,anotherblockedondisk-drive-2,anotherblockedonthekeyboard......
Then,whenaninterruptoccurs,it'squicktodeterminewhichprocess(es)shouldbeunblocked,andmovedtoReady.
CITS2002SystemsProgramming,Lecture7,p11,16thAugust2021.
CITS2002SystemsProgramming
←prev 12 next→ CITS2002 CITS2002schedule
TheDispatchingRoleofOperatingSystemsAsshouldnowbeclear,thisviewoftheoperatingsystemasadispatcherinvolvesthemovingofprocessesfromoneexecutionstatetoanother.
Theprocess'sstateisreflectedbywhereitresides,althoughitsstatewillalsorecordmuchotherinformation.
Thepossiblestatetransitionsthatwehavenowdiscussedare:
Null→New anewprocessisrequested.
New→Ready resourcesareallocatedforthenewprocess.
Ready→Running aprocessisgivenatimequantum.
Running→Ready aprocess'sexecutiontimequantumexpires.
Running→Blocked aprocessrequestsslowI/O.
Blocked→Ready anI/OinterruptsignalsthatI/Oisready.
Running→Exit normalorabnormalprocesstermination.
ReadyorBlocked→Exit externalprocessterminationrequested.
CITS2002SystemsProgramming,Lecture7,p12,16thAugust2021.
CITS2002SystemsProgramming
←prev 13 next→ CITS2002 CITS2002schedule
SuspensionofProcessesRecallthattheprocessorismuchfasterthanI/O.Asaconsequence,itisquitepossibleforallprocessestobeblockedonI/Orequests,whentheprocessorwillbeidlemostofthetimewhilewaitingforI/Ointerrupts.
Question:Howtogetmoreexecutingprocesses,giventhatresourcessuchasmemoryarefinite?
Toenablemoretrueworktobeperformedbytheprocessor,wecouldprovidemorememorytosupporttherequirementsofmoreprocesses.
Butasidefromtheexpense,providingmorememorytendstoencouragelargerprocesses,not(ingeneral)bettersupportformoreprocesses.
CITS2002SystemsProgramming,Lecture7,p13,16thAugust2021.
CITS2002SystemsProgramming
←prev 14 CITS2002 CITS2002schedule
SwappingofProcessesAnothersolutionisswapping:moving(partof)aprocess'smemorytodiskwhenitisnotneeded.
WhennoneoftheprocessesinmainmemoryisReady,theoperatingsystemswapsthememoryofsomeoftheBlockedprocessestodisktorecoversomememoryspace.Suchprocessesaremovedtoanewstate:theSuspendstate,aqueueofprocessesthathavebeen"kickedout"ofmainmemory:
Ifdesperateforevenmorememory,theoperatingsystemcansimilarlyreclaimmemoryfromReadyprocesses.Whenmemorybecomesavailable,theoperatingsystemmaynowresumeexecutionofaprocessfromSuspend,oradmitaprocessfromNewtoReady.
CITS2002SystemsProgramming,Lecture7,p14,16thAugust2021.