ch1操作系统引论
- 格式:ppt
- 大小:516.00 KB
- 文档页数:51
操作系统_第一章操作系统引论在我们日常使用的电脑和各种智能设备中,操作系统扮演着至关重要的角色。
它就像是一个幕后的大管家,默默地协调着硬件和软件的资源,为我们提供了一个稳定、高效、便捷的计算环境。
那么,操作系统到底是什么?它是如何工作的?又有哪些重要的功能和特点呢?让我们一起来揭开操作系统的神秘面纱。
首先,我们来谈谈操作系统的定义。
简单来说,操作系统是管理计算机硬件与软件资源的程序,同时也是计算机系统的内核与基石。
它负责控制和管理计算机的硬件设备,如处理器、内存、硬盘、输入输出设备等,同时为应用程序提供一个稳定、安全、高效的运行环境。
操作系统的主要功能可以概括为以下几个方面:进程管理是操作系统的核心功能之一。
在计算机中,多个程序可以同时运行,而操作系统需要合理地分配处理器资源,让每个程序都能得到适当的执行时间。
它通过进程调度算法,决定哪个进程先执行,哪个进程后执行,以及如何在多个进程之间切换,以确保系统的高效运行。
内存管理也至关重要。
计算机的内存是有限的,而操作系统需要合理地分配和管理内存空间,确保每个程序都能得到所需的内存,并且避免内存泄漏和内存冲突等问题。
它采用了虚拟内存技术,让程序看起来拥有比实际物理内存更大的内存空间。
文件管理是操作系统的另一个重要功能。
它负责管理计算机中的文件和目录,包括文件的创建、删除、读取、写入、存储等操作。
通过文件系统,我们可以方便地组织和管理数据,并且可以对文件进行权限设置,保护数据的安全性。
设备管理则负责管理计算机的各种输入输出设备,如键盘、鼠标、显示器、打印机等。
操作系统需要为设备驱动程序提供接口,使得设备能够正常工作,并且能够处理设备的中断和错误情况。
除了以上这些功能,操作系统还提供了用户接口,让用户能够方便地与计算机进行交互。
比如,图形用户界面(GUI)让我们可以通过点击图标和菜单来操作计算机,而命令行界面则适合那些熟悉计算机命令的用户。
接下来,让我们了解一下操作系统的分类。
Chapter 1: Introduction1.2Chapter 1: IntroductionWhat Operating Systems Do Computer-System Organization Computer-System Architecture Operating-System Structure Operating-System Operations Process Management Memory Management Storage Management Protection and Security Computing Environments1.3ObjectivesTo provide a grand tour of the major operating systemscomponentsTo provide coverage of basic computer system organization1.4What is an Operating System?A program that acts as an intermediary between a user of acomputer and the computer hardware. Operating system goals:zExecute user programs and make solving user problems easier.zMake the computer system convenient to use.Use the computer hardware in an efficient manner.1.5Operating Systems Driven FactorsMuch of operating system history driven by relative cost factors ofhardware and people. Hardware started out fantastically expensive relative to people and the relative cost has been decreasing ever since. Relative costs drive the goals of the operating system.z In the beginning: Expensive Hardware, Cheap People Goal: maximize hardware utilization.zNow: Cheap Hardware, Expensive People Goal: make it easy for people to use computer.1.6Early Days of Computer UseComputers were huge machines that are expensive to buy, run andmaintain.Computers were used in single user, interactive mode.Programmers interact with the machine at a very low level -flickconsole switches, dump cards into card reader, etc. The interface is basically the raw hardware.1.7A Problem in Early Days of Computer UseProblem: Code to manipulate external I/O devices is very complex,and is a major source of programming difficulty.Solution: Build a subroutine library (device drivers) to manage theinteraction with the I/O devices. The library is loaded into the top of memory and stays there. This is the first example of something that would grow into an operating system.1.81st Problem when Computers are ExpensiveProblem: computer idles while programmer sets things up. Poorutilization of huge investment.Solution 1: Hire a specialized person to do setup. Faster thanprogrammer, but still a lot slower than the machine.Solution 2: Build a batch monitor. Store jobs on a disk (spooling),have computer read them in one at a time and execute them. Big change in computer usage: debugging now done offline from print outs and memory dumps.1.92nd Problem when Computers are ExpensiveProblem: At any given time, job is actively using either the CPU oran I/O device, and the rest of the machine is idle and therefore unutilized.Solution: Allow the job to overlap computation and I/O. Bufferingand interrupt handling added to subroutine library.1.103rd Problem when Computers are ExpensiveProblem: one job can't keep both CPU and I/O devices busy. (Havecompute-bound jobs that tend to use only the CPU and I/O-bound jobs that tend to use only the I/O devices.) Get poor utilization either of CPU or I/O devices.Solution: multiprogramming -several jobs share system.Dynamically switch from one job to another when the running job does I/O. Big issue: protection. Don't want one job to affect the results of another. Memory protection and relocation added tohardware, OS must manage new hardware functionality. OS starts to become a significant software system. OS also starts to take up significant resources on its own.1.111st Problem When Computers Became Cheaper, People Costs Become SignificantProblem: It becomes important to make computers easier touse and to improve the productivity of the people. One big productivity sink: having to wait for batch output . So, it is important to run interactively. But computers are still so expensive that you can't buy one for every person.Solution: interactive timesharing.1.122nd Problem When Computers Became Cheaper, People Costs Become SignificantProblem: Old batch schedulers were designed to run a job for aslong as it was utilizing the CPU effectively (in practice, until it tried to do some I/O). But now, people need reasonable response time from the computer.Solution: Preemptive scheduling.1.133rd Problem When Computers Became Cheaper, People Costs Become SignificantProblem: People need to have their data and programs aroundwhile they use the computer.Solution: Add file systems for quick access to data. Computerbecomes a repository for data, and people don't have to use card decks or tapes to store their data.1.144th Problem When Computers Became Cheaper, People Costs Become SignificantProblem: The boss logs in and gets terrible response time becausethe machine is overloaded.Solution: Prioritized scheduling. The boss gets more of themachine than the peons.1.15Hardware Becomes Cheaper and Users moreSophisticated.People need to share data and information with otherpeople.zComputers become more information transfer,manipulation and storage devices rather than machines that perform arithmetic operations.zNetworking becomes very important, and as sharing becomes an important part of the experience so does security.z Operating systems become more sophisticated.1.16Computer System StructureComputer system can be divided into four componentszHardware –provides basic computing resourcesCPU, memory, I/O deviceszOperating systemControls and coordinates use of hardware among variousapplications and userszApplication programs –define the ways in which the system resources are used to solve the computing problems of the usersWord processors, compilers, web browsers, databasesystems, video gameszUsersPeople, machines, other computers1.17Four Components of a Computer System1.18Operating System DefinitionOS is a resource allocatorz Manages all resourceszDecides between conflicting requests for efficient and fair resource useOS is a control programzControls execution of programs to prevent errors and improper use of the computer1.19Operating System Definition (Cont.)No universally accepted definition“Everything a vendor ships when you order an operating system”is good approximationzBut varies wildly“The one program running at all times on the computer”is thekernel. Everything else is either a system program (ships with the operating system) or an application program1.20Computer Startupbootstrap program is loaded at power-up or rebootzTypically stored in ROM or EPROM, generally known as firmwarez Initializates all aspects of systemzLoads operating system kernel and starts execution1.21Computer System OrganizationComputer-system operationzOne or more CPUs, device controllers connect through common bus providing access to shared memory zConcurrent execution of CPUs and devices competing for memory cycles1.22Common Functions of InterruptsInterrupt transfers control to the interrupt service routine generally,through the interrupt vector , which contains the addresses of all the service routines.Interrupt architecture must save the address of the interruptedinstruction.Incoming interrupts are disabled while another interrupt is beingprocessed to prevent a lost interrupt .A trap is a software-generated interrupt caused either by an erroror a user request.An operating system is interrupt driven.1.23Interrupt HandlingThe operating system preserves the state of the CPU by storingregisters and the program counter.Determines which type of interrupt has occurred:z pollingzvectored interrupt systemSeparate segments of code determine what action should be takenfor each type of interruptOn completion,the cpu resumes the interrupted computation.1.24Interrupt Timeline1.25I/O StructureAfter I/O starts, control returns to user program only upon I/Ocompletion.z Wait instruction idles the CPU until the next interrupt z Wait loop.zAt most one I/O request is outstanding at a time, no simultaneous I/O processing.After I/O starts, control returns to user program without waitingfor I/O completion.z System call –request to the operating system to allow user to wait for I/O completion.z Device-status table contains entry for each I/O device indicating its type, address, and state.zOperating system indexes into I/O device table to determine device status and to modify table entry to include interrupt.1.26Two I/O Methods Synchronous Asynchronous1.27Device -Status Table1.28Direct Memory Access StructureUsed for high-speed I/O devices able to transmit information atclose to memory speeds.Device controller transfers blocks of data from buffer storagedirectly to main memory without CPU intervention.Only one interrupt is generated per block, rather than the oneinterrupt per byte.1.29Storage StructureMain memory –only large storage media that the CPU can accessdirectly.Secondary storage –extension of main memory that provides largenonvolatile storage capacity.Magnetic disks –rigid metal or glass platters covered withmagnetic recording materialzDisk surface is logically divided into tracks , which are subdivided into sectors .1.30Storage HierarchyStorage systems organized in hierarchy.z Speed z Cost zVolatility1.31Storage -Device Hierarchy1.32Performance of Various Levels of Storage1.33CachingCaching –copying information into faster storage system; mainmemory can be viewed as a last cache for secondary storage. Information in use copied from slower to faster storage temporarily Faster storage (cache) checked first to determine if information istherez If it is, information used directly from the cache (fast)zIf not, data copied to cache and used there Cache smaller than storage being cachedz Cache management important design problem zCache size and replacement policy1.34Migration of Integer A from Disk to RegisterMultitasking environments must be careful to use most recentvalue , no matter where it is stored in the storage hierarchyMultiprocessor environment must provide cache coherency inhardware such that all CPUs have the most recent value in their cacheDistributed environment situation even more complexzSeveral copies of a datum can exist1.35Operating System StructureMultiprogramming needed for efficiencyz Single user cannot keep CPU and I/O devices busy at all timesz Multiprogramming organizes jobs (code and data) so CPU always has one to executez A subset of total jobs in system is kept in memoryz One job selected and run via job schedulingzWhen it has to wait (for I/O for example), OS switches to another jobTimesharing (multitasking)is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computingz Response time should be < 1 secondz Each user has at least one program executing in memory >process z If several jobs ready to run at the same time >CPU schedulingz If processes don’t fit in memory, swapping moves them in and out to runzVirtual memory allows execution of processes not completely in memory1.36Memory Layout for Multiprogrammed System1.37Operating -System OperationsInterrupt driven by hardwareSoftware error or request creates exception or trapzDivision by zero, request for operating system serviceOther process problems include infinite loop, processes modifyingeach other or the operating systemDual-mode operation allows OS to protect itself and other systemcomponentsz User mode and kernel mode zMode bit provided by hardwareProvides ability to distinguish when system is running usercode or kernel codeSome instructions designated as privileged , onlyexecutable in kernel modeSystem call changes mode to kernel, return from call resetsit to user1.38Transition from User to Kernel ModeTimer to prevent infinite loop / process hogging resourcesz Set interrupt after specific period z Operating system decrements counter z When counter zero generate an interruptzSet up before scheduling process to regain control or terminate program that exceeds allotted time1.39Process ManagementA process is a program in execution. It is a unit of work within the system. Program is a passive entity , process is an active entity .Process needs resources to accomplish its taskz CPU, memory, I/O, files z Initialization dataProcess termination requires reclaim of any reusable resourcesSingle-threaded process has one program counter specifying location of next instruction to executezProcess executes instructions sequentially, one at a time, until completionMulti-threaded process has one program counter per threadTypically system has many processes, some user, some operating system running concurrently on one or more CPUszConcurrency by multiplexing the CPUs among the processes / threads1.40Process Management ActivitiesThe operating system is responsible for the following activities inconnection with process management: Creating and deleting both user and system processes Suspending and resuming processesProviding mechanisms for process synchronization Providing mechanisms for process communication Providing mechanisms for deadlock handling1.41Memory ManagementAll data in memory before and after processing All instructions in memory in order to execute Memory management activitieszKeeping track of which parts of memory are currently being used and by whomzDeciding which processes (or parts thereof) and data to move into and out of memoryz Allocating and deallocating memory space as needed1.42Storage ManagementOS provides uniform, logical view of information storagez Abstracts physical properties to logical storage unit -file zEach medium is controlled by device (i.e., disk drive, tape drive)Varying properties include access speed, capacity, data-transfer rate, access method (sequential or random)File-System managementz Files usually organized into directoriesz Access control on most systems to determine who can access whatzOS activities includeCreating and deleting files and directories Primitives to manipulate files and dirs Mapping files onto secondary storageBackup files onto stable (non-volatile) storage media1.43Mass -Storage ManagementUsually disks used to store data that does not fit in main memory or data that must be kept for a “long”period of time. Proper management is of central importanceEntire speed of computer operation hinges on disk subsystem and its algorithmsOS activitiesz Free-space management z Storage allocation zDisk schedulingSome storage need not be fastz Tertiary storage includes optical storage, magnetic tape z Still must be managedzVaries between WORM (write-once, read-many-times) and RW (read-write)1.44I/O SubsystemOne purpose of OS is to hide peculiarities of hardware devicesfrom the userI/O subsystem responsible forzMemory management of I/O including buffering (storing data temporarily while it is being transferred), caching (storing parts of data in faster storage for performance), spooling (the overlapping of output of one job with input of other jobs)z General device-driver interface zDrivers for specific hardware devices1.45Protection and SecurityProtection –any mechanism for controlling access of processes orusers to resources defined by the OSSecurity –defense of the system against internal and externalattackszHuge range, including denial-of-service, worms, virusesSystems generally first distinguish among users, to determine whocan do whatz User identities (user IDs , security IDs) include name and associated number, one per userz User ID then associated with all files, processes of that user to determine access controlzGroup identifier (g roup ID ) allows set of users to be defined and controls managed, then also associated with each process, filezPrivilege escalation allows user to change to effective ID with more rights1.46Computing EnvironmentsTraditional computerzOffice environmentPCs connected to a network, terminals attached tomainframe or minicomputers providing batch and timesharingNow portals allowing networked and remote systemsaccess to same resourceszHome networksUsed to be single system, then modems Now firewalled, networked1.47Computing Environments (Cont.)Client-Server Computingz Dumb terminals supplanted by smart PCszMany systems now servers , responding to requests generated by clientsCompute-server provides an interface to client to request services (i.e. database)File-server provides interface for clients to store and retrieve files1.48Peer -to -Peer ComputingAnother model of distributed system P2P does not distinguish clients and serversz Instead all nodes are considered peers z May each act as client, server or both zNode must join P2P networkRegisters its service with central lookup service on network,orBroadcast request for service and respond to requests forservice via discovery protocol zExamples include Napster and Gnutella1.49Web -Based ComputingWeb has become ubiquitous PCs most prevalent devicesMore devices becoming networked to allow web access New category of devices to manage web traffic among similarservers: load balancersUse of operating systems like Windows 95, client-side, haveevolved into Linux and Windows XP, which can be clients and servers1.50Chapter 1: IntroductionWhat Operating Systems Do Computer-System Organization Computer-System Architecture Operating-System Structure Operating-System Operations Process Management Memory Management Storage Management Protection and Security Computing EnvironmentsEnd of Chapter 1。