Chapter 1Introduction

上传人:枫** 文档编号:576975324 上传时间:2024-08-20 格式:PPT 页数:92 大小:5.85MB
返回 下载 相关 举报
Chapter 1Introduction_第1页
第1页 / 共92页
Chapter 1Introduction_第2页
第2页 / 共92页
Chapter 1Introduction_第3页
第3页 / 共92页
Chapter 1Introduction_第4页
第4页 / 共92页
Chapter 1Introduction_第5页
第5页 / 共92页
点击查看更多>>
资源描述

《Chapter 1Introduction》由会员分享,可在线阅读,更多相关《Chapter 1Introduction(92页珍藏版)》请在金锄头文库上搜索。

1、Principles of Operating SystemChapter 1IntroductionContents1.1 What is an operating system (OS)?1.2 History of OS1.3 The OS zoo1.4 OS concept1.5 The functions of OS1.6 System calls1.7 OS structure2Operating system (OS)vThe job of OS:To provide user programs with a better, simpler, cleaner, model of

2、the computerTo handle managing all the resources (one or more processors, some main memory, disks, printers, a keyboard, a mouse, a display, network interfaces, and various other input/output devices.)3vTwo modes of operation (运行模式运行模式) of computers:Kernel mode(内核态,也称管态、核心态内核态,也称管态、核心态)User mode(用户态

3、用户态)vThe OS runs in kernel mode, it can access to all the hardware and can execute any instruction the machine is capable of executing.vThe rest of the software runs in user mode, in which only a subset of the machine instructions is available.4Where the OS fits in51.1 What is an OS1.1.1 The OS as a

4、n extended machine Top-down view1.1.2 The OS as a resource manager Bottom-up view61.1.1 The OS as an extended machinevThe OS provides abstractions (抽象抽象) to application programs.vGood abstractions turn a nearly impossible task into two manageable ones.The first one: define and implement the abstract

5、ionsThe second one: use these abstractions to solve the problem at hand7vOne of the major tasks of the OS is to hide the hardware and present programs (and their programmers) with nice, clean, elegant, consistent, abstractions to work with instead.8OS turns ugly hardware into beautiful abstractions

6、91.1.2 The OS as a resource managervFrom this view, OS is designed to manage all the pieces of a complex system.vThe job of OS is to provide for an orderly and controlled allocation of the processors, memories, and I/O devices among the various programs.10vResource management includes multiplexing r

7、esources in two different ways:time multiplexing(时分复用)(时分复用)For example: CPU, printerspace multiplexing(空分复用)(空分复用) For example: main memory, disk11操作系统(操作系统(OS)的定义)的定义资源管理的观点资源管理的观点资源管理的观点资源管理的观点操作系统是控制和管理计算机软、硬件资源,操作系统是控制和管理计算机软、硬件资源,合理地组织计算机的工作流程,以及方便用户合理地组织计算机的工作流程,以及方便用户使用的程序集合使用的程序集合。本质本质1 12

8、23 3用户的观点用户的观点用户的观点用户的观点操作系统是配置在计算机硬件上的第一层软件,操作系统是配置在计算机硬件上的第一层软件,是对硬件系统的第一次扩充。是对硬件系统的第一次扩充。121.2 History of OSSince operating systems have closely tied to the architecture of the computers on which they run, we will look at successive generations of computers to see what their operating systems wer

9、e like. 131.2.1 The first generation: vacuum tubesIn this generation, all programming was done in absolute machine language, or even worse yet, by wiring up electrical circuits by connecting thousands of cables to plugboards(插件板插件板) to control the machines basic functions.Programming languages were

10、unknown, operating systems were unheard of. 141.2.2 The second generation: Transistors(晶体管晶体管) and Batch systemsvMainframe (大型机大型机)vTo run a job, a programmer would first write the program on paper (in FORTRAN or assembler), then punch it on cards(穿孔成卡片穿孔成卡片), then bring the card deck down to the in

