OS - Process Concepts

29,125 views 46 slides Jul 19, 2018
Slide 1
Slide 1 of 46
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46

About This Presentation

Gives an overview about Process, PCB, Process States, Process Operations, Scheduling, Schedulers, Interprocess communication, shared memory and message passing systems


Slide Content

Process Concept

Process Concept
•Anoperatingsystemexecutesavarietyof
programs:
–Batchsystem–jobs
–Time-sharedsystems–userprogramsortasks
•Manymodernprocessconceptsarestillexpressed
intermsofjobs,(e.g.jobscheduling),andthe
twotermsareoftenusedinterchangeably.
2

Incomputing,aprocessisaninstanceofacomputerprogramthat
isbeingexecuted.Itcontainstheprogramcodeanditscurrent
activity.
Processmemoryisdividedintofoursections:
Thetextsectioncomprisesthecompiledprogramcode,readin
fromnon-volatilestoragewhentheprogramislaunched.
Thedatasectionstoresglobalandstaticvariables,allocatedand
initializedpriortoexecutingmain.
Theheapisusedfordynamicmemoryallocation,andismanagedvia
callstonew,delete,malloc,free,etc.
Thestackisusedforlocalvariables.Spaceonthestackisreserved
forlocalvariableswhentheyaredeclared(atfunctionentranceor
elsewhere,dependingonthelanguage),andthespaceisfreedup
whenthevariablesgooutofscope.

Aprogramisapassiveentity,suchasafilecontainingalistof
instructionsstoredondisk(oftencalledanexecutablefile).
Incontrast,aprocessisanactiveentity,withaprogramcounter
specifyingthenextinstructiontoexecuteandasetofassociated
resources.
Althoughtwoprocessesmaybeassociatedwiththesameprogram,
theyareneverthelessconsideredtwoseparateexecution
sequences.

Whenaprocessexecutes,itpassesthroughdifferentstates.The
stateofaprocessisdefinedinpartbythecurrentactivityofthat
process.
Thesestagesmaydifferindifferentoperatingsystems,andthe
namesofthesestatesarealsonotstandardized.
AProcessmaybeinoneothefollowingstates:
-Theprocessisbeingcreated.
-Theprocessiswaitingtobeassignedtoaprocessor.
-Instructionsarebeingexecuted.
-Theprocessiswaitingforsomeeventtooccur(such
asanI/Ocompletionorreceptionofasignal).
-Theprocesshasfinishedexecution

New-Theprocessisinthestageofbeingcreated.
Ready-Theprocesshasalltheresourcesavailablethatitneedstorun,but
theCPUisnotcurrentlyworkingonthisprocess'sinstructions.
Running-TheCPUisworkingonthisprocess'sinstructions.
Waiting-Theprocesscannotrunatthemoment,becauseitiswaitingfor
someresourcetobecomeavailableorforsomeeventtooccur.
Terminated-Theprocesshascompleted.

Eachprocessisrepresentedintheoperatingsystembyaprocesscontrol
block(PCB)—alsocalledataskcontrolblock.Itcontainsmanypiecesof
informationassociatedwithaspecificprocess,includingthese:
►Processstate:Thestatemaybenew,ready,runningandsoon
►Programcounter:Itindicatestheaddressofthenextinstructiontobeexecuted
forthisprogram.
►CPUregisters:Thesevaryinnumberandtypebasedonarchitecture.They
includeaccumulators,stackpointers,generalpurposeregistersetc.Alongwith
►CPUschedulinginformation:Thisincludesprocesspriority,pointersto
schedulingqueuesandanyschedulingparameters.
►Memory-managementinformation:Thisincludesthevalueofbaseandlimit
registers(protection)andpagetables,segmenttablesdependingonmemory.
►Accountinginformation:ItincludesamountofCPUandrealtimeused,
accountnumbers,processnumbersetc
►I/Ostatusinformation:ItincludeslistofI/Odevicesallocatedtothisprocess,
alistofopenfilesetc

