[Operating System] Chapter One-Introduction to Operating System

Chapter 1: Introduction to Operating Systems

Preface

Operating System (Operating System, OS) is the first layer of software configured on computer hardware, and is the first expansion of the hardware system. Its main function is to manage these devices, improve their utilization and system throughput, and provide a simple interface for users and applications, which is convenient for users to use. OS is the most basic and important system software in modern computer systems, while other system software such as compilers, database management systems, and a large number of application software directly rely on the support of the operating system to obtain the services it provides . In fact, OS has become the system software that must be configured in modern computer systems, multiprocessor systems, and computer networks.

1. The goal and role of the operating system

The goal of the operating system is related to the application environment. For example, the OS used in the query system hopes to provide good human-computer interaction; for the OS used in industrial control, weapon control, and multimedia environments, it is required to have real-time performance; and for the OS configured on the microcomputer, it is What is more important is the convenience of its use.

1.1 Objectives of the operating system

The main purpose of configuring the operating system on the computer system is:Convenience, effectiveness, scalability and openness

  1. Convenience

    A computer system without an OS is extremely difficult to use. If users want to run their own programs directly on computer hardware (bare metal), they must write programs in machine language. But if the OS is configured on the computer hardware, the system can use compile commands to translate programs written by users in high-level languages ​​into machine code, or directly operate the computer system through various commands provided by the OS, which greatly facilitates users and makes The computer becomes easy to learn and use.

  2. Effectiveness

    The first meaning of effectiveness is to improve the utilization of system resources. In the early computer systems without OS, processors, I/O devices, etc. were often idle, and various resources could not be fully utilized. Therefore, at that time, improving the utilization of system resources was the main driving force for the development of OS. . Another meaning of effectiveness is to improve the throughput of the system. The OS can speed up the running of the program and shorten the running cycle of the program by rationally organizing the work flow of the computer, thereby improving the throughput of the system.

  3. Scalability

    In order to meet the requirements of computer hardware, architecture and computer application development, the OS must have good scalability. The scalability is very close to the structure of the OS, which promotes the continuous development of the OS structure: from the early unstructured to the modular structure, and then to the hierarchical structure, the OS has been widely adopted in recent years The micro-kernel structure. The micro-kernel structure can easily add new functions and modules, as well as modify the original functions and modules, and has good scalability.

  4. Openness

    The so-called openness refers to the system's ability to follow world standards and specifications, especially the OSI international standard for open system interconnection. In fact, all hardware and software developed in accordance with international standards can be compatible with each other and can be easily interconnected. Openness has become a core issue of computer technology after the 1990s, and it is also a crucial factor to measure whether a newly launched system or software can be widely used.

1.2 The role of the operating system

  1. OS as the interface between the user and the computer hardware system

    The OS is between the user and the computer hardware system, and the user uses the computer system through the OS. In other words, users can conveniently, quickly and reliably manipulate computer hardware and run their own programs with the help of the OS. The following figure is a schematic diagram of the OS as an interface. It can be seen that users can use the computer in three ways, namely, through the command mode, the system call mode, and the icon-window mode to communicate with the operating system and obtain its services.

    Insert picture description here

  2. OS as the manager of computer system resources

    In a computer system, it usually contains a variety of hardware and software resources. In summary, these resources can be divided into four categories: processors, memories, I/O devices, and files (data and programs). Correspondingly, the main function of the OS is to effectively manage these four types of resources. Processor management is used to allocate and control processors; memory management is mainly responsible for the allocation and recovery of memory; I/O device management is responsible for the allocation (recycling) and manipulation of I/O devices; file management is used to implement file management Access, share and protect.

    In addition, when a computer system is used by multiple users at the same time, many users' requirements for shared resources in the system (including quantity and time) may conflict. To this end, the operating system must authorize requests for the use of resources to coordinate the use of shared resources by users.

  3. OS realizes the abstraction of computer resources

    For a completely software-free computer system (ie bare metal), since it only provides the user with a hardware interface (physical interface), the user must have a full understanding of the implementation details of the physical interface, which results in the physical machine Difficult to use widely. In order to facilitate users to use I/O devices, people cover a layer of I/O device management software on the bare metal, as shown in the figure below, which implements the details of the I/O device operation and abstracts the I/O device upwards It is a set of data structures and a set of I/O operation commands, such as read and write commands, so that users can use these data structures, ie, operation commands, to input or output data without worrying about how I/O is implemented.

    Insert picture description here

