Operating System Notes - Introduction

1 Introduction

1.1 Basic concepts of operating systems

1.1.1 Von Neumann model and computer system

Insert image description here

The model consists of 5 parts, the host part is composed of arithmetic unit and memory controller, and the peripheral part is composed of input device and output device.

A computer without configuration software is called a bare metal computer .Bare metal merely forms the hardware foundation of a computer system. The computer system actually presented to the user is a computer that has undergone several layers of software transformation.

Insert image description here

There is a hierarchical relationship between computer hardware, software and various parts of the software. The upper layer is the operating system.Through the resource management functions provided by the operating system and various user-friendly service functions, the bare metal is transformed into a machine with more powerful functions and more convenient use (usually called a virtual machine or expansion machine). Various utility programs and applications are on top of the operating system. These programs are supported by the operating system and provide users with various services needed to complete their work.

The operating system is the first layer of software on bare metal and isThe first expansion of hardware capabilities. The purpose of introducing an operating system is to:Provide an interface between computer users and computer hardware systems to make the computer system easier to use; effectively control and manage various hardware and software resources in the computer system so that they can be utilized more effectively; rationally organize the computer system Workflow to improve system performance

1.1.2 The concept of operating system

  • User point of view: Different types of operating systems are designed according to the different computers used by users.
  • System perspective (resource management perspective): From a resource management perspective,The operating system is the resource management program of the computer system. There are two types of resources in a computer system: hardware resources and software resources . They can be divided into 4 major categories of resources according to their functions:Processor, memory, peripherals and information (programs and data). These four types of resources constitute the material basis and working environment on which the operating system itself and user operations rely. Their usage and management strategies determine the size, type, function and implementation of the entire operating system. Corresponding to the above four types of resources,The operating system can be divided into processor management, memory management, device management and information management (i.e. file system), and conduct analysis and research respectively. Thus, the relevant content of the operating system can be organized from the perspective of resource management.
  • Process view: This view views the operating system as consisting of several programs that can run independently and a core that coordinates these programs. These running programs are called processes, and each process is used to complete a specific task (such as controlling the running of user jobs, processing the input/output of a certain device...). andThe core of the operating system is to control and coordinate the operation of these processes and solve the communication between processes.; It starts from the concurrent work of each part of the system, considers the division of management tasks and the relationship between them, and solves the competition problems caused by sharing resources through communication between processes. usually,Processes can be divided into two categories: user processes and system processes. These two types of processes coordinately run under the control of the core to complete user requirements.
  • Virtual machine perspective: The virtual machine perspective is also known as the machine scaling perspective. From this point of view,The operating system provides many service functions and a good working environment for users to use the computer. Users no longer directly use hardware machines (called bare metal), but control and use computers through the operating system. The computer is expanded into a virtual computer that is more powerful and easier to use.

From the perspective of functional decomposition, considering the structure of the operating system, the operating system can be divided into several levels. Each level completes specific functions to form a virtual machine, and provides support for the upper layer to form its operating environment. . Through layer-by-layer function expansion, the operating system virtual machine is finally completed, thereby providing users with a full set of services to meet user requirements .

1.1.3 Characteristics of operating systems

  • Concurrency:Concurrency refers to two or more events occurring at the same time; concurrency refers to two or more events occurring within the same time interval. Concurrency looks like parallelism at a macro level. Concurrent execution of programs can effectively improve the resource utilization of the system, but it will complicate the system. Therefore, the operating system must have the ability to control and manage various concurrent activities.
  • Sharability: Resource sharing means that the hardware and software resources in the system are no longer exclusive to a certain program, but can be used by multiple users.
    • Mutually exclusive sharing. Some resources in the system that can be shared, such as printers, certain variables, queues, etc.Resources that can only be used by one job at a time, it can only be used by other jobs after the current job has finished using it and released it.
    • Visit simultaneously. Another type of resource in the system, such as disks, reentrant code, etc., canFor simultaneous access by multiple jobs

