Operating System (2): Operating System Structure

Study hard and make progress every day

This article has been included in my Github repository DayDayUP : github.com/RobodLee/DayDayUP, welcome to Star

Operating system services and interfaces

When I discussed what an operating system is in the previous article, I gave an example. I said that the operating system is the housekeeper who helps us manage the house. Since it is a housekeeper, there must be a lot of talents, otherwise it is difficult to take on this big task. It is the housekeeper who has many talents that can better serve us. For the operating system, these talents are operating system services . So what operating system services are there? To give a few examples:

· 用户界面
· 程序执行
· I/O 操作
· 文件系统操作
· 通信
· 错误检测
· 增值服务
· 资源分配
· 统计
· 保护和安全
· 操作系统服务
· 操作系统程序接口(系统调用)
· 操作系统用户界面
· 系统程序
  · · · · · 

Since the operating system has so many services, how do we usually use the operating system, or in other words, how do we use the housekeeper to serve us? There are two ways.

The first is to leave a small note to the housekeeper, telling him to go to the vegetable market in the afternoon to buy a few bottles of Tsingtao beer, and then the housekeeper ran away after seeing it. This method is commonly known as the command line , that is, a black window. Type commands in the black window and the system executes the command. This method is not easy to use. If you encounter any complicated operation, you will have to hit the keyboard for a long time.

The second type refers to where to fight. For example, when I saw that it was time to weed the garden, I called the housekeeper and said, "You see there are so many weeds here, you can arrange it and weed it." Then the housekeeper went to work again. This method is a graphical interface , such as our Windows and MacOS. This method is much simpler than the first one. Many operations can be done with a few clicks of the mouse, which is very comfortable~~~

Does the operating system seem to be nothing? As an ordinary user, very complicated operations can be completed with a few clicks of the mouse and the keyboard. Even for developers, the common API can be adjusted to complete the requirements. The reason why we can use the operating system so easily is because the operating system shields many implementation details. What we usually use is called user interface and system program . User interface and system program are the forms of service provided by the operating system to users, so who provides services for system programs- system calls . The system call is a service program provided by the operating system to the program.

Due to the existence of system calls, the programmer's work is greatly simplified. Didn’t the previous article say that the system operation is divided into user mode and kernel mode? When we call a system API, the operating system will switch from user mode Go to kernel mode and do a series of tasks. Such as open()

When executing open, the CPU switches from user mode to kernel mode. The operating system looks up the table according to the name "open" to find the location of the system call, then finds the entry address in the system call vector table, and then starts to execute the system call code. After the execution, the CPU switches to the user mode and returns the execution result to the application program.

System calls broadly divided into five 进程控制categories: 文件管理, 设备管理, , 信息维护and 通信.

Since system calls provide services for system programs, it is generally considered that the programs used to manage and maintain the operating system are system programs . So what are system programs?

  • File management
  • status information
  • File modification
  • Programming language support
  • Program loading and execution
  • communication

Operating system structure