1.3 The main driving force to promote the development of operating systems

  1. Continuously improve computer resource utilization
  2. User-friendly
  3. Continuous updating of devices
  4. Continuous development of computer architecture
  5. Constantly put forward new application requirements

2. The development process of the operating system

2.1 Computer system without operating system

  1. Manual operation
  2. Off-Line I/O mode

2.2 Single-channel batch processing system

2.3 Multi-pass batch processing system

2.4 Time Sharing System

2.5 Real Time System

2.6 Development of Microcomputer Operating System

  1. Single user single task operating system
  2. Single user multitasking operating system
  3. Multi-user and multi-task operating system

3. The basic characteristics of the operating system

3.1 Concurrence

It is the feature that the programs in the system can be executed concurrently, so that the OS can effectively improve the resource utilization in the system and increase the throughput of the system.

  1. Parallel and concurrency

    Parallelism means that two or more events happen at the same time; concurrency means that two or more events happen in the same time interval.

  2. Introducing the process

    In a system that does not introduce a process, the calculation program and the I/O program belonging to the same application can only be executed sequentially, that is, the I/O program is allowed to be executed only after the calculation program has been executed for a while; vice versa , When the program executes I/O operations, the calculation program cannot be executed either. But after creating a process (Process) for the calculation program and the I/O program, the two processes can be executed concurrently. If a process is created for multiple programs in the memory, they can be executed concurrently, which can greatly improve the utilization of system resources and increase the throughput of the system.

3.2 Sharing

  1. Mutually Exclusive Sharing

    Some resources in the system, such as printers, tape drives, etc., can be provided to multiple processes (threads), but it should be stipulated that only one process can access the resource within a period of time. For this reason, a mechanism should be established in the system to ensure mutually exclusive access to such resources by multiple processes.

  2. Simultaneous access

    There is another type of resource in the system that allows multiple processes to access them "simultaneously" within a period of time. The so-called "simultaneous" here is in a macroscopic sense in a single-processor environment, while at the microscopic level, these processes access the resource alternately. A typical resource that can be accessed "simultaneously" by multiple processes is a disk device. Some files written with reentrant codes can also be shared "simultaneously", that is, allowing several users to access the file at the same time.

3.3 Virtual

In the OS, the function of turning a physical entity into several logical counterparts through a certain technology is called "virtual".

  1. Time division multiplexing

    (1) Virtual processor technology. Use multi-program design technology to establish at least one process for each program, allowing multiple programs to be executed concurrently.

    (2) Virtual device technology. Virtualize a physical I/O device as multiple logical I/O devices, and allow each user to occupy one logical I/O device.

  2. Space Division Multiplexing Technology

    If it is said that multi-program technology (very multiplexing technology) is to use the free time of the processor to run other programs to improve the utilization rate of the processor, then the space division multiplexing technology is to use the free space of the memory to store in areas And run other multi-programs to improve memory utilization.

3.4 Asynchronism

In a multi-program environment, the system allows multiple processes to execute concurrently. In a single processor environment, because there is only one processor in the system, only one process is allowed to execute at a time, and the rest of the processes can only wait.

For each process in the memory, when can it get the processor to run, when it is suspended due to a certain resource request, and how fast the process advances, how much time does each program take to complete, etc. , Are all unpredictable. Due to the difference in the performance of each user program, it is likely that the job that enters the memory first is completed, and the job that enters the memory is completed first. In other words, the process advances at an unpredictable speed, which is the asynchronous nature of the process. Nevertheless, as long as a complete process synchronization system is configured in the OS and the operating environment is the same, the job will get exactly the same result even after multiple runs. Therefore, asynchronous operation is allowed and is an important feature of the operating system.

4. The main functions of the operating system

The main purpose of introducing OS is to provide a good operating environment for the operation of multi-programs, to ensure that multi-programs can run in an orderly and efficient manner, and to maximize the utilization of various resources in the system, which is convenient for users. use. For this reason, the traditional OS should have basic functions such as processor management, memory management, device management, and file management. In addition, in order to facilitate users to use the OS, it is necessary to provide users with a convenient user interface.