11、put room and hand it to the operators and wait until the output was ready.vGiven the high cost of the equipment, people quickly looked for ways to reduce the wasted time. The solution generally adopted was the batch system (批处理系统批处理系统).15An early batch systemAfter each job finished, the operating sy

12、stem automatically read the next job from the tape and began running it.16The structure of a typical input jobTypical operating systems were FMS (FORTRAN Monitor System) and IBMSYS (IBMs OS for the 7094).171.2.3 The third generation: ICs and multiprogrammingvICs: Integrated circuits, 集成电路集成电路vBy the

13、 early 1960s, most computer manufacturers had two distinct, incompatible product lines.(1) word-oriented, large-scale scientific computers, e.g. 7094(2) character-oriented, commercial computers, e.g. 1401vDeveloping and maintaining two completely different product lines was an expensive proposition

14、for the manufacturers.18vSolution: IBM System/360The 360 was a series of software-compatible machines ranging from 1401-sized to much more powerful than the 7094. Since all the machines had the same architecture(体系结构体系结构) and instruction set(指指令集令集), programs written for one machine could run on all

15、 the others, at least in theory.The operating system: OS/360vThe idea of a family of compatible computers(兼容机兼容机) was soon adopted by all the other major manufactures.19Some key techniquesvMultiprogramming: 多道程序设计多道程序设计vSPOOLing: Simultaneous Peripheral Operation On Line, 同时的外部设备联机同时的外部设备联机操作操作20Mul

16、tiprogrammingPartition memory into several pieces, with a different job in each partitions. While one job was waiting for I/O to complete, another job could be using the CPU.21(a) 单道程序的运行情况单道程序的运行情况(b) 多道程序的运行情况多道程序的运行情况22SPOOLingthe ability to read jobs from cards onto the disk as soon as they were

17、 brought to the computer room. Whenever a running job finished, the OS could load a new job from the disk into the now-empty partition and run it.With spooling, the 1401 were no longer needed.23Timesharing system(分时系统分时系统)v由于批处理系统对用户的响应时间长,因此用户由于批处理系统对用户的响应时间长,因此用户对响应时间的要求导致了对响应时间的要求导致了分时系统分时系统的出现的出

18、现vTimesharing system is a variant of multiprogramming, in which each user has an online terminal.vThe first general-purpose timesharing system: CTSS (Compatible Time Sharing System), developed by MIT24Timesharing system主机主机终终端端分时系统分时系统:在一台主机上连接:在一台主机上连接了多个带有显示器和键盘的终了多个带有显示器和键盘的终端,同时允许多个用户通过自端,同时允许多个

19、用户通过自己的终端,以交互方式使用计己的终端,以交互方式使用计算机,共享主机中的资源。算机,共享主机中的资源。25Timesharing systemvMULTICS-The designer of this system envisioned one huge machine providing computing power for everyone in the Boston area.vMULTICS introduced many seminal(有重大影有重大影响的响的) ideas into the computer literature(文献文献).26MULTICS 庞大的分

20、时系统庞大的分时系统v1965年在年在ARPA的支持下,的支持下,MIT、贝尔实验室和通贝尔实验室和通用电气公司决定开发一种用电气公司决定开发一种“公用计算服务系统公用计算服务系统”, 希望能够同时支持整个波士顿所有的分时用户。希望能够同时支持整个波士顿所有的分时用户。该系统称作该系统称作MULTICS (MULTiplexed Information and Computing Service )vMULTICS的设计目标是:的设计目标是:便利的远程终端使用,大量终端通过电话线接入计算机便利的远程终端使用,大量终端通过电话线接入计算机主机主机高可靠的大型文件系统;大容量的用户信息共享;存储高

21、可靠的大型文件系统;大容量的用户信息共享;存储和构造层次化信息结构的能力和构造层次化信息结构的能力27MULTICSvMULTICS的研制难度超出了所有人的预料,的研制难度超出了所有人的预料,1969年年4月贝尔实验室退出,通用电气公司也退出了,月贝尔实验室退出,通用电气公司也退出了,但最终,经过多年的努力,但最终,经过多年的努力,MULTICS成功地应用成功地应用v运行运行MULTICS的计算机系统在九十年代陆续被关的计算机系统在九十年代陆续被关闭闭vDespite its lack of commercial success, MULTICS had a huge influence on

