[Soft Exam - Notes on Essential Knowledge Points for Software Designers] Chapter 4 Operating System Knowledge

Preface

Since the notes copied to CSDN have invalid styles, I don’t have the energy to completely check and set the styles again. Those with points can download the word, pdf, and Youdao cloud note versions.
It should be noted that the downloaded content is consistent with the content shared in this article. The only difference is the style [for example, the key memory and frequently tested content have colors, font sizes, weights, etc., and the directory structure is more complete. Tables are not pictures, etc.]

Download address of this chapter:
https://download.csdn.net/download/chengsw1993/85518919

If you find that the article has reading differences, abnormal display, etc., please let us know in the comment area so that we can modify it. This should be caused by CSDN's markdown syntax.

Series of articles
Previous article:[Soft Exam - Notes on Essential Knowledge Points for Software Designers] Chapter 3 Data Structure

Next article:[Soft Exam - Notes on Essential Knowledge Points for Software Designers] Chapter 5 Basic Knowledge of Software Engineering

Process management

Operating system overview

The role of the operating system: improve the efficiency of the computer system through resource management; improve the human-machine interface to provide users with a friendly working environment.

Characteristics of operating systems: concurrency, sharing, virtuality, and uncertainty.

Functions of the operating system: process management, storage management, file management, device management, and job management.

Categories: Batch operating system, time-sharing operating system (using CPU work slices in turn), real-time operating system (quick response), network operating system, distributed operating system, microcomputer operating system (Windows), embedded operating system

Basic computer startup process: BIOS → Master Boot Record → Operating System

process

Composition: process control block PCB (unique identification), program (describing what the process is going to do), data (storing the data required when the process is executed)

Status: ready, running, waiting

Precursor graph

The predecessor graph can determine two points: the parallel relationship between tasks and the sequence between tasks.

Process resource graph

Process resource graph: used to represent the allocation and request relationships between processes and resources, as shown in the figure below
Insert image description here

P represents process, R represents resource. The number of circles in the R box indicates how many resources there are. For example, in this picture, R1 points to P1, which means that R1 has a resource that has been allocated to P1, and P1 points to R2, which means that P1 still has Need to request an R2 resource to execute.

  • Blocked nodes (check whether all required resources have been allocated): All resources requested by a process have been allocated and cannot be obtained. The process is blocked and cannot continue. As shown in the figure P2;
  • Non-blocking node: The resources requested by a process are still remaining and can be allocated to the process to continue running. As shown in P1 and P3 in the figure;
    When all processes in a process resource graph are blocking nodes, it will fall into a deadlock state.

Synchronization and mutual exclusion

Mutually exclusive: it can only be used by one task at a time, lock it, and release it after use, such as a printer;

Synchronization: multiple tasks can be executed concurrently

Critical resources: resources that need to be accessed in a mutually exclusive manner between processes

Critical section: refers to the code in the process that operates on critical resources, such as synchronized code

Mutually exclusive semaphore: initial value is 1

Synchronization semaphore: The initial value is generally the number of shared resources

Semaphore operations

P ​​operation: Apply for resources, S=S-1 [S>=0 indicates the number of available resources, S<0 indicates waiting for resources], if S>=0, the process of performing P operation continues Execute; if S<0, the process is blocked and inserted into the blocking queue;
V operation: Release resources, S=S+1, if S>0, it means that there are currently resources available , then the process that performs the V operation continues to execute; if S<=0, it means that there is currently a blocked process, wake up a process from the blocking queue, insert it into the ready queue, and then the process that performs the V operation continues.
As shown below: complete the operation first and then judge.
Insert image description here
Insert image description here
Insert image description here
Insert image description here

deadlock

A deadlock occurs when a process waits for an event that never occurs. If there are multiple processes in the system that are in a deadlock state, it will cause a system deadlock.

Four necessary conditions:

  • Mutually exclusive resources
  • Each process owns resources and waits for other resources
  • The system cannot deprive a process of resources
  • The process resource graph is a cycle

Solution: To break the four conditions, there are the following methods:

  • Deadlock prevention: Use a certain strategy to limit the requests for resources by concurrent processes so that the system does not meet deadlock conditions at any time.
  • Deadlock avoidance: Banker's algorithm is generally used to calculate a resource allocation plan that will not deadlock in advance, and then allocate resources
  • Deadlock detection: Deadlocks are allowed to occur, but the system regularly runs a program to detect deadlocks. If a deadlock is detected, it will be deleted.
  • Deadlock relief: methods to relieve deadlock after occurrence, such as forcibly depriving resources, canceling processes, etc.

