操作系统作业4姓名,学号.docx

上传人:b****9 文档编号:69596 上传时间:2022-10-02 格式:DOCX 页数:7 大小:25.90KB
下载 相关 举报
操作系统作业4姓名,学号.docx_第1页
第1页 / 共7页
操作系统作业4姓名,学号.docx_第2页
第2页 / 共7页
操作系统作业4姓名,学号.docx_第3页
第3页 / 共7页
操作系统作业4姓名,学号.docx_第4页
第4页 / 共7页
操作系统作业4姓名,学号.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

操作系统作业4姓名,学号.docx

《操作系统作业4姓名,学号.docx》由会员分享,可在线阅读,更多相关《操作系统作业4姓名,学号.docx(7页珍藏版)》请在冰豆网上搜索。

操作系统作业4姓名,学号.docx

橾作系统课柱作业

操作系统作业4

姓名,学号

1.Why istheseparationofmechanismandpolicydesirable?

Answer:

Mechanismandpolicymustbeseparatetoensurethatsystemsareeasytomodify.Notwosysteminstallationsarethesame,soeachinstallationmaywanttotunetheoperatingsystemtosuititsneeds.Withmechanismandpolicyseparate,thepolicymaybechangedatwillwhilethemechanismstaysunchanged.Thisarrangementprovidesamoreflexiblesystem.

2.·whatarethetwomodelsofinterprocesscommunication?

Whatarethestrengthsandweaknessesofthetwoapproaches?

Answer:

Thehvomodelsofintetprocesscommunicationaremessage-passingmodelandtheshared-memorymodel.Messagepassingisusefttlforexchangingsmalleramountsof

da,tabecausenoconflictsne,edbeavoided.Itisalsoeasiertoimplementthanisshared

memoryforintercomputercommunication.Sharedn1emoryallowsmaximumspeedandconvenienceofcommunication,sinceitcanbedoneatmemorytransferspeedswhenittakesplacewithinacomputer.However,thismethodcompromisesonprotectionandsynchronizationbel\veentheprocessessharingmemory

3.Includingtheinitialparentprocess,bowmanyprocessesarecreatedbytheprogramshowninFigurel?

#include#include

int main()

int i;

for (i一O;i<4;i++)

fork();

returnO;

Figure1:

ProgramforQuestion3.

2

Answer:

16processesarecreated.

Hint:

YoumayincludeprintfOstatementstobetterunderstandbowmanyprocesseshavebeencreated.

4..Explainthecircumstancesunderwhichthelineofcodemarkedprintf("LINEJ")inFigure2willbereached

#include#include#include

int main()

pid_t pid;

I*forkachildprocess*Ipid=fork();

if (pid

elseif (pid==0) { I*childprocess*I

execlp("/bin/ls","ls",NULL);printf("LINEJ");

else{/*parentprocess*I

I*parentwillw吐t for the childtocomplete*I

w吐t(NULL);

printf("ChildComplete");

returnO;

Fi驴re2:

ProgramforQuestion4.

橾作系统课柱作业

3

Answer:

ThecalltoexecOreplacestheaddressspaceoftheprocesswiththeprogramspecifiedastheparametertoexecQ.IfthecalltoexecOsucceeds,thenewprogramisnowrunningandcontrolfromthecalltoexec()neverreturns.ltithisscenario,thelineprintf("LineJ");wouldneverbeperformed.However,ifanerroroccmsinthecalltoexecO,thefunctionren1rnscontrolandthereforthelineprintf("LineJ");wouldbeperformed.

5.UsingtheprograminFigure3,identifythevaluesofpidat1inesA,B,C,andD.(Assumethattheactualpidsoftheparentandchildare2600and2603,respectively.)

#includes

#include#include

intmain{)

picLtpid,pidl;

I*forkachildprocess寒/pid frok();

if (pid<0){/•erroroccurred•/fprintf(stderr,"ForkFaile心);return1;

elseif(pidsc 0){/•childprocess•/pidl•getpid();

printf("child:

pid=¼d",pid);/亭A*Iprintf("child:

pid1=¼d",p过1);/•B•I

else{/•parentprocess•/pidl=getpid();

printf("parent:

pid=i.d",pid);/拿C拿/printf("parent:

p工di•i.d",pidl);/*D•I11ait(NULL);

returnO;

Figure3:

ProgramforQuestion5.

Answer:

A=0,B=2603,C=260,3D=2600

4

橾作系统课柱作业

6.UsingtheprogramshowninFigure4,explainwhattheoutputwillbeat

linesXandY.

#include<芍s/types.h>#include#include

#defineSIZE5

int nums[SIZE]={0,1,2,3,4};

int main()

inti;

pid_t pid;

pid=fork();

if (pid=0){

for (i=O;i

nums[i] •=-i;

printf("CHILD:

%d11,nums [i]);/•LINEX•/

elseif (pid>0){

wait(NULL);

for (i =O;i

rpintf("PARENT:

加 ",nums[i]);I*LINEY•/

returnO;

Figure4:

ProgramforQuestion6.

Answer:

Becausethechildisacopyoftheparent,anychangesthechildmakeswilloccurinitscopyofthedataandwon'tbereflectedintheparent.Asaresult,thevaluesoutputbythechildatlineXare0,-1,-4,-9,-16.ThevaluesoutputbytheparentatlineYare0,I,2,3,4

5

操作系统课杠作业

7.Whichofthefollowingcomponentsofprogramstatearesharedacrossthreadsinamultithreadedprocess?

a.Registervalues

b.Heapmemory

c.Globalvariables

d.Stackmemory

Answer:

Thethreadsofamultithreadedprocessshareheapmemoryandglobalvariables.Eachthreadhasitsseparatesetofregistervaluesandaseparatestack.

8.Asystemwithtwodual-coreprocessorshasfourprocessorsavailableforscheduling.ACPU-intensiveapplicationisrunningonthissystem.Allinputisperformed

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1