操作系统原理及应用_第1页
操作系统原理及应用_第2页
操作系统原理及应用_第3页
操作系统原理及应用_第4页
操作系统原理及应用_第5页
已阅读5页,还剩93页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

操作系统原理及应用Chapter2Operating-System

StructuresOperatingSystemFunctionsOperatingSystemServicesOperatingSystemInterfacesOperatingSystemStructureOperatingSystemDesignandImplementationOutlineCommonFunctionsofOSProcessManagementMainMemoryManagementFileManagementSecondary-StorageManagementI/OSystemManagementProcessManagementAprocessisaprograminexecutionSystemProcessesandUserProcessesActivitiesforprocessmanagementProcesscreationanddeletionprocesssuspensionandresumptionProvisionofmechanismsforprocesssynchronizationprocesscommunicationDeadlockhandlingMain-MemoryManagementMemoryisalargearrayofwordsorbytes,eachwithitsownaddress.ItisgenerallytheonlylargestoragedevicethattheCPUisabletoaddressandaccessdirectly.Mainmemoryisavolatilestoragedevice.Activitiesformain-memorymanagementRecordtheusageofMain-memoryAllocateanddeallocatememoryspaceasneededFileManagement(1/2)Therearedifferenttypesofphysicalmediatostoreinformation.Eachofthemhasitsowncharacteristicsandphysicalorganization.AccessspeedData-transferrateAccessmethod(sequentialorrandom)OperatingSystemprovidesauniformlogicalviewofinformationstorage,i.e.,file.Afileisacollectionofrelatedinformation(programsanddata)definedbyitscreator.ActivitiesforfilemanagementFilecreationanddeletionDirectorycreationanddeletionSupportofprimitivesformanipulatingfilesanddirectoriesMappingfilesontosecondarystorageFilebackuponstable(nonvolatile)storagemediaFileManagement(2/2)Secondary-StorageManagementSincemainmemory(primarystorage)isvolatileandtoosmalltoaccommodatealldataandprogramspermanently,thecomputersystemmustprovidesecondarystoragetobackupmainmemory.Mostmoderncomputersystemsusedisksastheprincipleon-linestoragemedium,forbothprogramsanddata.Secondary-StorageManagementActivitiesfordiskmanagementFreespacemanagementStorageallocationDiskschedulingI/OSystemManagementHidingthepeculiaritiesofspecifichardwaredevicesfromtheuserTheI/OsubsystemconsistsofAmemory-managementcomponentincludingbuffer,caching,spoolingAgeneraldevice-driverinterfaceDriversforspecifichardwaredevicesOperatingSystemFunctionsOperatingSystemServicesOperatingSystemInterfacesOperatingSystemStructureOperatingSystemDesignandImplementationOutlineOperatingSystemServices(1/2)ServicesforhelpingUsersProgramexecution–systemcapabilitytoloadaprogramintomemoryandtorunit.I/Ooperations–sinceuserprogramscannotexecuteI/Ooperationsdirectly,theoperatingsystemmustprovidesomemeanstoperformI/O.File-systemmanipulation–programcapabilitytoread,write,create,anddeletefiles.Communications–exchangeofinformationbetweenprocesses(sharedmemoryormessagepassing)Errordetection–ensurecorrectcomputingbydetectingerrorsinhardwaresorinuserprograms.ServicesforensuringsystemoperationsResourceallocation–allocatingresourcestomultipleusersormultiplejobsrunningatthesametime.Accounting–keeptrackofwhichusersusehowmuchandwhatkindsofcomputerresources.Protection–ensuringthatallaccesstosystemresourcesiscontrolledandrecordingalltheconnectionsfordetectionofbreak-ins.OperatingSystemServices(2/2)OperatingSystemFunctionsOperatingSystemServicesOperatingSystemInterfacesOperatingSystemStructureOperatingSystemDesignandImplementationOutlineInterfacestoUsersCommand-LineInterface–textcommandsBatchInterface–filesincludingsomecommandsGraphicalUserInterface–windowsystemOperatingSystemInterfaces(1/4)Command-lineInterpreter(Shell)TheprogramthatreadsandinterpretscontrolstatementsDOSOS:TwowaystoimplementcommandsInternalCommand:Thecommandinterpreteritselfcontainsthecodetoexecutethecommand.(dir,copy)ExternalCommand:Systemprogramesimplementmostcommands.(rm,fdisk,format)OperatingSystemInterfaces(2/4)Graphicaluserinterface(GUI)Desktop:Mouse-basedwindow-and-menusystemIcons,foldersMobilesystemGesturesonthetouchscreenManysystemsnowincludebothCLIandGUIinterfacesOperatingSystemInterfaces(3/4)InterfacestoProgramesSystemcallsTypicallywritteninassembly-languageinstructionsorahigh-levellanguage(CorC++)Mostlyaccessedbyprogramsviaahigh-levelApplicationProgramInterface(API)ratherthandirectsystemcalluseOperatingSystemInterfaces(4/4)ExampleofSystemCallsSystemcallsequencetocopythecontentsofonefiletoanotherfileSystemCallImplementationApplicationProgrammingInterface(API)APIfunctionsinvoketheactualsystemcallsonbehalfoftheapplicationprogrammerJustneedstoobeyAPIandunderstandwhatOSwilldoasaresultcall,mostdetailsofOSinterfacehiddenfromprogrammerbyAPIAPIsareManagedbyrun-timesupportlibrary(setoffunctionsbuiltintolibrariesincludedwithcompiler)SystemCallImplementationSystem-callInterface(SCI)Typically,anumberassociatedwitheachsystemcallSystem-callinterfacemaintainsatableindexedaccordingtothesenumbersThesystemcallinterfaceinvokesintendedsystemcallinOSkernelandreturnsstatusofthesystemcallandanyreturnvaluesDiscussionWhydouseruseAPIsratherthansystemcalls?SystemCallImplementationThreemostcommonAPIsWin32APIforWindowsPOSIXAPIforPOSIX-basedsystems(includingvirtuallyallversionsofUNIX,Linux,andMacOSX)JavaAPIfortheJavavirtualmachine(JVM)RelationshipbetweenAPI,SCI,OSStandardCLibraryExampleCprograminvokingprintf()librarycall,whichcallswrite()systemcallSystemCallParameterPassingOften,moreinformationisrequiredthansimplyidentityofdesiredsystemcallThreegeneralmethodsusedtopassparameterstotheOSSimplest:passtheparametersinregistersParametersstoredinablock,ortable,inmemory,andaddressofblockpassedasaparameterinaregister

