Notes for Chapter 2 of "Operating System Concept Essentials"

Operating system services:

The operating system provides an environment to execute programs, and it provides certain services to programs and program users. Operating system services facilitate programmers and make programming easier.

The operating system has a set of services to provide user functions:
① User interface: Almost all operating systems have a user interface (UI). There are many forms of this interface.
One is the command line interface, which uses text commands and is input by a certain method.
The other is a batch processing interface. Commands and instructions that control these commands can be written into files for execution. The most commonly used is the graphical user interface (GUI).

②Program execution: The system should be able to load the program into the memory and run it. The program should be able to end execution, including normal or abnormal (and give an error).

③I/O operation: Program operation may require I/O, and these I/O may involve files or equipment. For efficiency and protection, users generally should not directly control I/O devices. The operating system must provide means to perform I/O.

④File system operation: The program needs to read and write files and directories, and also needs to create and delete files based on file names, search for a given file, and list file information.

⑤Communication: A process needs to exchange information with another process. This kind of traffic may occur between two processes running on one computer, or between processes running on different computers connected via a network. Communication can be achieved through shared memory or through message exchange.

⑥ Error detection: The operating system needs to continuously detect and correct errors.

⑦Resource allocation: When multiple users or multiple jobs are running at the same time, each should allocate resources.

⑧Accounting: We need to record the type and quantity of resources used by users.

⑨Protection and security: For information stored in multi-user or networked computer systems, users may need to control the use of information. When multiple independent processes execute concurrently, one process should not interfere with other processes or the operating system itself. Protection should ensure that all access to system resources is controlled. It is also important that the system is safe and protected from external intrusions. This kind of security requires users to authenticate themselves to the system (using a password) in order to gain access to system resources.

The interface between the user and the operating system:
①Provide a command line interface or command interpreter, allowing the user to directly input commands for the operating system to execute.
The main function of the command interpreter is to obtain and execute the next command specified by the user. This layer provides many commands to manipulate files: create, delete, list, print, copy, execute, etc. There are two ways
to implement these commands : i. The command interpreter itself includes code to execute these commands.
ii. Realize most commands through system programs.

②Allow users to interact with the operating system through a graphical interface (GUI).
Instead of inputting commands directly through a command line interface, users use the desktop concept, which uses a mouse-based window and menu system. The user moves the mouse to locate the pointer to the icons on the screen, and these icons represent programs, files, directories, and system functions. According to the position of the mouse, pressing the mouse can call up programs, select files and directories, or open menu commands.

System call:

System calls provide operating system service interfaces. The application developer designs the program according to the application programming interface (API). The benefits of API:
①The portability of the program.
②The actual system call pays more attention to details and is more difficult to use than the API.

For most programming languages, the runtime support system (function library directly provided by the compiler) provides a system call interface to connect to the system calls of the operating system. The system call interface loads the API function calls and calls the required system calls in the operating system. Usually, each system call has a related number, and the system call interface will build a sequence table based on these numbers.

The caller does not need to know how to implement the system call, but only needs to follow the API and know what the operating system does after the system call. Through the API, most of the details of the operating system interface can be hidden, and the class is managed by the runtime library.

There are three ways to parameterize the operating system site:
①Transfer parameters through registers.
②It is stored in a block or table of memory, and the address of the block or table is passed through the register.
③ Put or push into the stack through the program, and pop out through the operating system.

Types of system calls:
① Process control: The
execution program should be able to stop execution normally or abnormally. If a system call abnormally stops the currently executing program, or the program encounters a problem and causes an error to be trapped, then sometimes the memory is dumped to disk and an error message is generated. After the memory information is dumped to disk, the debugger can be used to determine the cause of the problem. Regardless of normal or abnormal conditions, the operating system should immediately transfer control to the calling command interpreter. The command interpreter then reads in the next command.
For interactive systems, the command interpreter simply reads the next command, assuming that the user will use the appropriate command to handle the error.
For GUI systems, a pop-up window can be used to remind the user of an error and request guidance.
For batch systems, the command interpreter usually ends up the entire job and continues to the next job.
The more serious the error, the higher the level of error transmission. By defining the normal error level as 0, normal and abnormal termination can be handled together.

