《operatingsystem《操作系统》ch02-operating-systemstructu.ppt》由会员分享,可在线阅读,更多相关《operatingsystem《操作系统》ch02-operating-systemstructu.ppt(41页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Chapter 2:Operating-System Structures2.2Chapter ObjectivesnView OS from:lServiceslInterfaceslComponents and InterconnectionsnTo describe the services an operating system provides to users,processes,and other systemsnTo discuss the various ways of structuring an operating systemnTo explain how operat
2、ing systems are installed and customized and how they boot2.3Content OverviewnOperating System ServicesnUser Operating System InterfacenSystem CallsnTypes of System CallsnSystem ProgramsnOperating System Design and ImplementationnOperating System StructurenVirtual MachinesnOperating System Generatio
3、nnSystem Boot2.42.1 Operating System ServicesnOne set of operating-system services provides functions that are helpful to the user:lUser interface-Almost all operating systems have a user interface(UI)4Varies between Command-Line(CLI),Graphics User Interface(GUI),Batch programming interfacelProgram
4、execution-The system must be able to load a program into memory and to run that program,end execution,either normally or abnormally(indicating error)lI/O operations-A running program may require I/O,which may involve a file or an I/O device.lFile-system manipulation-The file system is of particular
5、interest.Obviously,programs need to read and write files and directories,create and delete them,search them,list file Information,permission management.2.5Operating System Services(Cont.)nOne set of operating-system services provides functions that are helpful to the user(Cont):lCommunications Proce
6、sses may exchange information,on the same computer or between computers over a network4Communications may be via shared memory or through message passing(packets moved by the OS)lError detection OS needs to be constantly aware of possible errors4May occur in the CPU and memory hardware,in I/O device
7、s,in user program4For each type of error,OS should take the appropriate action to ensure correct and consistent computing4Debugging facilities can greatly enhance the users and programmers abilities to efficiently use the system2.6Operating System Services(Cont.)nAnother set of OS functions exists f
8、or ensuring the efficient operation of the system itself via resource sharinglResource allocation-When multiple users or multiple jobs running concurrently,resources must be allocated to each of them4Many types of resources-Some(such as CPU cycles,mainmemory,and file storage)may have special allocat
9、ion code,others(such as I/O devices)may have general request and release code.lAccounting-To keep track of which users use how much and what kinds of computer resourceslProtection and security-The owners of information stored in a multiuser or networked computer system may want to control use of tha
10、t information,concurrent processes should not interfere with each other4Protection involves ensuring that all access to system resources is controlled4Security of the system from outsiders requires user authentication,extends to defending external I/O devices from invalid access attempts4If a system
11、 is to be protected and secure,precautions must be instituted throughout it.A chain is only as strong as its weakest link.2.72.2 User Operating System InterfacenCLI(Command Line Interface)allows direct command entry4Sometimes implemented in kernel,sometimes by systems program4Sometimes multiple flav
12、ors implemented shells4Primarily fetches a command from user and executes itSometimes commands built-in,sometimes just names of programsIf the latter,adding new features doesnt require shell modification2.8User Operating System Interface-GUInUser-friendly desktop metaphor interfacelUsually mouse,key
13、board,and monitorlIcons represent files,programs,actions,etclVarious mouse buttons over objects in the interface cause various actions(provide information,options,execute function,open directory(known as a folder)lInvented at Xerox PARC 1970snMany systems now include both CLI and GUI interfaceslMicr
14、osoft Windows is GUI with CLI“command”shelllApple Mac OS X as“Aqua”GUI interface with UNIX kernel underneath and shells availablelSolaris is CLI with optional GUI interfaces(Java Desktop,KDE)2.92.3 System CallsnProgramming interface to the services provided by the OSnTypically written in a high-leve
15、l language(C or C+)nMostly accessed by programs via a high-level Application Program Interface(API)rather than direct system call usenThree most common APIs are:lWin32 API for Windows,lPOSIX API for POSIX-based systems(including virtually all versions of UNIX,Linux,and Mac OS X),and lJava API for th
16、e Java virtual machine(JVM)2.10Example of System CallsnSystem call sequence to copy the contents of one file to another filen Why use APIs rather than system calls?Program portability/convenience/2.11Example of Standard APInConsider the ReadFile()function in the Win32 APIa function for reading from
17、a filenA description of the parameters passed to ReadFile()lHANDLE file the file to be readlLPVOID buffer a buffer where the data will be read into and written fromlDWORD bytesToRead the number of bytes to be read into the bufferlLPDWORD bytesRead the number of bytes read during the last readlLPOVER
18、LAPPED ovl indicates if overlapped I/O is being used2.12System Call ImplementationnTypically,a number associated with each system calllSystem-call interface maintains a table indexed according to these numbersnThe system call interface invokes intended system call in OS kernel and returns status of
19、the system call and any return valuesnThe caller need know nothing about how the system call is implementedlJust needs to obey API and understand what OS will do as a result calllMost details of OS interface hidden from programmer by API 4Managed by run-time support library(set of functions built in
20、to libraries included with compiler)2.13API System Call OS Relationship2.14Standard C Library ExamplenC program invoking printf()library call,which calls write()system call2.15System Call Parameter PassingnOften,more information is required than simply identity of desired system calllExact type and
21、amount of information vary according to OS and callnThree general methods used to pass parameters to the OSlSimplest:pass the parameters in registers4 In some cases,may be more parameters than registerslParameters stored in a block,or table,in memory,and address of block passed as a parameter in a r
22、egister 4This approach taken by Linux and SolarislParameters placed,or pushed,onto the stack by the program and popped off the stack by the operating system Block and stack methods do not limit the number or length of parameters being passed2.16Parameter Passing via TableX:address of table2.172.4 Ty
23、pes of System CallsnProcess control end,abort/load,execute/create process,terminate process/get process attributes,set process attributes/wait for time/wait event,signal event/allocate and free memorynFile management create file,delete file/open,close/read,write,reposition/get file attributes,set fi
24、le attributesnDevice management request device,release device/read,write,reposition/get device attributes,set device attributes/logically attach or detach devicesnInformation maintenance get time or date,set time or date/get system data,set system data/get process,file,or device attributes/set proce
25、ss,file,or device attributesnCommunications create,delete communication connection/send,receive messages/transfer status information/attach or detach remote devices2.18Examples of Windows and Unix System Calls2.19*Process control:MS-DOS execution(a)At system startup(b)running a program2.20*FreeBSD R
26、unning Multiple Programs2.212.5 System ProgramsnProvide a convenient environment for program development and executionlSome of them are simply user interfaces to system calls;others are considerably more complexnFile management-Create,delete,copy,rename,print,dump,list,and generally manipulate files
27、 and directoriesnStatus informationlSome ask the system for info-date,time,amount of available memory,disk space,number of userslOthers provide detailed performance,logging,and debugging informationlTypically,these programs format and print the output to the terminal or other output deviceslSome sys
28、tems implement a registry-used to store and retrieve configuration information2.22System Programs(contd)nFile modificationlText editors to create and modify fileslSpecial commands to search contents of files or perform transformations of the textnProgramming-language support-Compilers,assemblers,deb
29、uggers and interpreters sometimes providednProgram loading and execution-Absolute loaders,relocatable loaders,linkage editors,and overlay-loaders,debugging systems for higher-level and machine languagenCommunications-Provide the mechanism for creating virtual connections among processes,users,and co
30、mputer systemslAllow users to send messages to one anothers screens,browse web pages,send electronic-mail messages,log in remotely,transfer files from one machine to another2.232.6 Operating System Design 2.6 Operating System Design and Implementationand ImplementationnDesign and Implementation of O
31、S not“solvable”,but some approaches have proven successfulnInternal structure of different Operating Systems can vary widelynStart by defining goals and specifications nAffected by choice of hardware,type of systemnUser goals and System goalslUser goals operating system should be convenient to use,e
32、asy to learn,reliable,safe,and fastlSystem goals operating system should be easy to design,implement,and maintain,as well as flexible,reliable,error-free,and efficient2.24Operating System Design and Implementation(Cont.)Operating System Design and Implementation(Cont.)nImportant principle to separat
33、ePolicy:What will be done?Mechanism:How to do it?nMechanisms determine how to do something,policies decide what will be donelSuch as the timer construct is a Mechanism,and how long the timer is to be set is Policy.lThe separation of policy from mechanism is a very important principle,it allows maxim
34、um flexibility if policy decisions are to be changed laternImplementation Traditionally,operating systems have been written in assembly language.Now,however,they are most commonly written in higher-level languages such as C or C+.2.252.7 Operating-System Structure2.7 Operating-System StructurenSimpl
35、e Structure MS-DOS written to provide the most functionality in the least spacelNot divided into moduleslAlthough MS-DOS has some structure,its interfaces and levels of functionality are not well separatedlDifficult to implement and maintain.2.26Layered ApproachnThe operating system is divided into
36、a number of layers(levels),each built on top of lower layers.The bottom layer(layer 0),is the hardware;the highest(layer N)is the user interface.nWith modularity,layers are selected such that each uses functions(operations)and services of only lower-level layersnSimplicity of construction and debugg
37、ingnIt is difficult to define the various layersnLess efficient2.27UNIXnUNIX limited by hardware functionality,the original UNIX operating system had limited structuring.The UNIX OS consists of two separable partslSystems programslThe kernel4Consists of everything below the system-call interface and
38、 above the physical hardware4Provides the file system,CPU scheduling,memory management,and other operating-system functions;a large number of functions for one level2.28UNIX System Structure2.29Microkernel System Structure nMoves as much nonessential parts from the kernel into“user”space,provide min
39、imal process and memory management.nCommunication takes place between user modules using message passingnBenefits:lEasier to extend a microkernellEasier to port the operating system to new architectureslMore reliable(less code is running in kernel mode)lMore securenDetriments:lPerformance overhead o
40、f user space to kernel space communicationnExamplesl Mach True64 Unix QNX2.30ModulesnMost modern operating systems implement module kernel lUses object-oriented approachlEach core component is separatelEach talks to the others over known interfaceslEach is loadable as needed within the kernelnAllows
41、 the kernel to provide core services yet also allows certain features to be implemented dynamically.nOverall,similar to layers but with more flexible2.31Solaris Modular Approach2.32Mac OS X hybrid structure2.332.8 Virtual MachinesnThe fundamental idea behind a virtual machine is to abstract the hard
42、ware of a single computer into several different execution environments,thereby creating the illusion that each separate execution environment is running its own private computer.nA virtual machine takes the layered approach to its logical conclusion.It treats hardware and the operating system kerne
43、l as though they were all hardwarenA virtual machine provides an interface identical to the underlying bare hardwarenThe operating system creates the illusion of multiple processes,each executing on its own processor with its own(virtual)memory2.34Virtual Machines(Cont.)nThe resources of the physica
44、l computer are shared to create the virtual machineslCPU scheduling can create the appearance that users have their own processorlSpooling and a file system can provide virtual card readers and virtual line printerslA normal user time-sharing terminal serves as the virtual machine operators console2
45、.35Virtual Machines(Cont.)(a)Nonvirtual machine (b)virtual machineNon-virtual MachineVirtual Machine2.36Virtual Machines(Cont.)(Cont.)nThe virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines.This isolation,ho
46、wever,permits no direct sharing of resources.nA virtual-machine system is a perfect vehicle for operating-systems research and development.System development is done on the virtual machine,instead of on a physical machine and so does not disrupt normal system operation.nThe virtual machine concept i
47、s difficult to implement due to the effort required to provide an exact duplicate to the underlying machine2.37VMware Architecture2.38The Java Virtual Machine2.392.9 Operating System GenerationnOperating systems are designed to run on any of a class of machines;the system must be configured for each
48、 specific computer sitenSYSGEN program obtains information concerning the specific configuration of the hardware systemnBooting starting a computer by loading the kernelnBootstrap program code stored in ROM that is able to locate the kernel,load it into memory,and start its execution2.402.10 System
49、BootnOperating system must be made available to hardware so hardware can start itlSmall piece of code bootstrap loader,locates the kernel,loads it into memory,and starts itlSometimes two-step process where boot block at fixed location loads bootstrap loaderlWhen power initialized on system,execution starts at a fixed memory location4Firmware used to hold initial boot codenHomework 2.1 2 3 5 8 13 End of Chapter 2