ThearchitectureofaPCBiscompletelydependenton
OperatingSystemandmaycontaindifferentinformation
indifferentoperatingsystems.
ThePCBismaintainedforaprocessthroughoutits
lifetime,andisdeletedoncetheprocessterminates.

Aprocessisaprogramthatperformsasinglethreadof
execution.Thissinglethreadofcontrolallowstheprocessto
performonlyonetaskatatime.
Mostmodernoperatingsystemshaveextendedtheprocess
concepttoallowaprocesstohavemultiplethreadsof
executionandthustoperformmorethanonetaskatatime.
Thisfeatureisespeciallybeneficialonmulticoresystems,
wheremultiplethreadscanruninparallel.
Onasystemthatsupportsthreads,thePCBisexpandedto
includeinformationforeachthread.Otherchangesthroughout
thesystemarealsoneededtosupportthreads.

Process Scheduling
•Thetwomainobjectivesoftheprocessscheduling
systemaretokeeptheCPUbusyatalltimesandto
deliver"acceptable"responsetimesforall
programs,particularlyforinteractiveones.
•Theprocessschedulermustmeettheseobjectives
byimplementingsuitablepoliciesforswapping
processesinandoutoftheCPU.

Asprocessesenterthesystem,theyareputintoa ,which
consistsofallprocessesinthesystem.
Theprocessesthatareresidinginmainmemoryandarereadyand
waitingtoexecutearekeptonalistcalledthe .This
queueisgenerallystoredasalinkedlist.
Aready-queueheadercontainspointerstothefirstandfinalPCBs
inthelist.EachPCBincludesapointerfieldthatpointstothenext
PCBinthereadyqueue.
Thesystemalsoincludesotherqueues.Whenaprocessisallocated
theCPU,itexecutesforawhileandeventuallyquits,isinterrupted,
orwaitsfortheoccurrenceofaparticularevent,suchasthe
completionofanI/Orequest.
ThelistofprocesseswaitingforaparticularI/Odeviceiscalleda
.Eachdevicehasitsowndevicequeue.

Ready Queue And Various I/O Device Queues

Acommonrepresentationofprocessschedulingisa
.Eachrectangularboxrepresentsaqueue.
Twotypesofqueuesarepresent:the andasetof
.Thecirclesrepresenttheresourcesthatservethequeues,
andthearrowsindicatetheflowofprocessesinthesystem.

Inthefirsttwocases,theprocesseventuallyswitchesfromthe
waitingstatetothereadystateandisthenputbackintheready
queue.
Aprocesscontinuesthiscycleuntilitterminates,atwhichtimeitis
removedfromallqueuesandhasitsPCBandresourcesdeallocated.
Anewprocessisinitiallyputinthereadyqueue.Itwaitsthereuntilitis
selectedforexecution,ordispatched.
OncetheprocessisallocatedtheCPUandisexecuting,oneofseveral
eventscouldoccur:
TheprocesscouldissueanI/OrequestandthenbeplacedinanI/Oqueue.
Theprocesscouldcreateanewchildprocessandwaitforthechild’s
termination.
TheprocesscouldberemovedforciblyfromtheCPU,asaresultofan
interrupt,andbeputbackinthereadyqueue.

Aprocessmigratesamongthevariousschedulingqueues
throughoutitslifetime.Theoperatingsystemmustselect,for
schedulingpurposes,processesfromthesequeuesinsome
fashion.Theselectionprocessiscarriedoutbytheappropriate
scheduler.
A istypicalofabatchsystemoraveryheavily
loadedsystem.Whenmoreprocessesaresubmittedthanthatcan
beexecutedimmediately,theyarespooledtoamass-storage
deviceandarekeptthereforlaterexecution.Thelong-term
scheduler,orjobscheduler,selectsprocessesfromthispooland
loadsthemintomemoryforexecution.
The ,or ,selectsfromamong
theprocessesthatarereadytoexecuteandallocatestheCPUto
oneofthem.


