Modern Operating Systems 4 Edition Solution
Since I bought the book "Modern Operating System", I should study it. This is the first reading note.
Chapter 1 Introduction
Computer systems are generally divided into software and hardware, as shown in the following figure. Most computers have two modes of operation:Kernel state and user mode。The most basic part of the software is the operating system., it runs in kernel mode. The operating system has full access to all hardware and can execute any instructions that the machine can run. Other software runs in user mode and can only use some machine instructions. In particular, instructions that affect extreme control or I/O operations are prohibited in the user mode. If you cannot run the instructions directly, you can only achieve the purpose through the interface provided by the operating system.
Original address "Modern Operating System (Chinese Fourth Edition)" Notes Chapter 1 Introduction
The operating system is protected by hardware to prevent users from trying to modify it.
Everyone has operated Windows, Linux and other operating systems. Is this the operating system? These programs that interact with the user are not actually part of the operating system. They use the operating system to complete the work. The icon-based graphical user interface (GUI) is the kind of Windows we use. See various icons; text-based is often called a shell, such as we use the cmd command in Windows, or Xshell and other software programs in Ubuntu.
However, in embedded systems (without kernel mode) or interpretation systems (such as Java-based operating systems, which use interpreted methods rather than hardware to distinguish components), the boundaries of the above partitions are rather vague.
1.1 What is the operating system?
The operating system is a kind of software that runs in kernel mode, but this statement is not always true, but the operating system has two main functions:
- 1. Provide a clear abstraction of the resource set for the application (programmer)
- 2. Manage hardware resources
The second point is to understand. The first point is to use the vernacular to provide the corresponding interface or method to the upper layer, so that the upper application can use the resource.
In addition, the understanding of the operating system, from different perspectives, has different definitions.
Top-down: The operating system provides a basic abstraction for the application so that the application can combine functions on top of it.
From the bottom up: the operating system is used to manage the various parts of the complex system, allocate requests for resources, and adjust different programs to see conflicting resource requests. Among them, resource management has two different ways to implement multiplexing (sharing) resources:Temporal multiplexing and spatial multiplexing:
- Time multiplexing: When a resource is reused in time, it is used by different programs or users in turn, and everyone queues for use. The CPU is this kind of operation, a position, everyone takes turns sitting
- Spatial reuse: Each program gets a part of the resource, there is no need to queue, this is multiple locations, one person sits. The memory is allocated like this.
- Two ways of fairness and protection issues, solved by the operating system
1.2 History of the operating system
First generation: vacuum tube and punch card
Second generation: transistors and batch systems
Third generation: small-scale integrated circuits and multi-program design
Fourth generation: personal computer (large scale integrated circuit)
The fifth generation: mobile computers (mobile phones, tablets, etc.)
1.3 Introduction to Computer Hardware
1.3.1 processor
First, all devices are connected via bus:
Equivalent to the computer's brain, taking instructions from memory and executing them. Each CPU has a set of executable instruction sets. So x86 can't execute ARM program, ARM processor can't execute x86 program.
There are some general-purpose registers inside the CPU for saving key variables and temporary data, as well as some special registers such as program counter (PC), stack pointer register (pointing to the top position of the current memory), and program status word register (Program Status). Word, PSW, contains control bits such as condition code bits, CPU priority, kernel mode/user mode).
The mechanism for executing the CPU fetch instruction is completed by the internal fetch unit, the decoding unit, and the execution unit. In order to improve efficiency. Now the CPU can usually take multiple instructions at the same time. When the CPU executes the instruction n, it can decode the instruction n+1 and read the instruction n+2, so that when the instruction n is executed, without waiting, n+1 and then n+2 can be directly executed. Such a mechanism is calledassembly line(pipeline)
Different CPU designs for intel and AMD:
1.3.2 Memory
A typical storage hierarchy and its approximate access time are as follows:
The top layer of the storage system is the register in the CPU. It is made of the same material as the CPU, as fast as the CPU, and there is no delay in access. Typical storage capacity: 32x32 bits for 32-bit CPUs and 64x64 bits for 64-bit CPUs
The next level is the cache. When the CPU reads the data, if the data is in the cache line, it becomesCache hit. Improving cache hits helps improve efficiency.
1.3.3 disk
Compared with RAM, the cost of each bit is two orders of magnitude lower than that of RAM, so the capacity is large and cheap, but the reading speed is low.
The following figure shows the common mechanical hard disk structure:
There are one or more metal discs in a disk. Data can be recorded on both sides of a disc. Each side is divided into many concentric circles. A concentric circle is divided into a number of areas, typical of each sector. The size is 512 bytes. Then, as shown, each disk is divided into a number of cylinders (or fans).
Each disk has a read/write head for reading and writing data. It takes about 1 ms for the arm to move from one cylinder to the adjacent cylinder, and a typical time of random movement to a cylinder is 5-10 ms.
Original address
1.3.4 I/O Equipment:
I/O devices are input and output devices, such as keyboards, mice, printers, and hard disk lights. I/O devices generally consist of two parts: the device controller and the i/o device itself. The controller is a piece or group of chips that are plugged into the board.
Each type of device controller is different, requires different software to control, specifically talks with the controller, issues commands and receives response software, called device driver.
There are three ways to implement input and output.The firstThe user program issues a system call and then executes the I/O process. The CPU waits for I/O data until it gets the data and processes it. After processing, it returns the result and the CPU continues to process other things. This method is called busy waiting.
SecondIs throughInterrupt mechanismWhen I/O is needed, let the I/O device perform the corresponding operation first. At this time, the CPU does not need to wait and continue to do other things. If the I/O is executed, the data is obtained. At this time, the interrupt controller starts the CPU. An interrupt that processes the data obtained by this I/O. The vernacular is to let the CPU handle other things first. When I get the I/O data, tell the CPU that you should stop what you are doing now. The data you just want is ready. Now give it to you.
ThirdDirect memory access chip (DMA, Direct Memory Access) is used to directly control the bit stream. When the DMA obtains data, it also initiates an interrupt to the CPU.
1.3.5 bus
The bus is the line where the CPU is connected to other devices, and the data transfer between various devices is done through the bus. The sample diagram at the beginning has already been shown, and now I will return the general example diagram:
1.3.6 Starting the computer (the process)
After power-on, the system first starts the program inside the BIOS, the full name of the BIOS.Basic Input Output SystemThe internal contains the basic parameter settings, and the program to be started next, to start the system.
1.4 Operating System Grand View Garden (various operating systems)
There are many operating systems, mainly: mainframe operating system, server operating system, multiprocessor operating system, personal computer operating system, handheld computer operating system, embedded operating system, sensor node operating system, real-time operating system, smart card operating system. .
1.5 Operating System Concept
There are many basic concepts and abstractions in the operating system. They are the core content that needs to be understood, mainly: process, address space, file, I/O (input and output), protection, shell.
1.5.1 Process
Process: The essence of a process is a program that is being executed. It can be easily understood that a process is a program, but sometimes a program contains multiple processes. A process is an abstraction of the CPU processor. It can be thought of as a collection of resource schedules. The resources typically include: registers (program counters and stack pointers), lists of open files, prominent alarms, and lists of processes. And other information needed by the program.
1.5.2 Address Space
The main memory of the computer is used to save the program being executed. In order to find the location of the program in the main memory (that is, the memory), the physical memory sets the corresponding address number, and a set of address numbers is the address space. The physical address space is limited, which is determined by the device, but with virtual address space technology. The concept of address space is actually an abstraction of memory used to facilitate the management of memory and processes.
1.5.3 file
The abstraction of the concept of a file is to describe a collection of data, which is better understood. In reality, files are actually bound together, and some of these data are usually saved (text, charts, etc.).
1.5.4 I/O (input and output)
Mainly refers to input and output devices through which to input or output data, such as keyboards, printers, etc. Enter letters on the keyboard to output text on your hard drive or other location.
1.5.5 Protection
The computer has a lot of information that users want to protect. For a file, there are usually three states, readable (read only, not modifiable), writable (can only be written, not readable), readable and writable.
1.6 system call
First, let's briefly understand the process of the system call. The following figure is the process of calling a read method:
Then there are some commonly used calling functions:
1.7 Operating System Structure
1.7.1 Monolithic system
The entire operating system runs as a single program, with all processes linked into one large executable binary
1.7.2 Hierarchical system
The whole system is divided into many layers, each layer is encapsulated, and then called to the previous level, so that some restrictions can be added for protection.
1.8 Relying on the world of C
Operating systems are usually written in C (or C++).
Visit the original "Modern Operating System (Chinese Fourth Edition)" Notes Chapter 1 Introduction
Modern Operating Systems 4 Edition Solution
Source: https://www.programmersought.com/article/47861481318/