Concurrency and sharing are the two most basic features of operating systems, the two are mutually existing conditions. On the one hand, the sharing of resources is conditioned on the concurrent execution of programs. If the system does not allow the concurrent execution of programs, there will naturally be no resource sharing problem; on the other hand, if the system cannot effectively manage resource sharing, it must also It will affect the concurrent execution of the program, or even prevent concurrent execution at all.

  • Virtuality: In an operating system, virtuality refers toTurn a physical entity into several logical counterparts. The former is actual and the latter is virtual. This is just a feeling of the user.. For example, after the introduction of multi-programming technology into the operating system, although there is only one CPU and can only execute one program at a time, through time-sharing, within a period of time, this processor can macroscopically run multiple programs at the same time. program. It gives the user the feeling that each program has a CPU serving it. That is, multiprogramming technology can virtualize one physical CPU into multiple logical CPUs. In addition, there is virtual memory (logically expanded memory). capacity), virtual devices (exclusive devices become shared devices) and other technologies.
  • Asynchronousness: In a multiprogramming environment, due to resource constraints and other factors, the program runs in a "stop-and-go" manner.When each program in the system is executed, the order in which multiple programs are executed, and the time required to complete each program are all uncertain and therefore unpredictable.

1.1.4 Main functions and services provided by the operating system

The function of the operating system is to manage the software and hardware resources in the system, rationally organize the computer's workflow, and provide users with a good working environment and a friendly interface.

The five basic functions of the operating system: processor management, memory management, device management, file management and user interface.

Processor management

The main tasks of processor management areImplement effective management of processor allocation and operation. In a multiprogramming environmentThe allocation and operation of the processor is based on the process, so the management of the processor can be attributed to the management of the process.

  • Process control. Responsible for process creation, cancellation and state transition.
  • Process synchronization. Coordinate concurrently executing processes.
  • Process communication. Responsible for completing information exchange between processes.
  • Process scheduling. Processor allocation is performed according to a certain algorithm.

memory management

The main task of memory management is to allocate, protect and expand memory.

  • Memory allocation. Allocate memory for each program according to a certain strategy.
  • Memory protection. Ensure that each program runs in its own memory area without interfering with each other.
  • Memory expansion. In order to allow large jobs or multiple jobs to run, virtual storage technology must be used to obtain the effect of increasing memory.

Device management

The management of computer peripherals is the most complex and trivial part of the operating system.The main task of device management is to effectively manage all devices within the computer system

  • Equipment allocation. Allocate equipment according to certain equipment allocation principles. In order to make the device and the host work in parallel, buffering technology and virtualization technology are also needed.
  • Device transfer control. Realize physical input/output operations, that is, starting devices, interrupt processing, end processing, etc.
  • Device independence. That is, the devices in the user program have nothing to do with the actual physical devices used.

File management

The part of the operating system responsible for information management is called the file system, hence the name file management.The main task of file management is to effectively support file storage, retrieval and modification operations, and to solve file sharing, confidentiality and protection issues.

  • Management of file storage space. Responsible for managing file storage space, including storage space allocation and recycling functions.
  • Directory management. A directory is a data structure set up to facilitate file management. It provides access by name.
  • File operation management. Implement file operations and be responsible for completing data reading and writing.
  • File protection. Provides file protection function to prevent files from being damaged.

user interface