Theprimarydistinctionbetweenthesetwoschedulersliesin
frequencyofexecution.Theshort-termschedulermustselecta
newprocessfortheCPUfrequently(intheorderofmilliseconds).
Thelong-termschedulerexecutesmuchlessfrequently;minutes
mayseparatethecreationofonenewprocessandthenext.

Thelong-termschedulercontrolsthedegreeof
multiprogramming(thenumberofprocessesinmemory).
Anefficientschedulingsystemwillselectagoodprocessmix
ofCPU-boundprocessesandI/Oboundprocesses.


Someoperatingsystems,suchastime-sharingsystems,mayintroducean
additional,intermediatelevelofschedulingcalled
.

Thekeyideabehindamedium-termscheduleristhatsometimesitcan
beadvantageoustoremoveaprocessfrommemory(andfromactive
contentionfortheCPU)andthusreducethedegreeof
multiprogramming.

Swappingisamechanisminwhichaprocesscanbeswapped/moved
temporarilyoutofmainmemorytoabackingstore,andthenbrought
backintomemoryforcontinuedexecution.

Theprocessisswappedout,andislaterswappedin,bythemedium-
termscheduler.

Whenaninterruptoccurs,thesystemneedstosavethecurrent
contextoftheprocessrunningontheCPUsothatitcanrestorethat
contextwhenitsprocessingisdone,essentiallysuspendingthe
processandthenresumingit.ThecontextisrepresentedinthePCB
oftheprocess.
.
Context-switchtimeispureoverhead,becausethesystemdoesno
usefulworkwhileswitching.Switchingspeedvariesfrommachine
tomachine,dependingonthememoryspeed,thenumberof
registersthatmustbecopied,andtheexistenceofspecial
instructions.
Context-switchtimesarehighlydependentonhardwaresupport.

Operations on Processes
•Theprocessesinthesystemcanexecute
concurrently,andtheymustbecreatedand
deleteddynamically.Thus,theoperatingsystem
mustprovideamechanism(orfacility)forprocess
creationandtermination.
•Otherkindsofoperationsonprocessesinclude
Deletion,Suspension,Resumption,Cloning,Inter-
ProcessCommunicationandSynchronization

Process Creation
Duringthecourseofexecution,aprocessmaycreate
severalnewprocesses.
Thecreatingprocessiscalledaparentprocess,andthe
newprocessesarecalledthechildrenofthatprocess.Each
ofthesenewprocessesmayinturncreateotherprocesses,
formingatreeofprocesses.
Mostoperatingsystems(includingUNIX,Linux,and
Windows)identifyprocessesaccordingtoauniqueprocess
identifier(orpid),whichistypicallyanintegernumber.
Thepidprovidesauniquevalueforeachprocessinthe
system,anditcanbeusedasanindextoaccessvarious
attributesofaprocesswithinthekernel.

OntypicalUNIXsystemstheprocessscheduleristermedsched,and
isgivenPID0.Thefirstthingitdoesatsystemstartuptimeisto
launchinit,whichgivesthatprocessPID1.
Initthenlaunchesallsystemdaemonsanduserlogins,andbecomes
theultimateparentofallotherprocesses.
A typical process tree for a Linux system


Ingeneral,whenaprocesscreatesachildprocess,thatchildprocess
willneedcertainresources(CPUtime,memory,files,I/Odevices)to
accomplishitstask.

Achildprocessmaybeabletoobtainitsresourcesdirectlyfromthe
operatingsystem,oritmaybeconstrainedtoasubsetofthe
resourcesoftheparentprocess.

Theparentmayhavetopartitionitsresourcesamongitschildren,or
itmaybeabletosharesomeresources(suchasmemoryorfiles)
amongseveralofitschildren.

