1.2 operating system definition and role

  Here we introduce the definition and role of the operating system. So what operating system? How to understand its role? What operating system is it? 
  The operating system is a software system in a computer system, the system software it is a combination of some of the children's program modules, program modules work together, cooperate with each other to perform the following functions:
  (1) First, they can be effective to minimize, various hardware and software resources and rational way to organize the management computer;
  (2) In order to support the implementation of the program, the operating system for computer rational organization of work processes, the execution of the control program and during program execution provide a variety of services to the program; 
  (3) Third, the operating system must use a variety of ways that a user can very flexible, easy to use a computer, using a variety of techniques of the entire computer system can run efficiently.
  This is a definition of the operating system. Then the operating system to complete a variety of functions, our interpretation of what children in the definition of some of the key words:
  (1) The first word is valid. Then the operating system has managed a variety of resources, then these resources like CPU, CPU always hope that we are not free to take advantage of CPU, there are a lot of programs in the CPU to run on, then there is memory, disk, we hope that these memory, disk it should be able to take advantage of these spaces can be well managed. For example, a variety of devices, we hope that these devices can be sufficiently busy. All in all, we hope to be able to improve the utilization of various resources of the operating system, the operating system in order to improve the overall efficiency of the entire computer system.
  (2) The second key word is reasonable. Due to the management of resources, so it will have a variety of tactics. This strategy then manage these resources is not fair, is it reasonable? So if unfair, unreasonable, will be what kind of problems it? We do have to solve this problem. 
  (3) the third key is easy to use. We want to deal with the operating system, usually want to use the operating system very easily provide us with a variety of interfaces. Two typical interfaces are: a user interface, which is the command line, the user and the operating system to deal with; there it is a programming interface, which is developed by software programmers, dealing with operating system software. So these two interfaces are hoping to easy to use, easy to learn.
  What is the role of the operating system? We conclude that the role of a typical three operating systems:
  (1) The first role of the operating system resource managers. Operating system resource managers from what point of view it? From the bottom up, i.e. from the point of view of the inside of the operating system is an operating system resource manager. What is the operating system resources of the tube it? This is the familiar hardware and software resources: the CPU, memory, a variety of devices, including our talking I / O devices, printers, scanners ah ah, disks, clock, as well as network cards, and so on. So there are a lot of software resources, for example, there are a lot of files on the disk, there are a lot of management information is managed by the operating system. So the operating system resource managers. From such a perspective, we look at how to manage a wide variety of resources: the operating system to manage resources, first of all need to keep track of every usage of resources, then this is the data structure, a software data structure , algorithms for these components, the data structure is used to record usage of resources. Then a data structure in which information is recorded it? We can record what resources are free, what resources have been allocated out, who is assigned to be used, and for how long, and so allow the use of such information. Once you have the data structure, we also need algorithm, that is, the operating system to determine resource allocation policy: the operating system to determine the resources allocated to a process by which, to use it how long to use it much, this is the so-called resource allocation policy. Then the resource allocation policies usually do a few typical: a static allocation strategy. The so-called static allocation strategy that the program put before the execution of various resources it needs to get the hand, then the program in the implementation process eliminates the need for new resources, and you can perform has been completed. Of course, here there is a problem with this first resource in the implementation process sometimes when resources do not need it, this resource is wasted. Because it took the resources, other processes can not be used. Therefore, the static allocation strategy will lead to a waste of resources of the whole, therefore, many of the operating system, or the vast majority of operating systems uses a dynamic allocation strategy. So a dynamic allocation strategy that is in the process of execution of the process, and when resources are needed, apply when. Then the operating system will be based on the current system resource usage, which is just said data structure to determine whether the resources allocated to it. Then such advantage is that resource utilization has been fully improved. We give a typical example: for example, we are a paged memory management system, so that the memory had, we put the memory, the physical memory is divided into a lot of physical pages, we can use a very simple data structure bit map , bitmap or bitmaps to record usage of the physical memory, the physical memory corresponding to one page. If this page is free, then we head counts as 0 here, if this one is divided out, then we denoted 1. Then our allocation algorithm is actually up on the implementation of this data structure. Then the following is necessary to implement distribution and recovery of resources, the process is actually allocated in accordance with the policy, in accordance with this resource allocation strategy selected just developed this process to allocate resources to give, and then to decide how much allocated to it, then go modify the data structure. For example, just now, so if we put a memory allocated to a process, then the bit map would put the original 0 and 1 into the recovery, when a process used up resources, then they would recover the system to it recovered. Then the recovery time for it, but also to modify the data structure, for example, put the original 1 into 0 and recycling of this process is to implement resource allocation. In addition, the operating system also uses a variety of techniques to improve the utilization of resources, when there are multiple processes have to use resources to it, but also to protect the resource, then use the resources of a process course not in addition to the interference of a process, if there are multiple processes in a single system under the application of the resources are there, it had a conflict situation, it is necessary to coordinate the operating system. This is an operating system how to manage a resource of a general process, then we are in fact all future resources in line with this general process, of course, there are some special problems to be solved. From the perspective of resource management, so we look, summed up the five basic functions of the operating system:
    <1> process / thread management, sometimes also referred to as CPU management, because they are in the process and thread performs the process herein comprises the state of the thread design, the CPU controls the operation of the synchronization mutex, the through channel there scheduling;
    <2> the storage management is done distribution and recovery storage space, to complete the conversion, memory protection, expansion memory address;
    <3> File Manager, then of course, include the file directory management, access control management of a variety of operations, disk space management file, the file itself;
    <4> Device Management do, mainly in the dispensing device driver, device, recovery process; there are various techniques in order to improve a wide variety of resource utilization equipment it uses, for example, buffering technique and the like;
    <5> 那么一个操作系统在使用过程中,必然提供 给用户非常方便使用的接口,因此呢,作为操作系统呢我们要讨论 接口的,典型的接口,系统 命令,还有编程接口。
  (2)操作系统的第二个作用呢,是向用户提供各种服务。 那么这些服务呢是方便用户使用的,那么我们可以说 操作系统是各种系统服务的一个提供者 那么这个系统服务呢,如果操作系统 提供功能更强大,更容易使用的这样的一系列的命令或系统调用, 我们就认为这个操作系统提供了更好的服务。 那有哪些典型的服务呢?我们来看一下,典型的像进程的创建呀、 执行啊、文件和目录的各种操作呀、各种 I/O 设备的使用啊,还有提供各种各样的统计信息。这里简单地举了几个例子,大家有那么一个感性认识。
  (3)操作系统的第三个作用呢,是对机器硬件的一个扩展。 具有一个扩展能力。 我们来看一个示意。 那么我们在这里头我们知道操作系统 实际上是硬件基础上的第一层软件,那么操作系统完成各种各样的功能。 在操作系统之上是应用程序在执行, 操作系统为应用程序的执行提供了,像我们说的各种各样的接口,用户的接口和编程的接口。 那么这些就组成了一个虚拟机器界面。 操作系统之下呢,是硬件,也就是操作系统屏蔽了一些硬件的细节, 用户程序不需要直接和硬件打交道, 通常它都是通过操作系统来控制这些硬件的 执行,那么这是我们说操作系统是硬件基础上的第一层软件。 那么为什么要把,用操作系统把硬件屏蔽呢?那我们来看一下与硬件相关的一些工作 是非常复杂和繁琐的。 我们有两个操作, 我们现在介绍两个操作,那么想问一下,这两个操作当中的哪一个操作 你觉得简单,你觉得很方便。 第一个操作呢是说 从一个文件当中读一个数据块; 第二个操作呢是说你要移动磁头,要等待这个磁头放下。 那么我们对程序员来讲,第一个操作显然要比第二个操作更简单,更方便使用。 那我们来看看如果你要考虑第二个操作,你要实现第二个操作, 那你要考虑哪些问题,是不是很复杂,是不是很琐碎?我们举一个非常 简单的例子,软盘I/O操作:虽然软盘呢我们现在都很难见到了, 但是因为软盘和硬盘很相似,但是它又非常简单,所以我们就举 它作为例子。 那么硬盘比它要复杂得多,所以我们更多的问题需要去解决。有这么一个非常简单的软盘控制器, 那么这个软盘控制器呢可以执行16条命令。这 16条命令呢实际上的长度是不一样的,是从 1到9个字节的,长度不等。而这些命令包括了什么呢?我们简单来看一下,比如说读写数据, 然后移动磁头臂,格式化磁道, 还有些初始化呀,检测软盘的状态呀,复位呀等等等等。 那么这些呢都是非常细节的一些命令,我们很难记住。那么这些命令呢要把它写入到 设备的控制寄存器里头去来控制这个设备的执行,我们以这个 read命令为例,read命令呢,需要13 个参数,那我们还要记住13个参数,每个参数呢,像read命令的 13个参数呢包括了你要读取的磁盘地址,磁盘的扇区数,磁道的扇区数,还有很多跟 物理介质相关的一些物理特性,软盘的一些物理特性,你都要了解。 因此对于程序员来讲就很不容易来知道每一个细节, 另外呢,这个软盘工作的是不是正常,是不是完成了你的这种控制要求? 因此这个软盘的这个控制芯片呢还会返回给23 个状态或者出错信息,这些信息呢又记录在了7 个字节的地方,7 个字节的设备状态寄存器里头。 那么还要了解这23个不同的状态,什么样的情况,发生了什么事情。 除此之外,还有一个很特殊的, 就是程序员还要保持步进电机的一个开关状态,那么我们知道软盘不能总是在 启动的状态,那么时间久了,软盘就会损坏。因此呢,如果长时间不用,它就会停止, 但是一旦要用,读数据了,要写数据了,要启动这个软盘, 让它旋转到一定的转速那才能去读。因此呢,程序员要注意这样一些步进开关的这种 步进电机一个开关的一些状态,还要考虑这些细节。 从以上介绍其实我们已经看出来了,说如果让我们来编程的时候,考虑这么琐碎、 复杂的事情,那么程序员呢会非常非常头疼。所以我们说与硬件相关的这些工作特别地琐碎, 特别地繁杂,而且不同的硬件呢这些还不一样。 如果我们换了一个驱动器,那么这个命令就可能是另外的样子,每条命令就不一样,参数也是不一样的。 因此,操作系统就做了这样一个事情:操作系统就是在硬件之上, 在应用程序与硬件之间,建立了这么一个等价的一个扩展机器—— 虚拟机,那么通过对硬件的抽象。 那么提高了整个系统的可移植性。 那么对于程序员来讲呢,他去对底层硬件编程 更麻烦,而提供了这样一个操作系统这一层之后,那么 程序员比对这个编程就会比底层硬件的这种更容易。 操作系统起的作用,就是 把这些比较琐碎、复杂的一些硬件屏蔽在它之下, 然后向用户提供了一个非常良好的,非常优雅的、清晰的、 一致的这样一个接口,那么供用户去使用,那么我们说操作系统是对硬件机器的一个扩展 为用户程序提供了一个虚拟机器。
  那么我们最后再 考虑这个操作系统的三个作用,再强调一下:
  (1)第一个作用,就是有效地管理计算机系统的各种资源;
   (2)第二个作用,就是通过接口,命令接口和编程接口,为用户提供各种各样的服务功能;
  (3)第三个作用,就是屏蔽硬件细节,为用户提供一个扩展的虚拟机器。
 
Reference:北京大学陈向群老师操作系统原理课程
Notice:如有侵权,请告知我,我会删除,谢谢!

Guess you like

Origin www.cnblogs.com/morwing/p/11355990.html