22、 subsequent OSs.vMULTICS引入了许多现代操作系统领域概念的雏引入了许多现代操作系统领域概念的雏形,对随后操作系统特别是形,对随后操作系统特别是UNIX的成功有着巨大的成功有着巨大的影响的影响 28小型计算机,电子游戏和小型计算机,电子游戏和UNIX的成功的成功v1969年,在贝尔退出年,在贝尔退出MULTICS研制项目后,研制项目后,Ken Thompson和和Dennis M. Ritchie 想申请经费买计想申请经费买计算机从事操作系统研究,但多次申请得不到批准算机从事操作系统研究,但多次申请得不到批准v因此他们在一台无人用的因此他们在一台无人用的PDP-7上,重新摆

23、弄原上,重新摆弄原先在先在MULTICS项目上设计的项目上设计的“空间旅行空间旅行”游戏游戏v为了使游戏能够在为了使游戏能够在PDP-7上顺利运行,他们陆续上顺利运行,他们陆续开发了浮点运算软件包、显示驱动软件,设计了开发了浮点运算软件包、显示驱动软件,设计了文件系统、实用程序文件系统、实用程序、shell 和汇编程序和汇编程序v到了到了1970年,在一切完成后,给新系统起了个同年,在一切完成后,给新系统起了个同MULTICS发音相近的名字发音相近的名字UNIX,随后,随后,UNIX用用C语言全部重写,自此语言全部重写,自此,UNIX诞生了诞生了29UNIXvTwo major version

24、s of UNIX:System V: from AT&TBSD: from the University of California at Berkeley30MINIX, LinuxvMINIX: a small clone of UNIX, for education purposesvLinux: written by a Finnish student, Linus Torvalds 311.2.4 The fourth generation: Personal ComputersLSI (Large Sacle Integration, 大规模集成电路大规模集成电路)vCP/MvM

25、S-DOSvMacintoshvWindowsvUNIX321.3 The OS zoo1.3.1 mainframe OS1.3.2 Server OS1.3.3 Multiprocessor OS1.3.4 Personal Computer OS1.3.5 Handheld Computer OS1.3.6 Embedded OS1.3.7 Real-time OS331.3.1 mainframe OSvThe OS for mainframes are heavily oriented toward processing many jobs at once, most of whic

26、h need prodigious (巨大的巨大的) amounts of I/O.vThey typically offer three kinds of services: Batchtransaction processing(事务处理事务处理)timesharing341.3.2 Server OSvServer OS run on servers, which are either very large PC, workstations, or even mainframes. vThey serve multiple users at once over a network and

27、 allow the users to share hardware and software resources.vTypical server OS: Solaris, FreeBSD, Linux, Windows Server 200x351.3.3 Multiprocessor OSvAn increasingly common way to get major-league computing power is to connect multiple CPUs into a single system.vDepending on precisely how they are con

28、nected and what is shared, these systems are called: Parallel computers, multicomputers, multiprocessors. 361.3.4 Personal Computer OSvLinuxvFreeBSDvWindowsvMacintosh371.3.5 Handheld Computer OSvA handheld computer or PDA is a small computer that fits in a shirt pocket and performs a small number of

29、 functions, such as an electronic address book and memo pad.vTwo of the most popular OS for handhelds are Symbian OS and Palm OS.381.3.6 Embedded OSvEmbedded(嵌入式嵌入式) system run on the computers that control devices that are not generally thought of as computers and which do not accept user-installed