Restrictingachildprocesstoasubsetoftheparent’sresources
preventsanyprocessfromoverloadingthesystembycreatingtoo
manychildprocesses.
Inadditiontosupplyingvariousphysicalandlogicalresources,the
parentprocessmaypassalonginitializationdata(input)tothechild
process.


Therearetwooptionsfortheparentprocessaftercreatingthechild:

Waitforthechildprocesstoterminatebeforeproceeding.Theparentmakesa
wait()systemcall,foreitheraspecificchildorforanychild,whichcausesthe
parentprocesstoblockuntilthewait()returns.UNIXshellsnormallywaitfor
theirchildrentocompletebeforeissuinganewprompt.

Runconcurrentlywiththechild,continuingtoprocesswithoutwaiting.Thisis
theoperationseenwhenaUNIXshellrunsaprocessasabackgroundtask.It
isalsopossiblefortheparenttorunforawhile,andthenwaitforthechild
later,whichmightoccurinasortofaparallelprocessingoperation.(E.g.the
parentmayforkoffanumberofchildrenwithoutwaitingforanyofthem,
thendoalittleworkofitsown,andthenwaitforthechildren.
)

Twopossibilitiesfortheaddressspaceofthechildrelativetotheparent:

Thechildmaybeanexactduplicateoftheparent,sharingthesameprogram
anddatasegmentsinmemory.EachwillhavetheirownPCB,including
programcounter,registers,andPID.ThisisthebehavioroftheforkinUNIX.

Thechildprocessmayhaveanewprogramloadedintoitsaddressspace,with
allnewcodeanddatasegments.Thisisthebehaviorofthespawnsystemcalls
inWindows.UNIXsystemsimplementthisasasecondstep,usingtheexec
systemcall.

Thefigureshowstheforkandexec
processonaUNIXsystem.
TheforksystemcallreturnsthePID
oftheprocesses.
Itreturnsazerotothechildprocess
andanon-zerochildPIDtothe
parent,sothereturnvalueindicates
whichprocessiswhich.
ProcessIDscanbelookedupany
timeforthecurrentprocessorits
directparentusingthegetpid()and
getppid()systemcallsrespectively.

Creating a Separate Process via Windows API
Thefigureshowsthemorecomplicated
processforWindows,whichmust
providealloftheparameterinformation
forthenewprocessaspartoftheforking
process.

Process Termination
Aprocessterminateswhenitfinishesexecutingitsfinalstatement
andaskstheoperatingsystemtodeleteitbyusingtheexit()
systemcall.
Alltheresourcesoftheprocess—includingphysicalandvirtual
memory,openfiles,andI/Obuffers—aredeallocatedbythe
operatingsystem.
Aprocesscancausetheterminationofanotherprocessviaan
appropriatesystemcall.Suchsystemcallsareusuallyinvoked
onlybytheparentoftheprocessthatistobeterminated.Aparent
needstoknowtheidentitiesofitschildrenifitistoterminate
them.


AParentmayterminatetheexecutionofoneofitschildrenfora
varietyofreasons,suchasthese:
1.Thechildhasexceededitsusageofsomeoftheresourcesthatit
hasbeenallocated.(Todeterminewhetherthishasoccurred,
theparentmusthaveamechanismtoinspectthestateofits
children.)
2.Thetaskassignedtothechildisnolongerrequired.
3.Theparentisexiting,andtheoperatingsystemdoesnotallowa
childtocontinueifitsparentterminates.
Somesystemsdonotallowachildtoexistifitsparenthas
terminated.Insuchsystems,ifaprocessterminates(either
normallyorabnormally),thenallitschildrenmustalsobe
terminated.Thisphenomenon,referredtoascascading
termination,isnormallyinitiatedbytheoperatingsystem.

Whenaprocessterminates,allofitssystemresourcesarefreedup,
openfilesflushedandclosed,etc.