4.1 Processor management function

In the traditional multi-program system, the allocation and operation of the processor is based on the process as the basic unit, so the management of the processor can be attributed to the management of the process. The main functions of processor management are: creating and canceling processes, coordinating the operation of processes, realizing information exchange between processes, and assigning processors to processes according to certain algorithms.

  1. Process control

  2. Process synchronization

  3. Process communication

  4. Scheduling

    (1) Job scheduling

    (2) Process scheduling

4.2 Memory management function

The main task of memory management is to provide a good environment for the operation of multiple programs, improve the utilization rate of the memory, make it convenient for users to use, and expand the memory logically. To this end, memory management should have functions such as memory allocation and recycling, memory protection, address mapping, and memory expansion.

  1. Memory allocation

    The main tasks of memory allocation are:

    (1) Allocate memory space for each program, so they "get their own way."

    (2) Improve memory utilization and minimize unavailable memory space (fragmentation).

    (3) Allow running programs to apply for additional memory space to meet the needs of dynamic growth of programs and data.

    When the OS realizes memory allocation, it can adopt two methods: static and dynamic:

    (1) Static allocation method. The memory space of each job is determined when the job is loaded. During the entire running period after the job is loaded, the job is not allowed to apply for new memory space, and the job is not allowed to "move" in the memory.

    (2) Dynamic allocation method. Although the basic memory space required by each job is also determined at the time of loading, it allows the job to continue to apply for new additional memory space during the running process to adapt to the dynamic growth of programs and data, and also allows the job to "move" in the memory. ".

  2. Memory protection

    The main tasks of memory protection are: ①Ensure that each user program runs only in its own memory space and does not interfere with each other. ②Never allow user programs to access the programs and data of the operating system, nor allow user programs to be transferred to other user programs that are not shared for execution.

  3. Address mapping

    In a multi-program environment, since each program is compiled and linked to form a loadable program whose address starts from 0, it is impossible to load them into the memory from the "0" address (physical). As a result, the logical address in the address space (of each program segment) is not consistent with its physical address in the memory space. In order to ensure that the program can run correctly, the memory management must provide an address mapping function, that is, the logical address in the address space can be converted into the corresponding physical address in the memory space. This function is completed under the support of hardware.

  4. Memory expansion

    Memory expansion is not to expand the memory capacity physically, but with the help of virtual storage technology to logically expand the memory capacity, so that users feel that the memory capacity is much larger than the actual memory capacity, so that more user programs can be concurrent run. This not only meets the needs of users, but also improves the performance of the system. In order to expand the memory logically, the system must set up a memory expansion mechanism (including a small amount of hardware) to implement the following functions:

    (1) Request to call in function.

    (2) Replacement function.

4.3 Device management function

The main tasks of equipment management are as follows:

(1) Complete the I/O request put forward by the user process, allocate the required I/O device for the user process, and complete the specified I/O operation.

(2) Improve the utilization rate of CPU and I/O equipment, improve I/O speed, and facilitate users to use I/O equipment.

In order to achieve the above tasks, device management should have functions such as buffer management, device allocation, device processing, and virtual machine devices.

  1. Buffer management
  2. Equipment allocation
  3. Equipment handling

4.4 File management function

The main task of file management is to manage user files and system files for the convenience of users and ensure the security of files. To this end, file management should have functions such as file storage space management, directory management, file read/write management, and file sharing and protection.

  1. File storage space management
  2. Catalog management
  3. File read/write management and protection

4.5 The interface between the operating system and the user

  1. User interface

    (1) Online user interface

    (2) Offline user interface

    (3) Graphical user interface

  2. Program interface

    The program interface is set for user programs to access system resources during execution, and is the only way for user programs to obtain operating system services. It is composed of a set of system calls, and each system call is a subroutine that can complete a specific function. Whenever the application program requires the OS to provide a certain service (function), it calls the system call (subroutine) with the corresponding function. Early system calls were provided in assembly language, and system calls can only be used directly in programs written in assembly language.

4.6 New features of modern operating systems

