Beruflich Dokumente
Kultur Dokumente
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
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); } }
exit(num); } else { pid1 = fork(); if (pid1 > 0) { pid2 = fork(); if (pid2 > 0) { waitpid(pid1,&res1,0); waitpid(pid2,&res2,0);
Answerthefollowingquestions: (a) Drawtheprocesstreeandwriteineachnodethefollowinginformation: pid(startingwith1). Returncode. Otherrelevantinformation. (b) Whichistheoutputoftheprogram(manysolutionsarepossible). (c)Iftheinitialvalueofnumischanged,howdoestheexecutionoftheprogramchange? (d)Whatistheimplementedmathematicalfunction? NOTE:thefunctionwaitpidwaitsuntiltheprocessidentifiedbythefirstparameter terminates.Thereturnvalueofthechildprocessisreturnedinthesecondparameter.