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

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

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

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

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

stdio.h>

#include<

unistd.h>

int main()

int i;

for (i一O;

i<

4;

i++)

fork();

returnO;

Figure1:

ProgramforQuestion3.

2

16processesarecreated.

Hint:

YoumayincludeprintfOstatementstobetterunderstandbowmanyprocesseshavebeencreated.

4..Explainthecircumstancesunderwhichthelineofcodemarkedprintf("

LINEJ"

)inFigure2willbereached

#include<

sys/types.h>

#include<

stdio.h>

unistd.h>

int main()

pid_t pid;

I*forkachildprocess*Ipid=fork();

if (pid<

O){I*erroroccurred*Ifprintf(stderr,"

ForkFailed"

);

return1;

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"

Fi驴re2:

ProgramforQuestion4.

橾作系统课柱作业

3

ThecalltoexecOreplacestheaddressspaceoftheprocesswiththeprogramspecifiedastheparametertoexecQ.IfthecalltoexecOsucceeds,thenewprogramisnowrunningandcontrolfromthecalltoexec()neverreturns.ltithisscenario,thelineprintf("

LineJ"

wouldneverbeperformed.However,ifanerroroccmsinthecalltoexecO,thefunctionren1rnscontrolandthereforthelineprintf("

);

wouldbeperformed.

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

#includes<

ys/types.h>

stdio.h>

unistd.h>

intmain{)

picLtpid,pidl;

I*forkachildprocess寒/pid frok();

0){/•erroroccurred•/fprintf(stderr,"

ForkFaile心);

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

printf("

child:

pid=¼

d"

pid);

/亭A*Iprintf("

child:

pid1=¼

p过1);

/•B•I

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

parent:

pid=i.d"

/拿C拿/printf("

p工di•i.d"

pidl);

/*D•I11ait(NULL);

returnO;

Figure3:

ProgramforQuestion5.

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

4

6.UsingtheprogramshowninFigure4,explainwhattheoutputwillbeat

linesXandY.

芍s/types.h>

#include<

#defineSIZE5

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

inti;

pid=fork();

if (pid=0){

for (i=O;

i<

SIZE;

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•/

Figure4:

ProgramforQuestion6.

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

Thethreadsofamultithreadedprocessshareheapmemoryandglobalvariables.Eachthreadhasitsseparatesetofregistervaluesandaseparatestack.

8.Asystemwithtwodual-coreprocessorshasfourprocessorsavailableforscheduling.ACPU-intensiveapplicationisrunningonthissystem.Allinputisperformed

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

当前位置:首页 > 经管营销 > 公共行政管理

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

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