In order to facilitate users to use the operating system, the operating system also provides a user interface.

  • Command interface.Provides a set of commands for users to directly or indirectly control their own jobs. There are mainly two command interface control methods, namely online command interface and offline command interface .
    • The online command interface, also known as the interactive command interface, is suitable for time-sharing or real-time operating systems. It consists of a set of keyboard operation commands. Users input operation commands through the console or terminal to put forward various service requirements to the system.Every time the user inputs a command, control is transferred to the command interpreter of the operating system, and then the command interpreter interprets and executes the entered command to complete the execution function.. Control then returns to the console or terminal, where the user can enter the next command.
    • The offline command interface is also called the batch command interface, which is suitable for batch processing systems. It consists of a set of job control commands (or job control statements).Offline users cannot directly intervene in the running of the job. They should write a job operation instruction with the corresponding job control command in advance and submit it to the system together with the job. When the system schedules the job, the command interpreter in the system interprets and executes the command or control statements on the job description one by one, thereby indirectly controlling the operation of the job.
  • program interface.Also called system call, it is a program-level interface. The system provides a set of system call commands for user programs and other system programs to call.. Users can directly use this set of system call commands in the program to make various service requests to the operating system, such as using peripherals, applying for memory allocation, disk file operations, etc.
  • Graphical interface. The graphical interface (also called graphical interface) that has emerged in recent years isGraphical online command interface. You can know what services the operating system provides by the functions of the operating system: the operating system provides an environment for executing programs. The services provided include program execution, I/O operations, file operations, resource allocation and protection, error detection and elimination, etc. .

1.2 Development and classification of operating systems

1.2.1 The formation and development of operating systems

The development process of operating systems is actually closely related to the problems encountered by early people. For example, offline input/output technology was proposed to solve the speed contradiction between processors and devices, and batch processing technology was developed to reduce human intervention. , it can be seen that the development of operating systems is a very natural solution to the problems of early computer systems.

The operating system has gone through the following development process

  • Manual operation (without operating system)

    • User exclusive use of the entire machine
    • CPU waiting for manual operation

    Offline input/output technology is proposed to solve the speed mismatch between the CPU and I/O devices. This technology reduces the idle waiting time of the CPU and increases the IO speed.

Insert image description here

  • Batch systems (operating systems begin to appear)

    • Single lane batch processing system

    Insert image description here

    First transfer the first job on the tape to the memory, and give the control of the operation to the first job. When the first job is processed, the control is returned to the supervisor program, and the supervisor program then transfers the second job to the memory. A job is loaded into memory.In this way, the computer system automatically processes the jobs on the tape one after another until all the jobs on the tape are processed., thus forming an early batch processing system.

    • Features: Automatic, sequential, single-channel.

    • Disadvantage: During I/O operations, the CPU has nothing to do.

    • Multi-channel batch processing operating system

    Insert image description here

    • Features: Multi-channel, macro-level multi-task parallelism, and micro-level multi-task slicing serialization.

    • Advantages: System throughput is improved due to improved utilization of CPU, memory and I/O devices.

    • issues that need resolving

      • Processor management problems, memory management problems, I/O device (input and output device) management problems, file management problems, and job management problems.
      • Disadvantages: No interactive capabilities.
  • time sharing system

    • Features: multi-channel, independence, timeliness, interactivity.
  • real time system

    • Features: multi-channel, independence, timeliness, interactivity and reliability.
  • Microcomputer operating system

    • Single-user single-tasking systems, single-user multi-tasking and multi-user multi-tasking systems.
  • embedded operating system

    An embedded operating system is a software system that runs in an embedded system environment and performs unified coordination, scheduling, command and control of the entire embedded system and the various components and devices it operates and controls.

  • cluster system

    A clustered system couples two or more independent systems to complete a task. The definition of cluster has not been finalized yet,The generally accepted definition is a cluster of computers that share storage and are closely connected through a LAN network. A cluster usually has several node computers and one or more monitoring computers, where the monitoring computers are used to manage and control the nodes, issue work instructions, etc.

  • network operating system

    A network operating system is a system that interconnects multiple physically dispersed computer systems with autonomous functions through communication facilities to achieve information exchange, resource sharing, interoperability and collaborative processing.Its goal is to achieve mutual communication and resource sharing

  • Distributed operating system

    Distributed system refers toA system consisting of multiple distributed processing units connected via an interconnected network, each processing unit has a high degree of autonomy and collaborates with each other. It can realize resource management, dynamically allocate tasks within the system, and run distributed programs in parallel.

    Features: unity, sharing, transparency, autonomy.

1.3 Operating system environment

1.3.1 CPU operating mode

