Sie sind auf Seite 1von 6

1. JobsAandBarecompletelyCPUboundprocesses.JobCrequires1unitofCPUfollowed by4timeunitsofI/O,inapatternrepeatedthrice,followedby1unitofCPU(seetable below).Foreachofthefollowingschedulingpolicies,determinethejobschedule,calculate theturnaroundtimeforeachjob,andprovidethetotalnumberofcontextswitches.Youcan ignorethecontextswitchingoverheadinyourcalculations.ForRoundRobin,youcan assumethattheorderinthereadyqueueinA,B,C.Foreachjobsequence,Cstandsfor CPUandIstandsforI/O.

JobID A B C Arrival 0 1 2 Executionpattern CCCCCCCCCCC CCCCCCCCCCCC CIIIICIIIICIIIIC Length 10 11 16

Asanexample,thebeginningofaFIFOschedulingpolicy(withoutpreemption)wouldlook like: AAAAAAAAAABBBBBBBBBBBCxxxxCxxxxCxxxxC wherexrepresentsanidleCPU.Notethatinthisexample,JobAbeganattime0andfinishedat time10.Ajobthatarrivesattimeicanbeginattimei. (a)RoundRobinwitha5unittimequantum (b)RoundRobinwitha1unittimequantum (c)SRPT(jobsizeisnextcontiguousCPUburst;1unittimequantum) (d)Fromthegivenworkload,whichoftheaboveschedulingpoliciesmaximize(s)CPU utilization(theremightbemorethanone)? (e)Fromthegivenworkload,whichoftheaboveschedulingpoliciesismostsuitedfor interactivejobs?Ifthereismorethanone,explaintheprimaryadvantageofusingoneoverthe other.

2.ThreeprocessesA,BandCstartexecuting(nearly)togetherinamultiprocessing environment,andrequire7,12and16seconds,respectively,ofruntime.Whatwilltheaverage turnaroundtimebeif (a)(nonpreemptive)ShortestJobFirstschedulingisused? (b)(preemptive)RoundRobinschedulingisused? 3.AssumethatNisapositiveintegerconstant.WritesomecodethatwillresultinNprocesses executing,withtheoriginalprocesscreatingonechildprocess,andthisprocesscreatingone childprocess,andthisprocesscreatingonechildprocess,andsoon.HaveeachofthefirrstN1 processeswaitonitsownchildprocess'sterminationbeforeterminatingitself.Havetheoriginal processprint1,thenextprint2,thenextprint3,andsoforth.

4.AmongCPUschedulingpolicies,FirstComeFirstServe(FCFS)isattractivebecause: (a)itissimpletoimplement (b)itisfairtoallprocesses (c)itminimizesthetotalwaitingtimeinthesystem (d)itminimizestheaveragewaitingtimeinthesystem (e)itminimizestheaverageresponsetimeinthesystem (f)itminimizestheaverageturnaroundtimeinthesystem 5.AmongCPUschedulingpolicies,ShortestRemainingProcessingTime(SRPT)isattrac tivebecause: (a)itissimpletoimplement (b)itisfairtoallprocessesinthesystem (c)itminimizestheaveragewaitingtimeinthesystem (d)itminimizestheaverageresponsetimeinthesystem (e)itminimizesthenumberofcontextswitchesinthesystem (f)itmaximizesthenumberofcontextswitchesinthesystem 6.ConsideravariantoftheRRschedulingalgorithmwheretheentriesin thereadyqueuearepointerstothePCBs. a.Whatwouldbetheeffectofputtingtwopointerstothesameprocessinthereadyqueue? b.Whatwouldbethemajoradvantagesanddisadvantagesofthisscheme? c.HowwouldyoumodifythebasicRRalgorithmtoachievethesameeffectwithoutthe duplicatepointers?

7.ConsiderasystemrunningtenI/OboundtasksandoneCPUboundtask.AssumethattheI/ OboundtasksissueanI/OoperationonceforeverymillisecondofCPUcomputingandthat eachI/Ooperationtakes10millisecondstocomplete.Alsoassumethatthecontextswitching overheadis0.1millisecondandthatallprocessesarelongrunningtasks.WhatistheCPU utilizationforaroundrobinschedulerwhen: a.Thetimequantumis1millisecond b.Thetimequantumis10milliseconds 8.DefineDirectMemoryAccess(DMA).Givetwoexamplesinwhichitisuseful. 9.Whatisthemaincauseinthedifferenceincostbetweenacontextswitchforprocessesand kernellevelthreadsofthesameprocess? 10.Listtwokeydifferencesbetweenprocessesandthreads.

