1、Chapter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationChapter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem Struc
2、turenVirtual MachinesnSystem Design and ImplementationCommon System ComponentsnProcess ManagementnMain Memory ManagementnSecondary-Storage ManagementnI/O System ManagementnFile ManagementnProtection SystemnNetworkingnCommand-Interpreter SystemProcess ManagementnA process is a program in execution.A
3、process needs certain resources,including CPU time,memory,files,and I/O devices,to accomplish its task.nThe operating system is responsible for the following activities in connection with process management.在同进程管理有关的活动中,操作系统负责下列事务在同进程管理有关的活动中,操作系统负责下列事务nProcess creation and deletion.nprocess suspens
4、ion and resumption.nProvision of mechanisms for nprocess synchronizationnprocess communicationMain-Memory ManagementnMemory is a large 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
5、device.It loses its contents in the case of system failure.nThe operating system is responsible for the following activities in connections with memory management:nKeep track of which parts of memory are currently being used and by whom.nDecide which processes to load when memory space becomes avail
6、able.nAllocate and deallocate memory space as needed.Secondary-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.nMost modern computer systems use d
7、isks as the principle on-line storage medium,for both programs and data.nThe operating system is responsible for the following activities in connection with disk managementnFree space managementnStorage allocationnDisk schedulingI/O System ManagementnThe I/O system consists of:nA buffer-caching syst
8、emnA general device-driver interfacenDrivers for specific hardware devicesFile ManagementnA file is a collection of related 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
9、connections with file management:nFile creation and deletion.nDirectory creation and deletion.nSupport of primitives原语 for manipulating files and directories.nMapping files onto secondary storage.nFile backup on stable(nonvolatile)storage media.Protection SystemnProtection refers to a mechanism for
10、controlling access by programs,processes,or users to both system and user resources.nThe protection mechanism mustndistinguish between authorized and unauthorized usage.nspecify the controls to be imposed.nprovide a means of enforcement.Networking(Distributed Systems)nA distributed system is a colle
11、ction processors that do not share memory or a clock.Each processor has its own local memory.nThe processors in the system are connected through a communication network.nA distributed system provides user access to various system resources.nAccess to a shared resource allows:nComputation speed-up 加速
12、运算加速运算nIncreased data availability 提高数据利用性提高数据利用性nEnhanced reliability 增强可靠性增强可靠性Command-Interpreter SystemnMany commands are given to the operating system by control statements which deal with:nprocess creation and managementnI/O handlingnsecondary-storage managementnmain-memory managementnfile-sys
13、tem accessnprotectionnnetworkingCommand-Interpreter System(Cont.)nThe program that reads and interprets control statements is called variously:ncontrol-card interpreter ncommand-line interpreter nshell(in UNIX)Its function is to get and execute the next command statement.Chapter 3 Operating-System S
14、tructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationOperating System ServicesnProgram execution system capability to load a program into memory and to run it.nI/O operations since user programs cannot ex
15、ecute I/O operations directly,the operating system must provide some means to perform I/O.nFile-system manipulation program capability to read,write,create,and delete files.nCommunications exchange of information between processes executing either on the same computer or on different systems tied to
16、gether 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.Additional Operating System Functions Additional functions exist not for helping the user,but rather fo
17、r 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 usage statistics.Prote
18、ction ensuring that all access to system resources is controlled.System CallsnSystem calls provide the interface between a running program and the operating system.nGenerally available as assembly-language instructions.nLanguages defined to replace assembly language for systems programming allow sys
19、tem calls to be made directly nThree general methods are used to pass parameters between a running program and the operating system.nPass parameters in registers.nStore the parameters in a table in memory,and the table address is passed as a parameter in a register.nPush(store)the parameters onto th
20、e stack by the program,and pop off the stack by operating system.Passing of Parameters As A Table 表格方式的参数传递表格方式的参数传递Chapter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationSystem
21、Calls(Cont.)nProcess controlnFile managementnDevice managementnInformation maintenancenCommunicationsSystem Call process controlnend,abortnload,executencreate process,terminate processnget process attributes,set process attributesnwait for timenwait event,signal eventnAllocate and free memoryMS-DOS
22、ExecutionAt System Start-up系统启动系统启动Running a Program运行程序运行程序UNIX Running Multiple ProgramsSystem Call file managementncreate file,delete filenopen,closenread,write,repositionnget file attributes,set file attributesSystem Call device managementnrequest device,release devicenread,write,repositionnget
23、device attributes,set device attributesnlogically attach or detach devicesSystem Call information managementnget time or date,set time or datenget system data,set system datanget process,file,or device attributesnset process,file,or device attributesSystem Call communicationsncreate,delete communica
24、tion connectionnsend,receive messagesntransfer status informationnattach or detach remote devicesCommunication ModelsMsg Passing Shared Memory Chapter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Desig
25、n and ImplementationSystem ProgramsnSystem programs provide a convenient environment for program development and execution.They can be divided into:nFile manipulationnStatus informationnFile modificationnProgramming language supportnProgram loading and executionnCommunicationsnApplication programsCh
26、apter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationSystem Structure Layered ApproachnThe operating system is divided into a number of layers(levels),each built on top of lower
27、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.An Operating System LayerLayered Structure of the THE OSnA layered design was first used in
28、 THE operating system.Its six layers are as follows:layer 5:user programslayer 4:buffering for input and outputlayer 3:operator-console device driverlayer 2:memory managementlayer 1:CPU schedulinglayer 0:hardwareMicrokernelsWindows NT Client-Server StructureChapter 3 Operating-System StructuresnSyst
29、em ComponentsnOperating System ServicesnSystem CallsnSystem ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationVirtual MachinesnA virtual machine takes the layered approach to its logical conclusion.It treats hardware and the operating system kernel as though they were all ha
30、rdware.虚拟机是层次化的逻辑结果虚拟机是层次化的逻辑结果nA virtual machine provides an interface identical to the underlying bare hardware.nThe operating system creates the illusion of multiple processes,each executing on its own processor with its own(virtual)memory.操作系统创建了多个进程,每个进程在其处理器和(虚拟)内存执行操作系统创建了多个进程,每个进程在其处理器和(虚拟)内
31、存执行Virtual Machines(Cont.)nThe resources of the physical computer are shared to create the virtual machines.nCPU scheduling can create the appearance that users have their own processor.nSpooling and a file system can provide virtual card readers and virtual line printers.nA normal user time-sharing
32、 terminal serves as the virtual machine operators console.普通用户终端成为虚拟机操作员的控制台普通用户终端成为虚拟机操作员的控制台System ModelsNon-virtual Machine Virtual Machine Advantages/Disadvantages of Virtual MachinesnThe virtual-machine concept provides complete protection of system resources since each virtual machine is isola
33、ted from all other virtual machines.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 is difficu
34、lt to implement due to the effort required to provide an exact duplicate to the underlying machine.The Java Virtual MachineJava.class File on Cross Platforms跨平台的Java.class文件Java Development EnvironmentChapter 3 Operating-System StructuresnSystem ComponentsnOperating System ServicesnSystem CallsnSyst
35、em ProgramsnSystem StructurenVirtual MachinesnSystem Design and ImplementationSystem 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,e
36、rror-free,and efficient.Mechanisms 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.
37、System ImplementationnTraditionally written in assembly language,operating systems can now be written in higher-level languages.nCode written in a high-level language:ncan be written faster.nis more compact.nis easier to understand and debug.nAn operating system is far easier to port(move to some other hardware)if it is written in a high-level language.HomeworknP83 n3.5n3.7n3.13n3.15