30、 software.vTypical examples: microwave ovens(微微波炉波炉), TV sets, cars, DVD recorders, cell phones, MP3 players 391.3.7 Real-time OSvReal-time(实时实时) OS are characterized by having time as a key parameter.vHard real-time system: the action absolutely must occur at a certain moment (or within a certain r

31、ange)vSoftware real-time system: in this system, missing an occasional deadline, while not desirable, is acceptable and does not cause any permanent damage.401.3.8 操作系统的三种基本类型操作系统的三种基本类型v批处理操作系统批处理操作系统单道批处理系统单道批处理系统:由于第二代计算机的速度逐:由于第二代计算机的速度逐步提高,为了进一步解决人机矛盾,在系统中步提高,为了进一步解决人机矛盾,在系统中配置了监督程序,在它的控制下实现了作业

32、的配置了监督程序,在它的控制下实现了作业的自动过渡,由此出现了作业的成批处理,即单自动过渡,由此出现了作业的成批处理,即单道批处理系统。道批处理系统。多道批处理系统多道批处理系统:为了进一步提高资源的利用:为了进一步提高资源的利用率和系统吞吐量,引入了多道程序设计技术,率和系统吞吐量,引入了多道程序设计技术,由此而形成了多道批处理系统。由此而形成了多道批处理系统。v分时操作系统分时操作系统 在一台主机上连接了多个带有显示器和键盘的终端,同时允许多个在一台主机上连接了多个带有显示器和键盘的终端,同时允许多个用户通过自己的终端,以交互方式使用计算机,共享主机中的资源。用户通过自己的终端,以交互方式

33、使用计算机,共享主机中的资源。v实时操作系统实时操作系统411.4 OS concepts1.4.1 processes1.4.2 address spaces1.4.3 Files1.4.4 Input / Output421.4.1 ProcessesA key concept in all operating systems is the process. A process is basically a program in execution.vProcess table: in many OS, all the information about each process, oth

34、er than the contents of its own address space, is stored in this table.43ProcessesvProcess tree:vInterprocess communication: Related processes that are cooperating to get some job done often need to communicate with one another and synchronize their activities. 441.4.2 Address spacesAddress spaces:

35、a list of memory locations from 0 to some maximum, which the process can read and write.In the simplest case, the maximum amount of address space a process has is less than the main memory. In this way, a process can fill up its address space and there will be enough room in main memory to hold it a

36、ll. However, in more complicated case, ?45vThe technique of Virtual memory: the OS keeps part of the address space in main memory and part on disk and shuttles pieces back and forth between them as need.461.4.3 FilesvDirectoryvRoot directoryvWorking directoryvAbsolute path names: consists of the lis

37、t of directories that must be traversed from the root directory to get to the file, with slashes(斜杠斜杠, /) separating the components.vRelative path names: not begin with a slash are looked for.47A file system48File descriptorvFile descriptor(文件描述符文件描述符): Before a file can be read or written, it must

38、be opened, at which time the permissions are checked. If the access is permitted, the system returns a small integer called a file descriptor to use in subsequent operations.49Some important concepts in UNIX vThe mounted file system50Some important concepts in UNIXvSpecial fileBlock special fileChar

39、acter special file The special files are kept in the /dev directory.vPipe(管道管道): a sort of pseudofile(伪文件,伪文件,虚文件虚文件) that can be used to connect two processes.511.4.4 Input / OutputvAll computers have physical devices for acquiring input and producing output.vEvery OS has an I/O subsystem for manag

40、ing its I/O devices.vIn chapter 5, we will have a look at I/O software.521.5 操作系统的主要功能操作系统的主要功能创创创创 意意意意存储器管理存储器管理存储器管理存储器管理制作图片制作图片制作图片制作图片处理机管理处理机管理处理机管理处理机管理制作动画制作动画制作动画制作动画设备管理设备管理设备管理设备管理制作声音制作声音制作声音制作声音文件管理文件管理文件管理文件管理编制程序编制程序编制程序编制程序用户接口用户接口用户接口用户接口内存储器内存储器内存储器内存储器中央处理器中央处理器中央处理器中央处理器显示器显示器显示

