1、3.1Operating SystemChapter 3:Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem Structure nVirtual MachinesnSystem Design and ImplementationnSystem Generation3.2Operating SystemCommon System ComponentsnProcess Management nMain Memory Managemen
2、tnFile ManagementnI/O System ManagementnSecondary ManagementnNetworkingnProtection SystemnCommand-Interpreter System3.3Operating SystemProcess ManagementnA process is a program in execution.A process needs certain resources,including CPU time,memory,files,and I/O devices,to accomplish its task.nThe
3、operating system is responsible for the following activities in connection with process management.FProcess creation and deletion.Fprocess suspension and resumption.FProvision of mechanisms for:4process synchronization4process communication3.4Operating SystemMain-Memory ManagementnMemory is a large
4、array of words or bytes,each with its own address.It is a repository of quickly accessible data shared by the CPU and I/O devices.nMain memory is a volatile storage device.It loses its contents in the case of system failure.3.5Operating SystemnThe operating system is responsible for the following ac
5、tivities in connections with memory management:FKeep track of which parts of memory are currently being used and by whom.FDecide which processes to load when memory space becomes available.FAllocate and deallocate memory space as needed.3.6Operating SystemFile ManagementnA file is a collection of re
6、lated information defined by its creator.Commonly,files represent programs(both source and object forms)and data.nThe operating system is responsible for the following activities in connections with file management:FFile creation and deletion.FDirectory creation and deletion.FSupport of primitives f
7、or manipulating files and directories.FMapping files onto secondary storage.FFile backup on stable(nonvolatile)storage media.3.7Operating SystemI/O System ManagementnThe I/O system consists of:FA buffer-caching system FA general device-driver interfaceFDrivers for specific hardware devices3.8Operati
8、ng SystemSecondary-Storage ManagementnSince main memory(primary storage)is volatile and too small to accommodate all data and programs permanently,the computer system must provide secondary storage to back up main memory.3.9Operating SystemnMost modern computer systems use disks as the principle on-
9、line storage medium,for both programs and data.nThe operating system is responsible for the following activities in connection with disk management:FFree space managementFStorage allocationFDisk scheduling3.10Operating SystemCommand-Interpreter SystemnMany commands are given to the operating system
10、by control statements which deal with:Fprocess creation and managementFI/O handlingFsecondary-storage managementFmain-memory managementFfile-system access Fprotection Fnetworking3.11Operating SystemCommand-Interpreter System(Cont.)nThe program that reads and interprets control statements is called v
11、ariously:Fcommand-line interpreterFshell(in UNIX)Its function is to get and execute the next command statement.3.12Operating SystemOperating System ServicesnProgram execution system capability to load a program into memory and to run it.nI/O operations since user programs cannot execute I/O operatio
12、ns directly,the operating system must provide some means to perform I/O.nFile-system manipulation program capability to read,write,create,and delete files.3.13Operating SystemnCommunications exchange of information between processes executing either on the same computer or on different systems tied
13、together by a network.Implemented via shared memory or message passing.nError detection ensure correct computing by detecting errors in the CPU and memory hardware,in I/O devices,or in user programs.3.14Operating SystemAdditional Operating System FunctionsAdditional functions exist not for helping t
14、he user,but rather for ensuring efficient system operations.Resource allocation allocating resources to multiple users or multiple jobs running at the same time.Accounting keep track of and record which users use how much and what kinds of computer resources for account billing or for accumulating u
15、sage statistics.Protection ensuring that all access to system resources is controlled.3.15Operating SystemSystem CallsnSystem calls provide the interface between a running program and the operating system.FGenerally available as assembly-language instructions.FLanguages defined to replace assembly l
16、anguage for systems programming allow system calls to be made directly(e.g.,C,C+)3.16Operating SystemnThree general methods are used to pass parameters between a running program and the operating system.FPass parameters in registers.FStore the parameters in a table in memory,and the table address is
17、 passed as a parameter in a register.FPush(store)the parameters onto the stack by the program,and pop off the stack by operating system.3.17Operating SystemPassing of Parameters As A Table3.18Operating SystemTypes of System CallsnProcess controlnFile managementnDevice managementnInformation maintena
18、ncenCommunications3.19Operating SystemMS-DOS ExecutionAt System Start-upRunning a Program3.20Operating SystemUNIX Running Multiple Programs3.21Operating SystemCommunication ModelsMsg PassingShared MemorynCommunication may take place using either message passing or shared memory.3.22Operating SystemS
19、ystem ProgramsnSystem programs provide a convenient environment for program development and execution.The can be divided into:FFile manipulation FStatus informationFFile modificationFProgramming language supportFProgram loading and executionFCommunicationsFApplication programsnMost users view of the
20、 operation system is defined by system programs,not the actual system calls.3.23Operating SystemMS-DOS System Structure nMS-DOS written to provide the most functionality in the least spaceFnot divided into modulesFAlthough MS-DOS has some structure,its interfaces and levels of functionality are not
21、well separated3.24Operating SystemMS-DOS Layer Structure3.25Operating SystemUNIX System Structure nUNIX limited by hardware functionality,the original UNIX operating system had limited structuring.The UNIX OS consists of two separable parts.FSystems programsFThe kernel4Consists of everything below t
22、he system-call interface and above the physical hardware4Provides the file system,CPU scheduling,memory management,and other operating-system functions;a large number of functions for one level.3.26Operating SystemUNIX System Structure3.27Operating SystemLayered ApproachnThe operating system is divi
23、ded into 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 layers.3.28Operating SystemAn Opera
24、ting System Layer3.29Operating SystemMicrokernel System Structure nMoves as much from the kernel into“user”space.nCommunication takes place between user modules using message passing.nBenefits:-easier to extend a microkernel(微内核)-easier to port the operating system to new architectures-more reliable
25、(less code is running in kernel mode)-more secure3.30Operating SystemVirtual MachinesnA virtual machine takes the layered approach to its logical conclusion.It treats hardware and the operating system kernel as though they were all hardware.nA virtual machine provides an interface identical to the u
26、nderlying bare hardware.nThe operating system creates the illusion of multiple processes,each executing on its own processor with its own(virtual)memory.3.31Operating SystemVirtual Machines(Cont.)nThe resources of the physical computer are shared to create the virtual machines.FCPU scheduling can cr
27、eate the appearance that users have their own processor.FSpooling and a file system can provide virtual card readers and virtual line printers.FA normal user time-sharing terminal serves as the virtual machine operators console.3.32Operating SystemSystem ModelsNon-virtual MachineVirtual Machine3.33O
28、perating SystemAdvantages/Disadvantages of Virtual Machines nThe virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from all other virtual machines.This isolation,however,permits no direct sharing of resources.3.34Operating SystemnA virtua
29、l-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 is difficult to implement due to the effort required to
30、 provide an exact duplicate to the underlying machine.3.35Operating SystemJava Virtual MachinenCompiled Java programs are platform-neutral bytecodes executed by a Java Virtual Machine(JVM).nJVM consists of-class loader-class verifier-runtime interpreternJust-In-Time(JIT)compilers increase performanc
31、e3.36Operating SystemJava Virtual Machine3.37Operating SystemSystem Design GoalsnUser goals operating system should be convenient to use,easy to learn,reliable,safe,and fast.nSystem goals operating system should be easy to design,implement,and maintain,as well as flexible,reliable,error-free,and eff
32、icient.3.38Operating SystemMechanisms and PoliciesnMechanisms determine how to do something,policies decide what will be done.nThe separation of policy from mechanism is a very important principle,it allows maximum flexibility if policy decisions are to be changed later.3.39Operating SystemSystem Im
33、plementationnTraditionally written in assembly language,operating systems can now be written in higher-level languages.nCode written in a high-level language:Fcan be written faster.Fis more compact.Fis easier to understand and debug.nAn operating system is far easier to port(move to some other hardw
34、are)if it is written in a high-level language.3.40Operating SystemSystem Generation(SYSGEN)nOperating systems are designed to run on any of a class of machines;the system must be configured for each specific computer site.nSYSGEN program obtains information concerning the specific configuration of the hardware system.nBooting starting a computer by loading the kernel.nBootstrap program code stored in ROM that is able to locate the kernel,load it into memory,and start its execution.3.41Operating System3.73.83.113.13