Modern operating systems are developed on the basis of traditional operating systems. In addition to the functions of traditional operating systems, it also adds functions such as security-oriented, network-oriented, and multimedia-oriented.

  1. system security

    (1) Certification technology

    (2) Cryptography

    (3) Access control technology

    (4) Anti-virus technology

  2. Network functions and services

    (1) Network communication

    (2) Resource management

    (3) Application interoperability

  3. Support multimedia

    (1) Admission control function

    (2) Real-time scheduling

    (3) Storage of multimedia files

5.OS structure design

5.1 Traditional operating system structure

  1. Unstructured operating system

    In the early development of the operating system, the designer only focused his attention on the realization of functions and obtaining high efficiency, and lacked a consistent design idea. The OS at this time is a collection of a large number of processes. Each process can call other processes arbitrarily, making the operating system complex and chaotic. Therefore, this kind of OS is unstructured, and some people call it The overall system structure.

  2. Modular structure OS

    (1) The basic concept of modular programming technology

    Modular programming technology is a structured programming technology that appeared in the 1960s. The technology is based on the principles of "decomposition" and "modularity" to control the complexity of large-scale software. In order to make the OS have a clearer structure, the OS is no longer directly constituted by numerous processes, but is carefully divided into several modules with a certain degree of independence and size according to their functions. The following figure shows the modular OS structure composed of modules and sub-modules.

    Insert picture description here

    (2) Module independence

    In the module-interface method, the key issue is the division of modules and the provision of interfaces between modules. If we divide the module too small when dividing the module, although the complexity of the module itself can be reduced, it will cause too many connections between the modules, which will cause the system to be messy; if the module is divided too large, it will Increasing the internal complexity of the module increases the internal connections. Therefore, when dividing the module, a trade-off should be made between the two.

    Two standards to measure the independence of modules:

    ① Cohesion refers to the closeness of the connections between the various parts of the module.

    ② Coupling degree refers to the degree of mutual connection and mutual influence between modules.

    (3) Advantages and disadvantages of module interface method

    The OS developed by the module-interface method has the following obvious advantages over the unstructured OS:

    ①Improve the correctness, comprehensibility and maintainability of OS design.

    ②Enhance the adaptability of OS

    ③Accelerate the development process of OS

    Problems that still exist in modular structure design:

    ①In the OS design, it is difficult to meet the actual requirements for the interface after the module design is completed.

    ②In the OS design stage, the designer must make a series of decisions (decisions), and each decision must be based on the previous decision. However, in the modular structure design, the design of each module goes hand in hand, and it is impossible to find a reliable one. Deciding the order, resulting in the "disorder" of various decisions, which will make it difficult for programmers to make "every step in the design decision" is based on a reliable basis, so the module-interface method is also called " Unordered module method".

  3. Hierarchical structure OS

    (1) Basic concept of hierarchical structure

    To the module - the interface method "determine the order of" randomness into order of introduction of the ordered layering, layering is a design task, the target system A n- and bare metal systems (also known as host systems ) Between A 0 , lay several levels of software A 1 , A 2 , A 3 ,..., A n-1 , so that A n passes through A n-1 , A n-2 ,..., A 2 , A 1 layer , And finally can run on A 0 . In the operating system, the bottom-up approach is often used to lay these intermediate layers.

    (2) Disadvantages of hierarchical structure

    The main advantages of the layered structure are:

    ① It is easy to ensure the correctness of the system.

    ②Easy to expand and maintain.

    The main disadvantage of the layered structure is the reduced system efficiency. Since the hierarchical structure is hierarchical and unidirectional, it is necessary to establish a communication mechanism between each layer. Each time the OS performs a function, it usually traverses multiple layers from top to bottom, which will undoubtedly increase the communication overhead of the system. , Resulting in a decrease in system efficiency.

5.2 Introduction to Client/Server Model

The client/server model can be referred to as the C/S model for short. It has been popular all over the world in the 1990s, and the client/server model has been widely adopted in the various services provided by LAN, corporate network, and Internet.

  1. The origin, composition and types of the client/server model

    The client/server system is mainly composed of three parts:

    (1) Client

    (2) Server

    (3) Network system

  2. Client/server interaction

    (1) The client sends a request message

    (2) The server receives the message

    (3) The server sends back messages

    (4) The client receives the message

  3. Advantages of client/server model

    (1) Distributed processing and storage of data

    (2) Convenient for centralized management

    (3) Flexibility and scalability

    (4) Easy to adapt application software

