+ All Categories
Home > Documents > Processes CITS2002 Systems Programming

Processes CITS2002 Systems Programming

Date post: 04-Nov-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
14
CITS2002 Systems Programming 1 next CITS2002 CITS2002 schedule Processes The fundamental activity of an operating system is the creation, management, and termination of processes. What is a process? Naively: a program under execution, the "animated" existence of a program, an identifiable entity executed on a processor by the operating system. More particularly, we consider how the operating system itself views a process: as an executable instance of a program, as the associated data operated upon by the program (variables, temporary results, external (file) storage, ...), and as the program's execution context . It is a clear requirement of modern operating systems that they enable many processes to execute efficiently, by maximising their use of the processor, by supporting inter-process communication, and by maintaining reasonable response time. This is an ongoing challenge: as hardware improves, it is "consumed" by larger, "hungrier" pieces of interlinked software. CITS2002 Systems Programming, Lecture 7, p1, 16th August 2021.
Transcript
Page 1: Processes CITS2002 Systems Programming

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.

Page 2: Processes CITS2002 Systems Programming

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.

Page 3: Processes CITS2002 Systems Programming

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.

Page 4: Processes CITS2002 Systems Programming

CITS2002SystemsProgramming

←prev 4 next→ CITS2002 CITS2002schedule

TheSimple2-stateProcessModelAswegenerallyhavemorethantwoprocessesavailable,theReadystateisimplementedasaqueueofavailableprocesses:

Whenschedulingisdiscussed,wewillintroduceprocessprioritieswhendecidingwhichReadyprocessshouldbethenexttoexecute.

CITS2002SystemsProgramming,Lecture7,p4,16thAugust2021.

Page 5: Processes CITS2002 Systems Programming

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.

Page 6: Processes CITS2002 Systems Programming

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.

Page 7: Processes CITS2002 Systems Programming

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.

Page 8: Processes CITS2002 Systems Programming

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.

Page 9: Processes CITS2002 Systems Programming

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.

Page 10: Processes CITS2002 Systems Programming

CITS2002SystemsProgramming

←prev 10 next→ CITS2002 CITS2002schedule

SupportingMultipleBlockedStatesWhennotificationofanI/Oortimercompletionoccurs,thesimplestqueuingmodelrequirestheoperatingsystemtoscanitsBlockedqueuetodeterminewhichprocess(es)requested,orareinterestedin,theevent:

CITS2002SystemsProgramming,Lecture7,p10,16thAugust2021.

Page 11: Processes CITS2002 Systems Programming

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.

Page 12: Processes CITS2002 Systems Programming

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.

Page 13: Processes CITS2002 Systems Programming

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.

Page 14: Processes CITS2002 Systems Programming

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.


Recommended