Deadlock calculation problem: There are n processes, each process requires R resources, then

  • The maximum number of resources where deadlock occurs is n*(R-1). Every process is missing exactly one
  • The minimum number of resources that does not cause deadlock is n*(R-1) +1. One more resource. A certain process has exactly reached R resources and completed the execution to release the resources.

thread

A traditional process has two attributes: an independent unit that can own resources; a basic unit that can be independently scheduled and allocated.
After the introduction of threads, threads are the smallest unit of independent scheduling, and processes are the smallest units of resources

Storage management

Page storage management

Divide the process space into pages. Assume that the size of each page is 4K. Similarly, the physical space of the system is also divided into physical blocks (page frame numbers) of 4K size. In this way, each logical page that needs to be run will be Load it into a physical block, and then load other pages that need to be run after running. You can run the process in batches without loading the entire logical space into physical memory.
Insert image description here

Advantages: high utilization, small fragmentation (only in the last page), simple allocation and management

Disadvantages: increased system overhead, possible jitter

Insert image description here

Analysis: Consider the conversion of logical address and physical address. The representation of page storage: high bit [page number] + low bit [intra-page address/intra-page offset]. The address within the page will not change, whether it is a physical address or a logical address, only the page number will change according to the mapping. The in-page address is the page size.

4K=4*1024=2^12=(2^4)^3, representing 3 digits in hexadecimal. Therefore, D16H represents the address within the page, 1 represents the page number, and its corresponding physical block number is 3, so the physical address is 3D16H

Page replacement algorithm

Sometimes, the process space is divided into 100 pages, and the system memory only has 10 physical blocks, which cannot all be allocated. It is necessary to allocate the pages that are about to be executed first, and then eliminate them according to the algorithm so that the 100 pages can be executed as scheduled. The sequence is transferred into the physical block and executed.

A missing page means that the page that needs to be executed is not in the physical block of memory and needs to be transferred into the memory from the outside, which will increase the execution time. Therefore, the more missing pages, the lower the system efficiency.

  • Optimal algorithm: OPT is a theoretical algorithm that cannot be implemented. It is the best efficiency calculation performed after the process is executed to compare the gap with other algorithms. The principle is to select and replace pages that will not be accessed for the longest time in the future, so as to ensure that all future executions will be accessed immediately.
  • First-in, first-out algorithm: FIFO, the pages that are transferred into the memory first are replaced and eliminated first, which will cause jitter. That is, the more pages allocated, the higher the page fault rate may be (that is, the lower the efficiency)
  • Least recently used: LRU. In the recent past, during process execution, the least used pages in the past are replaced and eliminated. According to the principle of locality, this method is highly efficient and does not produce jitter.

Fast watch

The fast table is a small-capacity associative memory, which is composed of fast memory. It is accessed by content and is fast. The hardware can guarantee parallel searches by content. It is generally used to store the page numbers of the few most frequently active pages.

The fast table is stored in the Cache, and the slow table stores the page table in the memory. Therefore, the slow table needs to access the memory twice to fetch the page, while the fast table needs to access the cache once and the memory once.

Fast tables are essentially page tables, which represent the correspondence between logical page numbers and physical block numbers.

Segmented storage management

The process space is divided into segments. Each segment is composed of segment number + segment address. Different from page storage, each segment has a different physical size. The segmented storage is segmented according to the logical whole.

The address represents: segment number + address within the segment (offset within the segment). The address within the segment cannot exceed the segment length corresponding to the segment number, otherwise an out-of-bounds error occurs; and the memory address corresponding to this address is: the base address corresponding to the segment number + within the segment address

Segment table: segment length + base address,

For example, in the first picture below, the memory space is the physical address starting from 40K to 70K
Insert image description here

Advantages: The program logic is complete, and modifications do not affect each other
Disadvantages: low memory utilization, large waste of memory fragmentation

Segmented page storage management

Combine the two, segment the process space first, and then page it
Advantages: little space waste, easy storage sharing, and can be dynamically connected
Disadvantages : Increased complexity and overhead, slowed execution

File management

File structure

The index file structure used in the computer system is shown in the figure below:
Insert image description here

There are 13 index nodes in the system, 0-9 are direct indexes, that is, each index node stores content. Assuming that the size of each physical disk is 4KB, 4KB*10=40KB data can be stored;

Index node No. 10 is a first-level indirect index node with a size of 4KB. It does not store data directly, but is linked to the address of a direct physical disk block. Assuming that each address occupies 4B, there are a total of 4KB/4B = 1024 addresses that can be stored. 1024*4KB=4MB data;

No. 11 is the second-level index node, which stores the first-level node address. The first-level node stores the physical disk block address and then links to the physical disk block. The capacity is expanded by one order of magnitude, 102410244KB data;