5.3 Introduction to Object-Orientated Programming technology

  1. Basic concepts of object-oriented technology

    The technology is based on the principles of "abstraction" and "concealment" to control the complexity of large-scale software. The so-called object refers to the abstraction of a series of things that have the same properties and obey the same rules in the real world, and the concrete things are called instances of objects.

  2. The advantages of object-oriented technology

    (1) Improve product quality and productivity through "reuse".

    (2) Make the system easier to modify and easy to expand.

    (3) It is easier to ensure the "correctness" and "reliability" of the system.

5.4 Microkernel OS structure

  1. Basic concepts of microkernel operating system

    (1) Small enough kernel

    In a microkernel operating system, the kernel refers to a small kernel that is carefully designed to realize the most basic core functions of a modern OS. The microkernel is not a complete OS, but only puts the most basic parts of the operating system into the microkernel. Usually include: ①parts closely related to hardware processing; ②some basic functions; ③communication between client and server. The most basic part of these OSs is just to provide an important foundation for building a general-purpose OS, so that you can ensure that the operating system kernel is made small.

    (2) Based on client/server model

    Because the client/server model has many advantages, the client/server model is almost invariably adopted in the stand-alone microkernel operating system, which puts the most basic parts of the operating system into the kernel, and puts the absolute value of the operating system into the kernel. Most of the functions are implemented in a set of servers (processes) outside the microkernel, such as a process (thread) server that provides management of processes (threads), a virtual memory server that provides virtual memory management functions, and I/ The O device management I/O device management server, etc., are all implemented as processes, running in user mode, and information exchange is realized between the client and the server by means of the message transfer mechanism provided by the microkernel. The following figure shows the client/server model in a stand-alone environment.

    Insert picture description here

    (3) Apply the principle of "separation of mechanism and strategy"

    In the current structural design of operating systems, the principle of "separation of mechanism and strategy" is often used to construct the OS structure. The so-called mechanism refers to the specific implementing agency that realizes a certain function. The strategy is to achieve the optimization of the function with the help of certain parameters and algorithms on the basis of the mechanism, or to achieve different functional goals. Usually, the mechanism is at the basic level of a system, and the strategy is at the high level of the system.

    (4) Using object-oriented technology

    The operating system is an extremely complex large-scale software system. We can not only decompose the complexity of the operating system through structural design, but also control the complexity of the system based on the principle of "abstraction" and "concealment" in object-oriented technology. Use concepts such as "object", "encapsulation" and "inheritance" to ensure the "correctness", "reliability", "easy modification" and "easy scalability" of the operating system, and improve the design speed of the operating system.

  2. Basic functions of microkernel

    (1) Process (thread) management

    (2) Low-level memory management

    (3) Interruption and trapping processing

  3. The advantages of microkernel operating systems

    (1) Improve the scalability of the system

    (2) Enhance the reliability of the system

    (3) Strong portability

    (4) Provides support for distributed systems

    (5) Incorporating object-oriented technology

  4. Problems in the microkernel operating system

    Compared with earlier operating systems, the operating efficiency of the microkernel operating system has been reduced.

    The main reason for the reduction in efficiency is that when completing a service request from a customer to the operating system, it is necessary to use messages to achieve multiple interactions and to switch between user/kernel mode and context multiple times. However, in the early OS, when the user process requests the OS service, it usually only needs to switch the context twice: one is when the user mode turns to the system mode after the system call is executed; the other is when the system completes the user request. After the service, the system state returns to the user state.

    In the microkernel OS, since the communication between the client and the server, and the server and the server all need to pass through the microkernel, the same service request requires at least four context switches. The first time is when the client sends a request message to the kernel to request a server-specific service; the second time is when the kernel sends the client's request message to the server; the third time is when the server completes the client request Later, when the response message is sent to the kernel; the fourth time is when the kernel sends the response message to the client.

    The actual situation is that it often causes more context switches. For example, when a server itself is not capable of fulfilling client requests and needs the help of other servers, as shown in the figure below, the file server also needs the help of the disk server. At this time, 8 context switches are required.

    Insert picture description here

Guess you like

Origin blog.csdn.net/m0_50833438/article/details/114792147