Theprocessterminationstatusandexecutiontimesarereturnedto
theparentiftheparentiswaitingforthechildtoterminate,or
eventuallyreturnedtoinitiftheprocessbecomesanorphan.

Aprocessthathasterminated,butwhoseparenthasnotyetcalled
wait(),isknownasa .

Ifaparentdidnotinvokewait()andinsteadterminated,thereby
leavingitschildprocessesas .LinuxandUNIXaddressthis
scenariobyassigningtheinitprocessasthenewparenttoorphan
processes.
Theinitprocessperiodicallyinvokeswait(),therebyallowingtheexit
statusofanyorphanedprocesstobecollectedandreleasingthe
orphan’sprocessidentifierandprocess-tableentry.

InterprocessCommunication
•Processesexecutingconcurrentlyintheoperating
systemmaybeeitherindependentprocessesor
cooperatingprocesses.
Aprocessis ifitcannotaffectorbe
affectedbytheotherprocessesexecutinginthesystem.
Anyprocessthatdoesnotsharedatawithanyother
processisindependent.
Aprocessis ifitcanaffectorbeaffected
bytheotherprocessesexecutinginthesystem.Clearly,
anyprocessthatsharesdatawithotherprocessesisa
cooperatingprocess.

Thereareseveralreasonsforprovidinganenvironmentthatallows
processcooperation:

InformationSharing-Theremaybeseveralprocesseswhich
needaccesstothesamefile.(e.g.pipelines.)

Computationspeedup-Oftenasolutiontoaproblemcanbe
solvedfasteriftheproblemcanbebrokendownintosub-tasksto
besolvedsimultaneously(particularlywhenmultipleprocessors
areinvolved.)

Modularity-Themostefficientarchitecturemaybetobreaka
systemdownintocooperatingmodules.(E.g.databaseswitha
client-serverarchitecture.)
Convenience-Evenasingleusermaybemulti-tasking,suchas
editing,compiling,printing,andrunningthesamecodein
differentwindows.

Cooperatingprocessesrequiresometypeofinter-processcommunication,
whichismostcommonlyoneoftwotypes:MessagePassingsystems(a)or
SharedMemorysystems(b)
MessagePassingrequires
systemcallsforeverymessage
transfer,andisthereforeslower,
butitissimplertosetupand
workswellacrossmultiple
computers.
Messagepassingisgenerally
preferablewhentheamount
and/orfrequencyofdata
transfersissmall,orwhen
multiplecomputersare
involved.
SharedMemoryisfasteronceitissetup,becausenosystemcallsare
requiredandaccessoccursatnormalmemoryspeeds.Howeveritismore
complicatedtosetup,anddoesn'tworkaswellacrossmultiplecomputers.
Sharedmemoryisgenerallypreferablewhenlargeamountsofinformation
mustbesharedquicklyonthesamecomputer.

Interprocesscommunicationusingsharedmemoryrequires
communicatingprocessestoestablisharegionofsharedmemory.
Typically,ashared-memoryregionresidesintheaddressspaceofthe
processcreatingtheshared-memorysegment.
Otherprocessesthatwishtocommunicateusingthisshared-memory
segmentmustattachittotheiraddressspace.
Sharedmemoryrequiresthattwoormoreprocessesagreetoremove
therestrictionofpreventingoneprocessaccessinganotherprocesses
memory.
Theycanthenexchangeinformationbyreadingandwritingdatain
thesharedareas.Theformofthedataandthelocationare
determinedbytheseprocessesandarenotundertheoperating
system’scontrol.Theprocessesarealsoresponsibleforensuringthat
theyarenotwritingtothesamelocationsimultaneously.