In order to prevent the operating system and its key data (such as PCB, etc.) from being intentionally or unintentionally damaged by user programs, the execution state of the processor is usually divided into two types: core state and user state.

  • core state. The core state, also known as the management state and system state, is the state of the machine when the operating system management program is executed. It has higher privileges, can execute all instructions including privileged instructions, and can access all registers and storage areas .
  • User mode. User mode, also known as eye mode, is the state of the machine when user programs are executed. It is an execution state with lower privileges. It can only execute specified instructions and can only access specified registers and storage areas .

User-mode programs cannot directly call core-mode programs, butBy executing the command to access the core state, an interrupt is caused, and the interrupt system is transferred to the corresponding program in the operating system., for example, when a system call is made, the user mode is converted to the core mode.

Privileged instructions :Instructions that can only be used by the operating system kernel part and are not allowed to be used directly by users., such as I/0 refers to the set interrupt mask instruction, clear memory instruction, storage protection instruction and set clock instruction.

Some modules in the operating system that are closely related to hardware (such as clock management, interrupt processing, device drivers, etc.) and programs with higher running frequencies (such as process management, memory management, device management, etc.) constitute the kernel of the operating system.The kernel's instruction operations work in the core state

  • Clock management. The clock is the most critical device among all components of the computer . The operating system provides standard system time to users through clock management. In addition, through the management of clock interrupts, process switching can be realized, such as time slice rotation scheduling.
  • interrupt mechanism. Keyboard or mouse input, process management and scheduling, system function calls, device drivers, file access, etc. all rely on the interrupt mechanism. In the interrupt mechanism, only a small part belongs to the kernel, which is responsible for protecting and restoring information at the interrupt site, and transferring control to the relevant handler. This can reduce the processing time of the terminal and improve the parallel processing capability of the system.
  • Primitives. Primitives are small utility routines used to turn off interrupts
    • It is at the bottom of the operating system and is the part closest to the hardware.
    • Program execution is atomic, and operations can only be completed in one go.
    • These programs have short running times and are called frequently.
  • Data structure and processing for system control. In the operating system, some data structures are needed to register status information, such as job control blocks, process control blocks, device control blocks, various linked lists, message queues, buffers, free registration areas, memory allocation tables, etc.; in addition In addition, a series of operations on these data structures should be defined: process management, memory management, and device management.

1.3.2 Interrupt and exception handling

Interrupts, also known as external interrupts, are part of the normal functions of the system. For example, due to process scheduling, the system stops the currently running process and executes other processes, or interrupts the current operation due to lack of required resources and waits for the arrival of resources. After other things are processed, the process before the interruption will be continued.

Exceptions, also called internal interrupts, are caused by errors, such as file corruption, process out of bounds, etc.

Usually exceptions cause interrupts, but interrupts are not necessarily caused by exceptions.

1.3.3 System calls

System call is one of the user interfaces provided by the operating system. It is a collection of all system calls implemented by the operating system, that is, the program interface or Application Programming Interface (API). It is the interface between the application program and the system.

The main function of the operating system is to create a good environment for applications to run. In order to achieve this goal, the kernel provides a series of kernel functions with predetermined functions, which are presented to users through a set of interfaces called system calls. The system call passes the application request to the kernel, calls the corresponding kernel function to complete the required processing, and returns the processing result to the application program. Without system calls and kernel functions, users would not be able to write large applications. The system calls provided by the operating system usually include process control, file system control (file read and write operations and file system operations) system control, memory management, network management, socket control user management, and inter-process communication (signals, messages, pipes, semaphores and shared memory).

When the user needs to perform a system call,First, prepare and pass the parameters required for the system call, and enter the system kernel of the operating system through the trap instruction. At this time, it will enter the kernel state from the user mode; then execute the corresponding system call function and use specific system kernel functions; finally Return the processing result to the user process. At this time, it will return from the kernel mode to the user mode.

Insert image description here

1.4 Operating system architecture

