Documente Academic
Documente Profesional
Documente Cultură
1.a)Createasharedmemoryobjectof3pagesizeandattachcurrent
processtothesharedmemoryobject.
Now,writesomedataintopagesofthissharedmemoryregion.
Createachildprocessfromthisprocessandaccessthesharedmemory
sectioninthechildprocessareyouabletoreadthedatathatwas
writtenintheparentprocess?Youmustbeabletoaccesseverypage
ofthesharedmemoryregion.
Note:youcancreateasharedmemoryregionofanysizeasperyour
Requirements!!!Here,wearejustusingoneexample!!!
b)canyourepeattheabovestepsusing2unrelatedprocessesmeaning,
the2processesmustnotbeparentandchildprocesses.Areyouable
towritedatafromoneprocessintothesharedmemorysectionand
readthesamedatafromanotherprocess?Onceagain,youmustbe
abletoaccesseverypageofthesharedmemoryregion.
Note:inthiscase,youmustload2separateprogramsfrom2terminals
thiswillensurethatwearecommunicatingbetween2unrelated
processes!!!
LinuxAssignment3.....
2.Inthefollowingproblem,usethesamplecodeprovidedinrace.c!!!
a)provethatraceconditionscanoccurandleadtoinconsistencies
incomputing!!!!youmayneedtomodifythecodetogenerate
raceconditionsandinconsistencies!!!
Note:asmentionedintheclasslectures,raceconditionsmaynotoccur
everysecond,millisecond,orevery10years!!!!concurrencyrelated
problemsareunpredictable!!!!
Note:youmusttestinuniprocessorenvironmentandthenonmultiprocessor
environmentaswell!!!
Note:youmustunderstandyourexecutionenvironmentandscheduling
aspectstogenerateraceconditionsonhintcouldbechangingthe
nicevaluesofprocessestoreducetheirtimesharesinaddition,
youmustalsoloadthesystemwithwhile.cprogramstosharethecpu
cyclesamongprocesses!!!
b)now,usingabinarysemaphore(whosevalueisfixedas0or1)asalock
toprotectcriticalsectionsintheaboveproblem,provethatsemaphore
lockcanpreventraceconditionsandpreventinconsistenciesin
computing!!!
Note:provethisworksinuniprocessorandmultiprocessorenvironments!!!
linuxAssignment3...continued
3.lookintoprod_test.c,prod_1_1.c,prod_1_2.c,cons_test.c,cons_1_1.cand
cons_1_2.cexamples
a)provethatyouneed2countingsemaphoresforsynchronization,
inthesecasestrytotestitpracticallywith/withoutcounting
semaphores!!!
b)doyouneedacriticalsectionsemaphore?Whydoyouneedit??
linuxAssignment3...continued
3.
c)finally,rewritetheabovesetofexamplessuchthatyoucandothe
following:
createasharedmemorysegmentasneededintheparent
process
createandinitializeasemaphoreobjectwithnecessarysemaphores
(maybe,3semaphores)
create2childprocessesonechildwillbeproducerandoneanother
willbeconsumer
producerwillreadastringandwriteintosharedcircularbufferarea
ofstrings,notcharactersmeaning,eachcircularbufferslotwill
holdastring,notacharacterasinthesamplecodes!!!
parentprocessmustcreatethechildrenprocesses,waitfor
thechildrenprocessestoterminate,cleanupthechildrenprocesses,
destroysharedmemory,destroysemaphoreobjectsandthen
terminate