No. 12 is a three-level indirect index, with another layer of nesting, 102410241024*4KB data.

tree file directory

Relative path: the file path starting from the current directory
Absolute path: the path starting from the root directory
Full file name: absolute path + file name
The tree structure is mainly used to distinguish between relative paths and absolute paths
Insert image description here

Free storage space management

Free area table method: integrate all free space into one table, that is, free file directory
Free linked list method: link all free space into a linked list and allocate as needed a>
Group linking method: grouping, linking into linked lists within each group, combining the two
Bitmap method: marking each physical space with one bit, If it is 1, it is used, and if it is 0, it is idle, forming a bitmap.

Device management

Equipment classification:

Classified by data organization: block device, character device.
Resource allocation perspective classification: exclusive devices, shared devices and virtual devices.
Data transmission rate classification: low-speed equipment, medium-speed equipment, high-speed equipment.

I/O software hierarchy:
Insert image description here

Input and output technology

  • Program control (query) method: The CPU actively queries whether the peripheral device has completed data transmission, which is extremely inefficient. CPU serial

  • Program interrupt method: After the peripheral completes the data transmission, it sends an interrupt to the CPU and waits for the CPU to process the data, which is relatively efficient. Suitable for scenarios with high real-time performance such as keyboards. CPU parallelism

    • Interrupt response time refers to the time from when the interrupt request is issued and the interrupt handler is entered.
    • Interrupt processing time refers to the time from the start of interrupt processing to the end of interrupt processing
    • The interrupt vector provides the entry address of the terminal service program.
    • Multi-level interrupt nesting, using stacks to protect breakpoints and contexts.
  • DMA mode (direct main memory access): The CPU only needs to complete necessary initialization and other operations, and the entire process of data transmission is completed by the DMA controller. A direct data path is established between the main memory and peripherals, which is very efficient. . Suitable for high-speed devices such as hard disks. CPU parallelism

CPU time occupied: Program Query>Interrupt>DMA>Channel>I/O Processor

After the end of a bus cycle, the CPU will respond to the DMA request and start reading data; the CPU responds to the program interrupt mode request at the end of an instruction execution; distinguish between the end of instruction execution and the end of the bus cycle.

Real question: (2017 Question 7) During the operation of the computer, the CPU needs to exchange data with peripherals. When using (interrupt mode and DMA mode) control technology, the CPU and peripherals can work in parallel

Virtual devices and SPOOLING technology

SPOOLING technology is to establish two data buffers (input well, output well) on the peripheral, so that no matter how many processes can share this printer, you only need to issue the print command, and the data will be queued and stored in the buffer. The printer will automatically print in sequence, realizing the sharing of physical peripherals and making each process feel like it is using a printer. This is the virtualization of physical devices.
Insert image description here

disk structure

The disk has two disk surfaces, and each disk surface has multiple concentric circles. One circle is a track. The track is divided into multiple sectors, and data is stored in the sectors.

When reading data, first find the corresponding track and wait until the disk rotates to the specified sector before it can be read. Therefore, there is seek time (the time required for the head to move to the track) and waiting time (waiting for reading and writing). The time it takes for the sector to turn under the disk head), the seek time is the longest
Seek time scheduling algorithm:

First come, first served FCFS: According to the process request order
Shortest seek time first SSTF: The process requesting access to the track closest to the current track is scheduled first. Problem: "Hungry phenomenon", remote processes may never be accessible
Scanning algorithm SCAN [elevator algorithm]: the head moves in both directions on the disk, and selects the request for access closest to the current position of the head track, and is consistent with the movement direction of the magnetic head. The magnetic head always moves inside → outside or outside → inside before turning around
Single scan scheduling algorithm CSCAN: When different from SCAN, only a single move is made , it can only go in one direction: inside → outside or outside → inside.

microkernel operating system

Only the most core and necessary things are put into the kernel, and other things that can be independent are put into the user process. User mode and core mode
Insert image description here

embedded operating system

Features of embedded operating systems: miniaturization, high code quality, specialization, strong real-time performance, tailorability and configurability.

Kernel services for real-time embedded operating systems: exceptions and interrupts, timers, I/O management.

Common embedded RTOS (real-time operating system): VxWorks, RT-Linux, QNX, pSOS.

The embedded system initialization process is in the order of bottom-up, from hardware to software:
Chip-level initialization->Board-level initialization->System initialization.

The chip level is the initialization of the microprocessor, the board level is the initialization of other hardware devices, and the system level initialization is the initialization of the software and operating system.

Guess you like

Origin blog.csdn.net/chengsw1993/article/details/125067956