41、器显示器键盘键盘键盘键盘CD-ROMCD-ROM外存储器外存储器外存储器外存储器音响设备音响设备音响设备音响设备鼠标鼠标鼠标鼠标53u 对处理机的分配和运行实施有效对处理机的分配和运行实施有效管理。管理。u 在多道程序环境下,处理机的分配在多道程序环境下,处理机的分配和运行以进程为单位,因此对处理机和运行以进程为单位,因此对处理机的管理即的管理即对进程的管理对进程的管理。 任务任务u 进程控制进程控制u 进程同步进程同步u 进程通信进程通信u 进程调度进程调度 功能功能处理机管理处理机管理54u为多道程序的并发运行提供良好环境为多道程序的并发运行提供良好环境u便于用户使用存储器便于用户使用存储

42、器u提高存储器的利用率提高存储器的利用率u为尽量多的用户提供足够大的空间为尽量多的用户提供足够大的空间 任务任务u内存分配内存分配u内存保护内存保护u地址映射地址映射u内存扩充内存扩充 功能功能存储管理存储管理55u完成用户程序请求的完成用户程序请求的I/O操作操作u为用户程序分配为用户程序分配I/O设备设备u提高提高CPU和和I/O设备的利用率设备的利用率u改善人机界面改善人机界面 任务任务u缓冲管理缓冲管理u设备分配设备分配u设备处理(设备驱动程序)设备处理(设备驱动程序) 功能功能设备管理设备管理56u大量的信息以文件的形式放在外存,大量的信息以文件的形式放在外存, 对信息的管理也就是对

43、信息的管理也就是对文件的管理对文件的管理 任务任务u文件存储空间的管理文件存储空间的管理u目录管理目录管理u文件的读、写管理文件的读、写管理u文件的存取控制文件的存取控制 功能功能文件管理文件管理57u联机命令接口联机命令接口u脱机命令接口脱机命令接口u图形用户界面(命令接口的改版)图形用户界面(命令接口的改版) 用户接口用户接口操作系统与用户之间的接口操作系统与用户之间的接口u也称系统调用也称系统调用 程序接口程序接口581.6 System callsvWe have seen that OS has two main functions:Providing abstractions to

44、 user programsManaging the computers resourcesvThe interface between user programs and the OS is primarily about dealing with the abstractions.System calls59System callsvIn a sense, making a system call is like making a special kind of procedure call, only system calls enter the kernel and procedure

45、 calls do not.60Some of the most heavily used POSIX system calls (1)61Some of the most heavily used POSIX system calls (2)621.6.1 system calls for process managementvfork is the only way to create a new process in POSIX.vIt creates an exact duplicate of the original process, including all the file d

46、escriptors, registerseverything.vAfter the fork, the original process (the parent) and the copy (the child) go their separate ways. 63forkvThe fork call returns a value, which is zero in the child and equal to the childs process identifier or PID in the parent.vUsing the returned value, the two proc

47、esses can see which one is the parent process and which one is the child process.64forkvwaitpid: waits until the child terminates. It can wait for a specific child, or for any old child by setting the first parameter to -1.65创建进程的例子创建进程的例子例例1:66例例2# include # include # include main( ) pid_t pid; / 保

