[Notes] Operating System (2)-Operating System Structure

Preface

1. Operating system service

This section discusses what services the operating system provides .

The types of services provided by the operating system: user interface, program execution, I/O operations, file system operations, communications, error detection, resource allocation, statistics, protection, and security.

User interface (user interface, UI): Divided into command-line interface (CLI) and graphical user interface (graphical user interface, GUI).

Program execution: The system must be able to load the program into memory and run the program. The program must be able to end execution, including normal or abnormal end.

Communication: In many cases, a process needs to exchange information with a process. Communication can be achieved through shared memory or through information exchange technology (for information exchange, message packets are moved between processes through the operating system).

Resource allocation: When there are multiple users or multiple jobs running at the same time, the system must allocate resources for each of them.

Second, the user interface of the operating system

Command interpreter

The command interpreter is relative to the command line interface, which is what we often call Shell. The main function of the command interpreter is to obtain and execute the next command specified by the user.

Classification of command interpreters : Command interpreters contain codes to execute these commands; most commands are implemented by system programs (used in UNIX systems, and programmers can easily add commands to the system by creating new files with appropriate names).

GUI

The windows and macOS we commonly use are graphical user interfaces by default. But also provide a command line interface.

Three, system call

System calls: The operating system kernel provides a series of predetermined functions, which are presented to programmers through a set of interfaces called system calls. The system calls pass application requests to the kernel, and the system calls the corresponding kernel functions to complete the required processing. The processing result is returned to the application. System calls are part of the kernel.

System call example: write a simple program that reads data from one file and copies it to another file (the blue part is a series of system calls).
Insert picture description here
Application program interface (applicatino interface, API): API is a series of functions suitable for programmers, including the parameters passed to each function and the values ​​that programmers want to return. It can be understood that an API is an encapsulation of system calls. An API operation often contains multiple system calls. A single programmer does not need to know which API calls are made, that is, the details are hidden.

API example:
Insert picture description here
The relationship between the ReadFile() method in Windows32API and the system call: three methods for handling a user application that calls the open() system call and
Insert picture description here
operating system parameters:

  1. Pass parameters through registers.
  2. Store the parameters in the memory block and table, and pass the block address through the register.
  3. The parameter tongg program is pushed onto the stack and popped out by the operating system.

Four, system call type

Type and content of system call

Process control
  1. End
  2. Load, execute
  3. Create process, terminate process
  4. Get process attributes, set process attributes
  5. waiting time
  6. Wait for event, signal event
  7. Allocate and release memory
File management
  1. Create files, delete files
  2. Open file, close file
  3. Read, write, reposition
  4. Get file attributes, set file attributes
Equipment management
  1. Request device, release device
  2. Read, write, reposition
  3. Get device properties, set device properties
  4. Connect or disconnect devices logically
Information maintenance
  1. Get time or date, set time or date
  2. Get system data, set system data
  3. Get process, file or device attributes
  4. Set process, file or device properties
communication
  1. Create, delete communication connection
  2. Send and receive messages
  3. Transmission status information
  4. Attach or disconnect remote equipment

Five, system procedures

System program: The system program provides a convenient environment to develop and execute programs. A small part of the system program is just a simple interface for system calls, others may be quite complicated. Divided into the following categories: file management, status information, file modification, program language support, program execution and loading, and communication .

The relationship between the operating system and the system program: It can be understood from the computer logic level. The bottom layer is the hardware, and the operating system is above, followed by the system program, and finally the application program. The system program is the operating system except the kernel.

6. Operating system design and implementation

Seven, operating system structure

Simple Structure

Early operating systems did not have a very good architecture, and some did not even distinguish between user mode and system mode, resulting in system instability.

Layered structure (Layered approcah)

The operating system is divided into multiple levels, the lowest level is the hardware, and the highest level is the user interface. Each layer is implemented only by the lower level functions, thus forming a hierarchical structure.
Advantages: Simplified construction and debugging.
Disadvantages: The coupling between levels is high, and it is difficult to define between levels. Another problem is that the efficiency of the hierarchical structure is low. A system commissioning may have to fall into multiple layers and then return, which increases a lot of expenses.

Microkernels

Remove all non-essential parts from the kernel and implement them as system programs or user programs, resulting in a smaller kernel. The microkernel usually includes minimal process management, memory management, and communication functions.

The main function of the microkernel is to enable communication between client programs and various services running in user space. Communication is provided in the form of messaging.

Example: If a client program wants to access a file, it must interact with the file server. The client program and the server never interact directly, but through the message transmission of the microkernel.

advantage:

  1. Easy to expand the operating system.
  2. The operating system is easy to transplant.
  3. Better safety and reliability.

Disadvantages:
The decrease in system performance due to the increase in the total overhead of system functions (the lack of communication between various services, which can only rely on the information transmission of the microkernel, resulting in a decrease in efficiency).

Modules

Using object-oriented features, each function is modularized, and each module uses an interface for communication, and part of the content can be loaded into the kernel for operation when needed. It is similar to a hierarchical structure, but there is no dependency relationship between the upper and lower layers, and the modules can call each other, which is more flexible. It is similar to a microkernel, but it loads content into the kernel when necessary, which is more efficient than a microkernel.

Eight, virtual machine

Virtual machine: The core idea of ​​a virtual machine is to abstract a set of hardware devices into multiple sets. The use of CPU scheduling and virtual memory technology creates the "illusion" that each process has its own separate processor and memory.

Advantages: For operating system designers, virtual machines can be used for system development without interruption and stop the current operating system; for users, each virtual machine is completely independent of other virtual machines, so different system resources are completely protected , No need to consider security issues.

How does the virtual machine realize resource sharing?

There are two ways:

  1. Files can be shared by sharing small disks. This scheme simulates the sharing of physical disks, but is implemented through software.
  2. You can define a network of virtual machines, and each virtual machine communicates through the virtual network to deliver messages. Similarly, the network is simulated in accordance with the physical communication network, but is implemented through software.

Virtual machine instance (Java virtual machine)

Java Virtual Machine (Java Virtual Machine): Java objects are described by class structure: Java programs are composed of one class or multiple classes. For each Java class, the Java compiler generates a platform-independent bytecode output file (.class), which can run on any JVM.

JVM is an abstract computer specification. It includes a class loader and a Java interpreter that executes platform-independent bytecode. The class loader loads the compiled .class file from the Java program and JavaAPI. In order to be executed by the Java interpreter.
Insert picture description here

Nine, system generation (System Generation)

It is to configure (not design) a specific operating system for a specific target , and usually need to consider such issues:

  1. What CPU is used?
  2. How much memory is available?
  3. What equipment is available?
  4. What operating system options or parameter values ​​are required?

10. System startup

Bootloader: Most computer systems have a small piece of code called a successful bootstrike or bootloader. This code can locate the operating system kernel, load it into memory and start execution.

Guess you like

Origin blog.csdn.net/qq_41882686/article/details/112388252