Producer-Consumerproblemisacommonparadigmforcooperating
processesinwhichoneprocessisproducingdataandanotherprocess
isconsumingthedata.
Theproducer–consumerproblemprovidesausefulmetaphorforthe
client–serverparadigm.Aserveristhoughtasaproducerandaclient
asaconsumer.
Onesolutiontotheproducer–consumerproblemusesshared
memory.Toallowproducerandconsumerprocessestorun
concurrently,wemusthaveavailableabufferofitemsthatcanbe
filledbytheproducerandemptiedbytheconsumer.
Thisbufferwillresideinaregionofmemorythatissharedbythe
producerandconsumerprocesses.Aproducercanproduceoneitem
whiletheconsumerisconsuminganotheritem.Theproducerand
consumermustbesynchronized,sothattheconsumerdoesnottryto
consumeanitemthathasnotyetbeenproduced.

Twotypesofbufferscanbeused.Theunboundedbufferplaces
nopracticallimitonthesizeofthebuffer.Theconsumermay
havetowaitfornewitems,buttheproducercanalways
producenewitems.
Theboundedbufferassumesafixedbuffersize.Inthiscase,the
consumermustwaitifthebufferisempty,andtheproducer
mustwaitifthebufferisfull.
Aproducertriestoinsertdatainto
anemptyslotofthebuffer.A
consumertriestoremovedata
fromafilledslotinthebuffer.As
youmighthaveguessedbynow,
thosetwoprocesseswon'tproduce
theexpectedoutputiftheyare
beingexecutedconcurrently.

Theproducerprocesshasalocalvariablenextproducedinwhich
thenewitemtobeproducedisstored.Theconsumerprocesshasa
localvariablenextconsumedinwhichtheitemtobeconsumedis
stored.

Messagepassingprovidesamechanismtoallowprocessesto
communicateandtosynchronizetheiractionswithoutsharingthe
sameaddressspace.
Itisparticularlyusefulinadistributedenvironment,wherethe
communicatingprocessesmayresideondifferentcomputers
connectedbyanetwork.
Amessage-passingfacilityprovidesatleasttwooperations:
send(message) receive(message)
Messagessentbyaprocesscanbeeitherfixedorvariableinsize.
Ifonlyfixed-sizedmessagescanbesent,thesystem-level
implementationisstraightforward.However,makesthetaskof
programmingmoredifficult.
Ifitisvariable-sizedmessagesthenitrequireamorecomplexsystem-
levelimplementation,buttheprogrammingtaskbecomessimpler.

IfprocessesPandQwanttocommunicate,theymustsend
messagestoandreceivemessagesfromeachother:a
communicationlinkmustexistbetweenthem.Thislinkcanbe
implementedinavarietyofways.
Hereareseveralmethodsforlogicallyimplementingalinkand
thesend()/receive()operations:
Directorindirectcommunication(Naming)
Synchronousorasynchronouscommunication
Automaticorexplicitbuffering

Processesthatwanttocommunicatemusthaveawaytoreferto
eachother.Theycanuseeitherdirectorindirectcommunication.
Under ,eachprocessthatwantsto
communicatemustexplicitlynametherecipientorsenderofthe
communication.Inthisscheme,thesend()andreceive()primitives
aredefinedas:
•send(P,message)—SendamessagetoprocessP.
•receive(Q,message)—ReceiveamessagefromprocessQ.Acommunicationlinkinthisschemehasthefollowingproperties:
Alinkisestablishedautomaticallybetweeneverypairof
processesthatwanttocommunicate.Theprocessesneedto
knowonlyeachother’sidentitytocommunicate.
Alinkisassociatedwithexactlytwoprocesses.
Betweeneachpairofprocesses,thereexistsexactlyonelink.
40
Naming
I
P
C

Thepreviousschemeexhibitssymmetryinaddressing;thatis,boththe
senderprocessandthereceiverprocessmustnametheotherto
communicate.
Avariantofthisschemeemploysasymmetryinaddressing.Here,only
thesendernamestherecipient;therecipientisnotrequiredtonamethe
sender.Inthisscheme,thesend()andreceive()primitivesaredefinedas
follows:
•send(P,message)—SendamessagetoprocessP.
•receive(id,message)—Receiveamessagefromanyprocess.
Thevariableidissettothenameoftheprocesswithwhich
communicationhastakenplace.
Thedisadvantageinbothoftheseschemes(symmetricand
asymmetric)isthelimitedmodularityoftheresultingprocess
definitions.
Anysuchhard-codingtechniques,whereidentifiersmustbeexplicitly
stated,arelessdesirablethantechniquesinvolvingindirection.
41
Naming
I
P
C