More than ten years ago, there were no smart phones, only functional phones. The performance of functional phones was limited, and they could only play Tetris or something. With the continuous improvement of mobile phone performance, smart phone operating systems such as Android and IOS began to appear. The early Android system had limited functions and had an ugly interface. After so many years of development, it has become where it is today. I think there are two reasons to promote the development of operating system structure. The first is to optimize the system structure based on the existing hardware to improve performance. The second is to adapt to the constantly updated and iterative computer hardware to reflect the value of hardware .

  • 简单结构

    The early computer functions were very simple. When developing the operating system, there was no need to think too much about how the system should be designed. Just just do it. Even with a good design, under the limitations of computer hardware, its value cannot be well reflected. Therefore, the initial operating systems are small in scale and simple in functions. One person can build an operating system for a few months. The disadvantage is that it is not conducive to maintenance. With the development of computers, such operating systems are not suitable. Up.

  • 层次结构

    In order to design the operating system better, the idea of ​​modularity can be adopted, and the hierarchical structure is a modular idea. The hierarchical structure is the same as the building. The lowest layer is the hardware, and the highest layer is the user layer. Each layer uses only low-level functions and services, which means that the upper layer can call the services of the lower layer but not the services of other layers. Just like the picture below:

    The advantage of this structure is that it simplifies the system design and facilitates debugging and upgrade maintenance . For example, I can debug the first layer first, and then debug the second layer when there are no problems with the first layer. However, this design also has shortcomings, that is , the definition of layers is difficult and the efficiency is poor . For example, for a program to perform I/O operations, it needs to pass through the I/O layer, memory management layer, CPU scheduling layer, and then pass it to the hardware. Each layer will increase additional overhead, and the result is more than in a non-layered system. The execution will take more time.

  • 微内核结构

    With the further development of the operating system, the functions continue to be superimposed, and the kernel is also expanded. The problem brought about is that it becomes more and more difficult to manage. Just like a person, the more fat you get, the more difficult it is to move around. So there is a microkernel technology to optimize the modular structure, which is to move some non-core functions to the user space. The advantage of this design is that it is convenient to expand the system . All new services can be added in the user space. The kernel is basically No need to make changes. But this also brings a problem, which is to increase the communication overhead between user space and kernel space , so a message transfer mechanism is introduced .

  • 模块化结构

    The modular structure divides the functions of the system into different modules, and the modules communicate through interfaces. The modular structure is similar to the layered structure, the difference is that the layered structure can only communicate between two adjacent layers, while the modular structure is not restricted by this.

    A feature of the modular structure is that it will be loaded into the kernel when it is used, similar to when we use a computer when we use a mouse or keyboard to plug it into the computer. The advantage is that it is flexible and we can also design it ourselves. A module is then loaded into the system.

  • 混合结构

    When system designers are dissatisfied with a single system structure, they will choose a mixed structure to meet the performance, safety and other requirements, that is, the coexistence of multiple structures. Such as Mac the X-OS .

virtual machine

I believe many people have used a virtual machine. A virtual machine is a complete computer system that is implemented through software simulation, has complete hardware system functions, and runs in a completely isolated environment . Virtual machines are also divided into many types. There are high-level language virtual machines for specific language operation and use, and multiple operating systems virtualized on a computer.

  • Java虚拟机

    Anyone who learns Java should know that a major feature of Java is "write once, run in many places". Why does Java have this feature? Because of the existence of the Java Virtual Machine ( JVM ). Java programs are run in the JVM, and do not directly contact the computer's operating system and computer hardware. So as long as you install a specific JVM on a specific platform, such as the Linux version or the Windows version, you can implement a set of codes to run everywhere.

  • 工作站虚拟机

    Workstation virtual machine is to install many operating systems in a host operating system. For example, we can install a VMWare on our computer, and then install different operating systems in VMWare

    The biggest advantage of this method is convenience. For example, I usually need to use Docker on CentOS. If I install CentOS on a separate computer, it will not only cost money but also be troublesome. If I install a virtual machine, I can save a lot of money, and even I can run many CentOS at the same time as a cluster.

  • 服务器虚拟机

    The server virtual machine is a bit similar to the workstation virtual machine, but the difference is that it directly abstracts the physical resources of the server into logical resources, turning a server into several or even hundreds of isolated virtual servers without a host operating system. . There are two modes:

    One virtual machine: One server virtualizes into multiple server virtual machines

    Multiple virtual one : multiple independent physical servers are virtualized as one server virtual machine

    I think the biggest benefit of this approach is to improve resource utilization. For example, in our school, there are cloud computer rooms as well as traditional computer rooms. One of my biggest feelings is that the computers in some laboratories are rarely used at ordinary times, so they may only be used during class, and they can be used when they are not in use. After waiting for a few years, it was a bit stuck when the performance was not enough, which was very uncomfortable. The server virtual machine in the cloud computer room is very good, and it can be dynamically expanded to improve resource utilization.

to sum up

This article first introduces operating system services and interfaces, and then introduces several operating system structures, such as simple structure, hierarchical structure, and microkernel structure. Finally, several virtual machines are introduced, including JVM, workstation virtual machine, and server virtual machine. The next article will start the process~~~

Codeword is not easy, if you can, give me a 点赞, 收藏, 关注

this paper has been accepted for my Github repository daydayup : github.com/RobodLee/DayDayUP, welcome Star

Guess you like

Origin blog.csdn.net/weixin_43461520/article/details/108545283