11.Listtwosimilaritiesbetweenprocessesandthreads.

12.Discussanyadditionalhardwareand/orsoftware(codeand/ordata)considerations necessarytopermitamultiprocessingOSto.... (a)spoolprocesses(jobs). (b)implementtimesharingtocreatetheillusionofprocessesexecutinginparallel. (c)implementadynamicpriority(timesharing)schedulingschemethatestimateshowI/O boundaprocessis(basedonmeasurementsfromasinglequantumofCPUusage),andusesthis estimateinordertogiveheavilyI/Oboundprocesseshigherpriority. 13.True/False. (a)Aninterruptcanbedeliveredwhileinsideaninterrupthandler. (b)Changingthesystemclockisaprivilegedoperation. (c)Withoutkernellevelsupport,ablockinguserlevelthreadwillblockalltheother threadsinthesameprocess. (d)Contextswitchingbetweenthreadsismoreexpensivethancontextswitching betweenprocesses. (e)Ifjobruntimesareknown,theSJFschedulerprovidesoptimalaveragewaiting timeforjobs. 14.WhydidtheUnixschedulerallowprioritiestobedynamicallyadjusted?Whydidntitjust setprioritiesstatically? 15.Supposethatthefollowingjobsarriveasindicatedforschedulingandexecutionona singleCPU. Job ArrivalTime Size(msec) Priority J1 0 12 1 J2 2 4 3 J3 5 2 1 J4 8 10 3 J5 10 6 2 DrawaGanttchartsshowing(a)FCFS,(b)preemptiveSJF,(c)nonpreemptiveSJF,(d)RR (quantum=4)and(e)preemptivePRIORITYschedulingforthesejobs,andcalculatethe averagejobwaitingtime. 16.ExplaintheadvantagesanddisadvantagesofShortestJobFirst(SJF)scheduling. ExplainwhywesaythattheMultiLevelFeedbackQueue(MLFQ)isanapproximationto SJF.WhydoesMLFQnothavethedisadvantagesofSJF? 17.Whatinformationsharethefatherandchildafterexecutingthefollowingcode? if(fork()!=0) wait(&status); else

execve(ls,parameters,0); (a)Openfiledescriptors. (b)Stacksegment. (c)Datasegment. (d)Codesegment. 18.Giventhefollowingprogramcalledcreate_process1:


#include <stdio.h> main (int argc, char **argv) { int num_proc, i, pid; num_proc = atoi (argv[1]); for (i=o; i<num_proc; i++) { pid = fork(); if (pid == 0) { write (1, I am a process, 14); } } }

Andtheprogram create_process2:
#include <stdio.h> main (int argc, char **argv) { int num_proc, i, pid, status; num_proc = atoi (argv[1]); for (i=o; i<num_proc; i++) { pid = fork(); if (pid == 0) { write (1, I am a process, 14); } else wait (&status); } }

Answerthefollowingquestions: a)Drawtheprocesshierarchyforexecutingcreate_process13ycreate_process23. b)Isispossiblethattheexecutionresultsinzombies? c)Whathappensiftheusercallscreate_process150?Why?Howcantheprogrambemodified inordertoavoidtheseproblems? 20.Thefollowingprogramimplementsamathematicalfunctioncomputedthroughthecreation ofagroupofprocesses:


int num=4; int pid1,pid2; int res1,res2; while(1) { if((0==num)||(1==num)){ printf("res:%d\n",num);

exit(num); } else { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); if (pid2 > 0) { waitpid(pid1,&res1,0); waitpid(pid2,&res2,0);

printf("res:%d+%d=%d\n",res1,res2,res1+res2); exit(res1+res2); }else{ num=num2; } }else{ num=num1; } } }

Answerthefollowingquestions: (a) Drawtheprocesstreeandwriteineachnodethefollowinginformation: pid(startingwith1). Returncode. Otherrelevantinformation. (b) Whichistheoutputoftheprogram(manysolutionsarepossible). (c)Iftheinitialvalueofnumischanged,howdoestheexecutionoftheprogramchange? (d)Whatistheimplementedmathematicalfunction? NOTE:thefunctionwaitpidwaitsuntiltheprocessidentifiedbythefirstparameter terminates.Thereturnvalueofthechildprocessisreturnedinthesecondparameter.

Das könnte Ihnen auch gefallen