Withindirectcommunication,themessagesaresenttoandreceived
from .
Amailboxcanbeviewedabstractlyasanobjectintowhichmessages
canbeplacedbyprocessesandfromwhichmessagescanberemoved.
Eachmailboxhasauniqueidentification.
Aprocesscancommunicatewithanotherprocessviaanumberof
differentmailboxes,buttwoprocessescancommunicateonlyifthey
haveasharedmailbox.Thesend()andreceive()primitivesaredefined
asfollows:
send(A,message)—SendamessagetomailboxA.
receive(A,message)—ReceiveamessagefrommailboxA.
Inthisscheme,acommunicationlinkhasthefollowingproperties:
Alinkisestablishedbetweenapairofprocessesonlyifbothmembersofthe
pairhaveasharedmailbox.
Alinkmaybeassociatedwithmorethantwoprocesses.
Betweeneachpairofcommunicatingprocesses,anumberofdifferentlinks
mayexist,witheachlinkcorrespondingtoonemailbox
42
Naming –Indirect Communication
I
P
C

AmailboxmaybeownedeitherbyaprocessorbytheOS.
Ifthemailboxisownedbyaprocess(thatis,themailboxispartofthe
addressspaceoftheprocess),thenwedistinguishbetweentheowner
(whichcanonlyreceivemessagesthroughthismailbox)andtheuser
(whichcanonlysendmessagestothemailbox).
Sinceeachmailboxhasauniqueowner,therecanbenoconfusion
aboutwhichprocessshouldreceiveamessagesenttothismailbox.
Whenaprocessthatownsamailboxterminates,themailbox
disappears.Anyprocessthatsubsequentlysendsamessagetothis
mailboxmustbenotifiedthatthemailboxnolongerexists.
AmailboxownedbyanOSisindependentandisnotattachedtoany
process.ThentheOSneedstoprovideamechanismtodothe
following:
Createanewmailbox.
Sendandreceivemessagesthroughthemailbox.
Deleteamailbox.
43
Naming –Indirect Communication
I
P
C

44

Communicationbetweenprocessestakesplacethroughcallsto
send()andreceive()primitives.Therearedifferentdesignoptions
forimplementingeachprimitive.
Messagepassingmaybeeitherblockingornonblocking—also
knownassynchronousandasynchronous.
Thesendingprocessisblockeduntilthe
messageisreceivedbythereceivingprocessorbythemailbox.
.Thesendingprocesssendsthemessageand
resumesoperation.
.Thereceiverblocksuntilamessageis
available.
Thereceiverretrieveseitheravalid
messageoranull.
45
Synchronization
I
P
C

Whethercommunicationisdirectorindirect,messagesexchanged
bycommunicatingprocessesresideinatemporaryqueue.
Basically,suchqueuescanbeimplementedinthreeways:
.Thequeuehasamaximumlengthofzero;thus,the
linkcannothaveanymessageswaitinginit.Inthiscase,thesender
mustblockuntiltherecipientreceivesthemessage.
Thequeuehasfinitelengthn;thus,atmostn
messagescanresideinit.Ifthequeueisnotfullwhenanew
messageissent,themessageisplacedinthequeue,andthesender
cancontinueexecutionwithoutwaiting.Ifthelinkisfull,the
sendermustblockuntilspaceisavailableinthequeue.
Thequeue’slengthispotentiallyinfinite;
thus,anynumberofmessagescanwaitinit.Thesendernever
blocks
.
46
Buffering
I
P
C