48、存子进程的保存子进程的ID号号int status; / 等待的退出状态等待的退出状态pid=fork( ); / 创建新进程创建新进程if(pid= -1) perror(“Fork failed to creat a process”);exit(1);else if (pid=0) / 子进程代码子进程代码 if(execl(“/bin/ls”, “ls”, “-l”, NULL)0) perror(“Exec failed”); exit(1); else if(pid!=wait(&status) / 父进程代码父进程代码perror(“A signal occurred befor

49、e the child exited”);exit(0);67例例2的运行结果的运行结果681.6.2 system calls for file managementvopenvreadvwritevlseek: changes the value of the current position pointer in the file, so that subsequent calls to read or write can begin anywhere in the file.vstat: keeps track of the file mode, size, time of last

50、modification, and other information. 691.6.3 system calls for directory managementvmkdir: create a new directoryvrmdir: remove an empty directoryvlink(name1, name2): create a new entry, name2, point to name1vunlink: remove a directory entryvmountvumount70examplelink(“/usr/jim/memo”, “/usr/ast/note”)

51、;711.6.4 miscellaneous system callsvchdir(“/usr/ast/test”): changes the current working directoryvchmod(“file”, 0644): change the mode of a filevkill: send signals721.6.5 The windows Win32 APIvIn windows, the library calls and the actual system calls are highly decoupled. vMicrosoft has defined a se

52、t of procedures called the Win32 API (Application Program Interface) that programmers are expected to use to get OS services.73Win32 API741.7 OS structurevMonolithic systems (单体系统单体系统)vLayered systems vMicrokernels (微内核微内核)vClient-server modelvVirtual Machines751.7.1 Monolithic systemsIn this approa

53、ch, the entire OS runs as a single program in kernel mode. The OS is written as a collection of procedures, linked together into a single large executable binary program.When this technique is used, each procedure in the system is free to call any other one, if the latter provides some useful comput

54、ation that the former needs.76A simple structuring model for a monolithic systemvThis organization suggests a basic structure for the OS:A main program that invokes the requested service procedureA set of service procedures that carry out the system callsA set of utility procedures that help the ser

55、vice procedures77A simple structuring model for a monolithic systemFigure 1-24781.7.2 layered systemvA generalization of the approach of Fig. 1-24 is to organize the OS as a hierarchy of layers, each one constructed upon the one below it. 79Example: Structure of the THE OS801.7.3 micorkernelsThe bas

56、ic idea behind the micorkernels design is to achieve high reliability by splitting the OS up into small, well-defined modules, only one of which - the micorkernel - runs in kernel mode and the rest run as relatively powerless ordinary user processes. 81micorkernelsvMicorkernels are especially common

57、 in real-time, industrial, avionics (航空航空), and military applications that are mission critical and have very high reliability requirements.82micorkernelsvAn idea somewhat related to having a minimal kernel is to put the mechanism (机制机制) for doing something in the kernel but not the policy(策略策略). 机制

58、与策略分离机制与策略分离vExample: A simple scheduling algorithm of processes is to assign a priority to every process and then have the kernel run the highest-priority process that is runnalble.The mechanism is to look for the highest-priority process and run it. The policy assigning priorities to process can b

59、e done by user-mode processes.831.7.4 Client-Server modelvA slight variation of the micorkernel idea is to distinguish two classes of processes:The servers: each of which provides some serviceThe clients: use these servicesvThe essence of this model is the presence of client processes and server pro

60、cesses.84Client-Server modelCommunication between clients and servers is often by message passing.To obtain a service, a client process constructs a message saying what it wants and sends it to the appropriate service. The service then does the work and sends back the answer. 85The client-Server mod

61、el over a networkAn obvious generalization of this idea is to have the clients and servers run on different computers, connected by a local or wide-area network.86client-Server modelSince clients communicate with servers by sending messages, the clients need not know whether the messages are handled

62、 locally on their own machines, or whether they are sent across a network to servers on a remote machine. As far as the client is concerned, the same thing happens in both cases: requests are sent and replies come back. Thus the client-server model is an abstraction that can be used for a single mac

63、hine or for a network of machines. 871.7.5 Virtual machines1. VM/370The heart of the system, known as the virtual machine monitor, runs on the bare hardware and does the multiprogramming, providing not one, but several virtual machines to the next layer up.88VM/370vBecause each virtual machine is id

64、entical to the true hardware, each one can run any OS that will run directly on the bare hardware.892. Virtual machines rediscoveredvMany companies have traditionally run their mail servers, Web servers, FTP servers, and other servers on separate computers, sometimes with different OS. They see virt

65、ualization as a way to run them all on the same machine without having a crash of one server bring down the rest.vVirtualization is also popular in the Web hosting (Web托管托管) world.90vAnother use of virtualization is for end users who want to be able to run two or more OSs at the same time, say Windows and Linux.913. Java virtual machine JVM92

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号