The architecture of the operating system is the component structure of the operating system.The architecture of the operating system mainly includes module combination structure, hierarchical structure and microkernel structure

1.4.1 Module combination structure

The module combination structure is the architecture of early operating systems before the emergence of software engineering and some current small operating systems.The operating system is a system program with multiple functions. It can be regarded as an integral module or a system composed of several modules according to a certain structure.. Each module in the system is divided according to the functions they want to complete. These functional modules are combined according to a certain structural method to collaboratively complete the functions of the entire system.

  • Advantages: compact structure, simple and direct interface, relatively high system efficiency.
  • Disadvantages: The modules of this structure can be switched at will, and each module is involved with each other. It is not easy to grasp the independence of the module, resulting inThe structure of the system is unclear. Secondly, this kind ofThe structure is less scalable. When replacing a module or modifying a module, you must first clarify the interfaces between modules. If you want to design a new module according to the originally designed module interface, and the originally designed module interface is likely to be arbitrarily agreed, then you need to do this There is a certain degree of difficulty in this work. Finally, thisPoor adaptability of structural systems. As the scale of the system continues to increase, the complexity of the system constructed using this structure will increase rapidly, so it is only suitable for systems with small systems, few modules, and relatively stable usage environments.

1.4.2 Hierarchy

To make up for the shortcomings of inter-module calls in the module combination structure, it is necessary to improve the irregular mutual calls and interdependence relationships between modules, especially to eliminate the cyclic calls between modules.The design of the hierarchical structure starts from this point and strives to change the disorder of calls between modules into order and reduce the irregularity of module calls.. Designing the operating system according to the hierarchical structure isArrange all functional modules of the operating system into several layers according to the order of function calls, so that there are only one-way calls and one-way dependencies between functional modules

  • Advantages: The organization and dependencies between modules are clear and clear,The upper-layer functions are built on the lower-layer functions, and the readability, adaptability and reliability of the system are enhanced. In addition, when modifying or replacing a certain layer, it will only affect two adjacent layers at most, making it easy to modify and expand.
  • Disadvantages: Which layer should the various functional modules of the operating system be placed on, and how to effectively layer them are issues that must be considered.

1.4.3 Microkernel structure

With the widespread application and development of network technology, it is necessary to provide users with a distributed system environment that is suitable for processing distributed information. Therefore, the operating system can adopt a microkernel structure.The main idea of ​​the microkernel is to leave only some of the most basic functions in the operating system kernel, and separate other services from the kernel as much as possible, by several processes (i.e. server processes) running in user mode. Implementation, forming the so-called "client/server" model, that is, C/S model. Ordinary user processes (ie, client processes) can send requests to the server process through the kernel to obtain operating system services. It can be seen from the main idea of ​​the microkernel structure that it is very suitable for distributed systems.

  • Advantages: First of all, each service process runs in an independent user process. Even if a server fails or problems occur, it will not cause other servers and other components of the system to collapse, and the reliability is good; secondly, the system has good Flexibility, as long as the interface is standardized, the operating system can easily add and delete service functions; thirdly, it is easy to maintain, that is, modifying the server code will not affect other parts of the system; finally, this structured operating system is suitable for distributed processing computing environments.
    User process) can send requests to the server process through the kernel to obtain operating system services. It can be seen from the main idea of ​​the microkernel structure that it is very suitable for distributed systems.

  • Advantages: First of all, each service process runs in an independent user process. Even if a server fails or problems occur, it will not cause other servers and other components of the system to collapse, and the reliability is good; secondly, the system has good Flexibility, as long as the interface is standardized, the operating system can easily add and delete service functions; thirdly, it is easy to maintain, that is, modifying the server code will not affect other parts of the system; finally, this structured operating system is suitable for distributed processing computing environments.

  • Disadvantages: The operating system with this structure is not efficient because all user processes have to communicate with each other through the microkernel, so the microkernel itself becomes the "bottleneck" of the system, especially systems with frequent communication.

Guess you like

Origin blog.csdn.net/pipihan21/article/details/129587160