Parametersplaced,orpushed,ontothestackbytheprogramandpoppedoffthestackbytheoperatingsystemParameterPassingviaTableTypesofSystemCallsProcesscontrolFilemanagementDevicemanagementInformationmaintenanceCommunicationsTypesofSystemCallsProcesscontrolend,abortload,executecreateandterminateprocessgetandsetprocessattributeswaitfortimewaitevent,signaleventallocateandfreememoryTypesofSystemCallsFilemanagementcreateanddeletefileopenandclosefileread,write,repositiongetandsetfileattributesDevicemanagementrequestandreleasefileread,write,repositiongetandsetdeviceattributeslogicallyattachordetachdevicesTypesofSystemCallsInformationmaintenancegetandsettimeordategetandsetsystemdatagetandsetprocess,fileordeviceattributesCommunicationscreateanddeletecommunicationconnectionsendandreceivemessagetransferstatusinformationattachordetachremotedevicesOperatingSystemFunctionsOperatingSystemServicesOperatingSystemInterfacesOperatingSystemStructureOperatingSystemDesignandImplementationOutlineOperatingSystemStructureSimpleStructureLayeredStructureVirtualMachinesMicrokernelStructureModulesSimpleStructureMS-DOSWrittentoprovidethemostfunctionalityintheleastspaceNotdividedintomodulesAlthoughMS-DOShassomestructure,itsinterfacesandlevelsoffunctionalityarenotwellseparatedMS-DOSLayerStructureOriginalUNIXTwoseparablepartsSystemsprogramsThekernel:Consistsofeverythingbelowthesystem-callinterfaceandabovethephysicalhardware,providesalargenumberoffunctionsforonelevelSimpleStructureUNIXSystemStructureLayeredStructureTheoperatingsystemisdividedintoanumberoflayers(levels),eachbuiltontopoflowerlayers.Thebottomlayer(layer0),isthehardware;thehighest(layerN)istheuserinterface.Withmodularity,layersareselectedsuchthateachusesfunctions(operations)andservicesofonlylower-levellayersLayeredOperatingSystemOS/2LayerStructureMicrokernelStructureMovesasmuchfromthekernelinto“user”spaceTypically,microkernelsprovideminimalprocessmanagement,memorymanagementandcommunicationfacilityCommunicationtakesplacebetweenusermodulesusingmessagepassingMicrokernelStructureBenefitsEasiertoextendaoperatingsystemEasiertoporttheoperatingsystemtonewarchitecturesMorereliable(lesscodeisrunninginkernelmode)MoresecureLacksPerformanceoverheadofuserspacetokernelspacecommunicationModulesMostmodernoperatingsystemsimplementkernelmodulesUsesobject-orientedapproachEachcorecomponentisseparateEachtalkstotheothersoverknowninterfacesEachisloadableasneededwithinthekernelOverall,similartolayersbutwithmoreflexibleSolarisModularApproach设计操作系统时采用的模块化内核方法和分层方法在那些方面类似?哪些方面不同?作业1VirtualMachinesAvirtualmachinetakesthelayeredapproachtoitslogicalconclusion.IttreatshardwareandtheoperatingsystemkernelasthoughtheywereallhardwareAvirtualmachineprovidesaninterfaceidenticaltotheunderlyingbarehardwareTheoperatingsystemcreatesthe“illusion”ofmultipleprocesses,eachexecutingonitsownprocessorwithitsown(virtual)memoryVirtualMachinesNon-virtualMachineVirtualMachineVirtualMachinesAdvantagesProvidingcompleteprotectionofsystemresourcesEachvirtualmachineisisolatedfromallothervirtualmachines.Thisisolation,however,permitsnodirectsharingofresources.BeingabletosharethesamehardwareyetrundifferentoperatingsystemsconcurrentlyAperfectvehicleforoperating-systemsresearchanddevelopmentSystemdevelopmentisdoneonthevirtualmachine,sodoesnotdisruptnormalsystemoperation.VMwareArchitectureJavaVirtualMachineCompiledJavaprogramsareplatform-neutralbytecodesexecutedbyaJavaVirtualMachine(JVM).JVMconsistsofclassloaderruntimeinterpreterJust-In-Time(JIT)compilersincreaseperformanceJavaVirtualMachineJavaVirtualMachineOperatingSystemFunctionsOperatingSystemServicesOperatingSystemInterfacesOperatingSystemStructureOperatingSystemDesignandImplementationOutlineWhatanOSActuallyDoes?VirtualizesthephysicalresourcesHandlesissuesrelatedtoConcurrencyStoresfilesPersistentlyOperatingSystemDesignandImplementationDesignandImplementationofOSnot“solvable”,butsomeapproacheshaveprovensuccessfulInternalstructureofdifferentOperatingSystemscanvarywidelyStartbydefininggoalsandspecificationsAffectedbychoiceofhardware,typeofsystemOperatingSystemDesignandImplementationDesigngoalsUsergoals–operatingsystemshouldbeconvenienttouse,easytolearn,reliable,safe,andfastSystemgoals–operatingsystemshouldbeeasytodesign,implement,andmaintain,aswellasflexible,reliable,error-free,andefficientOperatingSystemDesignandImplementationImportantprincipletoseparatePolicy:Whatwillbedone?Mechanism:Howtodoit?Theseparationofpolicyfrommechanismisaveryimportantprinciple,itallowsmaximumflexibilityifpolicydecisionsaretobechangedlaterOperatingSystemDesignandImplementationWrittenmostlyinCorC++Advantage—beingfareasiertoportDisadvantage—reducedspeedandincreasedstoragerequirementsSomesmallsectionsofassemblycodefordevicedriversandforsavingandrestoringthestateofregistersPart1小结(1/2)操作系统概念(管理各种资源、支持程序运行、方便用户使用的程序集)操作系统的基本目标(方便性与高效性)引导程序、中断、中断处理程序、中断向量存储结构:内存(小、易失)、二级存储(大、非易失)、分层结构I/O结构:设备控制器(本地缓冲)、DMA硬件保护:双重模式操作、特权指令、I/O保护、内存保护、CPU保护Part1小结(2/2)操作系统的发展(大型机(无OS、批处理、多道程序设计(并发性、共享性、虚拟性、异步性)、分时)——桌面——并行(紧耦合)——分布式(松耦合,集群)——专用(实时、手持))操作系统的功能:进程(CPU)管理、内存管理、文件管理、磁盘管理、I/O管理、用户接口操作系统的服务:程序执行、I/O操作、文件系统操作、通信、错误检测与处理、资源分配、统计、保护操作系统的接口:用户接口(CLI、GUI)+程序接口(系统调用(参数传递、类型)、SCI、API)操作系统的结构:简单结构、分层结构(虚拟机)、微核结构(进程管理、内存管理、通信功能)、模块化HistoryEarlyOS:JustLibrariesBatchBeyondLibraries:ProtectionSystemcallinsteadofanormalprocedurecallUsermode/KernelmodeTrap&traphandlerHistoryEraofMultiprogrammingMainfametominicomputerMultiprogrammingMemoryprotectionConcurrencyHistoryTheModernEraMinicomputer–PersonalcomputerDOS:thediskoperatingsystemLackofmemoryprotectionMacOSPainfuljobschedulingModernOSadoptthegoodfeaturesofminicomputerOS.VirtualMachineMonitorsIntroductionMotivationVirtualizingtheCPUVirtualizingtheMemoryTheInformationGapSummaryIntroductionWhatifonewantedtorundifferentoperatingsystemsonthemachineatthesametime?Virtualmachinemonitor(VMM)(alsocalledahypervisor)IBMIntroductionScene:VMMgivestheillusiontoeachrunningOSthatitcontrolsthemachineBehindthescene:VMMisincontrolofthehardware,andmustmultiplexrunningOSesacrossthephysicalresourcesofthemachine.VMMservesasanoperatingsystemforoperatingsystemsIntroductionTheOSmuststillthinkitisinteractingwiththephysicalhardware.TransparencyisamajorgoalofVMMs.IntroductiontoVMwareMarketleaderinvirtualizationtechnologyProfessorMendelRosenblum(Stanford)VirtualMachineMonitorsIntroductionMotivationVirtualizingtheCPUVirtualizingtheMemoryTheInformationGapSummaryMotivationWhyVMMs?Inhistory:IBMmainframesToday:multiplereasonsServerconsolidationApplicationsondifferentplatformsTestinganddebuggingVirtualMachineMonitorsIntroductionMotivationVirtualizingtheCPUVirtualizingtheMemoryTheInformationGapSummaryVirtualizingtheCPUBasictechnique:LimiteddirectexecutionContextswitch–MachineswitchDirectExecutionRestrictedOperationsUsermode/KernelModeInterrupt/trap,handlerSystemcall,API,SCILimitedDirectExecutionRestrictedOperationsDiscussion:WhataboutaTimerInterrupt,insteadofaSoftwareInterrupt?ContextSwitchWillbedetailedinProcessManagement.Save/restorecontext(machinestate)MachineSwitchTheVMMmustsavetheentiremachinestateofoneOS,restorethemachinestateoftheto-be-runVM,andthenjumptothePCoftheto-be-runVMandthuscompletetheswitch.TheOScanbeeitherinusermodeorkernelmode.VirtualizingtheCPUWhatifOStriestoperformaprivilegedoperation?VMMmustsomehowinterceptattemptstoperformprivilegedoperations.Discussion:WHY?Hints:whowilltakecontrolofthemachine?VirtualizingtheCPUWhatifanapplicationtriestomakeasystemcall?Interrupt/trap?Discussion:traditionalsettingwithoutvirtualizationReview:SystemCallVirtualizingtheCPUTransferscontroltoawell-definedtraphandlerwithintheoperatingsystem.ChangesthemodeoftheprocessorfromusermodetokernelmodeVirtualizingtheCPUOnavirtualizedplatform:AfteraninterruptVMMcontrolsthemachine,andthustheVMMwhohasinstalledatraphandlerthatwillfirstgetexecutedinkernelmodeBUT:VMMDOESNOTreallyknowhowtoha

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论