The process or job that executes one program may require the loading and execution of another program. This function allows the use of a command interpreter to execute a program, which can be given by user commands, mouse clicks, or batch commands.

If the applet is terminated and control is returned to the existing program, then the memory image of the existing program must be saved. Therefore, a mechanism is actually created so that one program can call another program.

Usually, two or more processes will share data. In order to ensure the integrity of the shared data, the operating system usually provides system calls to allow one process to lock the shared data. In this way, other processes cannot access the data before unlocking.

②File management

③Equipment management:
some resources are needed for process execution, such as memory, disk drive, required files, etc.

④Information maintenance:
Single step, that is, a trap will be generated every time the CPU executes an instruction. The debugger can usually catch these traps.

⑤Communication:
There are two commonly used models of inter-process communication:
i. Message transfer type: Communication processes transfer information by exchanging information with each other. The information exchange between processes can be done directly or indirectly through a common mailbox. Before starting communication, a connection should be established first. You should know the name of another communicating entity. It may be another process of the same system, or it may be a process of another computer connected via a network. Every network computer has a host name, and every host also has a network identifier, such as an IP address. Similarly, each process has a process name, which can usually be converted into an identifier for reference by the operating system. Most of the processes that can accept connections are dedicated daemons, that is, dedicated system programs. The communication source is called the client, and the receiving daemon is called the server.
ii. Shared memory model: Processes create shared memory through system calls and access memory areas owned by other processes. Note that the operating system usually needs to prevent one process from accessing the memory of another process. Shared memory requires that two or more processes agree to remove this restriction so that they can exchange information by reading and writing data in the shared area.

Information transfer is useful for the exchange of small amounts of data because there are no conflicts to avoid. Compared with the shared memory used between computers, it is also easier to implement. Shared memory has the characteristics of high speed and writing in terms of communication, because when the communication occurs in the same computer, it can be carried out at the memory transfer speed. However, processes sharing memory have problems with protection and synchronization.

⑥ Protection
Protection provides a mechanism to control access to computer system resources.

System program

Another feature of modern operating systems is a set of system programs. System programs are also called system tools, which provide a convenient environment for program development and execution. System programs can be divided into the following categories:
①File management: These programs create, delete, copy, rename, print, dump, list, and manipulate files and directories.
②Status information: Some program courses get the date, time, available amount of memory or disk space, number of users or other status information from the system. Some systems also support a registry, which can be used to store and retrieve configuration information.
③File modification: There are multiple editors to create and modify files located on disks or other storage devices.
④Program language support: compilers, assemblers, debuggers and interpreters of commonly used programming languages ​​are usually provided to users together with the operating system.
⑤Program loading and execution: Once the program is assembled or compiled, it must be loaded into the memory before it can be executed.
⑥Communication: It provides a mechanism for creating virtual connections between processes, users, and computer systems.
⑦Background service: All general systems have methods to create some system program processes when booting. System processes that are always running are called services, subsystems, or daemons.

Design and implementation of operating system:

Design purpose:
The first issue of system design is to define goals and specifications. Requirements can be divided into two categories:
①User goals
②System goals

Mechanism and strategy:
An important principle is the separation of strategy and mechanism. The mechanism feels how to do it, and the strategy determines what to do.
For flexibility, the separation of strategy and mechanism is essential.
As long as you decide whether to allocate resources, you should make a strategic decision. As long as the question is "how to do" rather than "what to do," it must be determined by the mechanism.

Implementation: The advantages of
using a high-level language or at least a system implementation language to implement an operating system are the same as writing applications in a high-level language: the code is faster to write, more compact, and easier to understand and debug. In addition, the improvement of programming technology makes it possible to improve the generated code of the entire operating system as long as it is recompiled. Finally, if you use a high-level language to write, the operating system is easier to transplant. The shortcomings of using a high-level language to implement an operating system are only the reduction in speed and the increase in storage.

The structure of the operating system

Layered approach:
There are many ways to modularize the system. One method is the layered method, that is, the operating system is divided into nogan layers (levels). The lowest layer (layer 0) is the hardware, and the highest layer (layer N) is the user interface. The main advantage of the layered method is that it simplifies the construction and debugging. The selected layer requires that each layer can only call lower-layer functions (operations) and services. This method simplifies the debugging and verification of the system. The implementation of each layer uses the operations provided by the lower layer, and only needs to know these What does the operation do without knowing how these operations are implemented. Exceptions, each layer must hide certain data structures, operations, and hardware for higher layers. The main difficulty of the layering method is to define each layer reasonably. Since each layer can only use the functions of the lower layers, careful planning is necessary for exceptions.

Microkernel:
The operating system constructed by the microkernel removes all unnecessary components from the kernel and treats them as system-level and user-level programs. This results in a smaller kernel.

The main function of the microkernel is to provide communication between the client and various services running in the user space. Communication is provided through message passing. If a client program wants to access a file, it should interact with the file server. The client program and the server do not interact directly, but communicate indirectly through the message passing of the microkernel.

One of the advantages of the microkernel is that it is easy to extend the operating system.

Module:
The best way to design an operating system at present is to use a loadable kernel module. The kernel has a set of core components, no matter at startup or runtime, the kernel can link in additional services through modules.
The idea of ​​this design is that the kernel provides a harmonious service, while other services can be dynamically implemented while the kernel is running. Dynamic link services are better than adding new features directly to the kernel, because the latter has to recompile the kernel for each change. This overall system function is similar to a layered system, where each core part has a defined and protected interface. But it is more flexible than a layered system, because any module can call any other module.

Hybrid system

Few operating systems use a single, strictly defined structure. Instead, they combined different structures to form a hybrid system to solve performance, safety, and availability issues.

Operating system debugging

Broadly speaking. Debugging is to find and correct system (including hardware and software) errors. Performance problems are bugs, so debugging will also include performance optimization, that is, improving performance by solving processing bottlenecks.

Failure analysis:
When a process fails, most operating systems write error information to a log file to remind the operator or user of the problem. The operating system will also perform core dumps, that is, capture the process memory and save it to a file for later analysis, so that the programmer can analyze the code and memory of the process.
Kernel failures are called crashes. When a crash occurs, the error information will be saved to a log file, and the memory state will be saved to a crash dump.

Performance optimization:
Performance optimization is to improve performance by eliminating processing bottlenecks. In order to find bottlenecks, we must be able to monitor system performance. Therefore, the operating system should have some means to calculate and display metrics of system behavior. Several operating systems do this by generating a list of system behavior tracking. All related events and their events and other important parameters are recorded and written to a file. After that, the log file can be processed by an analysis program to determine system performance and identify bottlenecks and inefficiencies. Such tracking can be used as input to simulate the proposed system for improvement. Tracking helps find errors in operating system behavior.

Another solution for performance optimization is to use dedicated interactive tools so that users and administrators can check the status of various system components to find system behavior errors.

Operating system generation

The process of loading the kernel to start the computer is called system boot. Most computer systems have a small piece of code called a boot program or boot loader. The interrupt code can locate the kernel and load it into memory to begin execution. Some computer systems use two steps: a simple boot program loads a more complex boot program from the disk, and the latter loads the kernel.

When the CPU receives a reset event, such as power-on or restart, the instruction register will load a predefined memory location and start execution from that location. This location is where the initial boot program is located. The output is in the form of read-only memory (ROM) because the RAM is in an unknown state when the system is started. Because it does not need to be initialized and is not affected by computer viruses, it is very convenient to use ROM.

Some systems, such as mobile phones, tablet computers, and game controllers, store the entire operating system in ROM. For a small operating system, simple supporting hardware, and durable operation, it is appropriate to store the operating system in ROM. This method has a problem: changing the bootloader code requires changing the ROM chip. To solve this problem, some systems use erasable programmable read-only memory, which is a read-only memory, but it becomes writable when a command is explicitly given.

For large operating systems or systems that change frequently, the boot program is stored in the firmware, and the operating system is stored on the disk. In this case, the boot program will first perform a diagnosis, then read the entire block of information from a fixed location on the disk (such as block 0) to the memory, and finally execute the code of the boot block. The program stored in the boot block may be enough to value the entire operating system into memory and begin execution. A disk with a boot partition is called a boot disk or system disk.

Guess you like

Origin blog.csdn.net/weixin_45715461/article/details/114759946