Summary of operating system knowledge points (overview + architecture + process management)

Summary of operating system knowledge points

Article Directory

overview section

what is an operating system

Resource allocator, control program, kernel program, core system software.

A program that manages computer hardware, also provides the foundation for application programs, and acts as an intermediary between computer hardware and the computer user.

The operating system is a resource manager, the operating system is a virtual machine, and the operating system is a collection of system software . ( Note that it is not a collection of many software ).

Operating System Design Goals

To provide users with an environment in which programs can be executed conveniently and efficiently.

Convenience (upward service), effectiveness (downward management).

What are the parts of an operating system

The composition includes process management, main memory management, auxiliary memory management, I/O management, file management, protection system, networking, and command interpretation system.

insert image description here

What problem does each part mainly solve

  • Process management (CPU management): create and delete processes, suspend (suspend) and continue processes, process synchronization mechanism, process communication mechanism, deadlock handling mechanism.

  • Memory management (precious resources, small capacity): record which part of memory is being used and by whom; when memory space is available, decide which processes can be loaded into memory; allocate and release memory space as needed.

  • Auxiliary storage management: The internal memory is too small to accommodate all data and programs, and data will be lost after power failure, so the computer must provide secondary storage to back up the internal memory. Disks are used as the main online storage medium to store programs and data. The OS is responsible for hard disk management related activities: free space management, storage space allocation, hard disk scheduling.

  • I/O management: including buffers, caches and other parts. Drivers for specific hardware devices.

  • File management: create and delete files, create and delete directories, provide primitives for operating files and directories, map files to secondary storage (auxiliary storage), and back up files on stable (non-volatile) storage media.

  • Protection system: Distinguish between authorized and unauthorized use, provide a method to specify all controls to be carried out, and provide methods to enforce controls.

  • Networking (distributed system): Processors are connected through a communication network, and both parties use the same protocol. access to shared resources

Operating system kernel technology development

Simple Structure - Layered Approach - Microkernel Structure

Single Structure - Core Hierarchy - Microkernel Structure

Microkernel : A carefully designed small kernel that implements the core functionality of a modern OS.

It is not a complete operating system, but only provides the basis for building a general-purpose OS. Provide some basic functions, such as process management, memory management, inter-process communication, low-level I/O functions, etc. Move all non-essential parts out of the kernel and implement them as system programs or user programs.

The difference between concurrency and parallelism

  • Concurrency: Handing tasks to processors at different points in time for processing. At the same point in time, tasks do not run concurrently.
  • Parallelism: Assign each task to each processor to complete independently. At the same point in time, the tasks must be running concurrently.

Concurrency is not parallelism. Parallelism is the simultaneous execution of different pieces of code on different physical processors. The key to parallelism is to do many things at the same time, and concurrency refers to managing many things at the same time. These things may be suspended to do other things after only half of them are done.

Parallel "simultaneously" means that multiple processes can be running (running) at the same time. Concurrent "simultaneously" means that through rapid context switching, it seems that multiple processes are running at the same time. It is a kind of OS to deceive users. phenomenon .

In many cases, the effect of concurrency is better than parallelism, because the total resources of the operating system and hardware are generally small, but it can support the system to do many things at the same time.

Operating system development stage

  • batch stage

    • Simple Batch: Problem: Slow Performance Solved: Multiprogrammed Batch Systems

    • Multi-program batch processing system: CPU and equipment, equipment and equipment can be used in parallel, the utilization rate of system resources is improved, and the throughput is increased.

      Problem: Improved resource utilization, but lack of human-computer interaction Solved: Time-sharing system

  • Time-sharing system: the granularity of tasks executed becomes smaller, and the frequency of switching between tasks is faster ( emphasis on interactivity )

  • Time-sharing CPU

  • PC system: increase file management

  • parallel system

  • real time system

Relationship Between Jobs and Processes

  • Job: usually refers to the collection of work that the user requires the computer system to do during a calculation process or a transaction process, including user programs, required data, and commands.
  • Process: It is the running process of a program with independent functions that can be executed concurrently on a data set, and is an independent unit for the system to allocate and schedule resources.

The difference and connection between jobs and processes are as follows:

1. A job is a task entity submitted by a user to a computer, while a process is an execution entity that completes a user task, and is the basic unit that applies to the operating system for resource allocation.

2. A job can consist of multiple processes, and a job consists of at least one process.

3. The concept of jobs is mainly used in batch processing systems, while the concept of processes is used in all multiprogramming systems.

The tasks performed by the time-sharing system are usually called processes/threads, and the tasks in multi-channel are often relatively large in granularity, which may be called jobs.

architecture part

Hardware platform:

I/O mode:

  1. Synchronous I/O: After the I/O is started, control is returned to the user process only when the I/O is complete. Causes the CPU to wait in an idle loop until the next interrupt begins; at most one I/O request can be processed at any one time.
  2. Asynchronous I/O: After I/O is started, control can be returned to the user process without waiting for the completion of the I/O operation

I/O technology (control mode) ( fill in the blank !!):

  • Programmable I/O
  • interrupt mechanism
  • Direct Memory Access (DMA)
  • Channel technology (aka I/O processor)

Software system:

Microkernel Architecture: A carefully designed small kernel that implements the core functions of a modern OS.

Process management section

Why introduce the process

Modern computer systems allow multiple programs to be loaded into memory for concurrent execution. This requirement provides stricter control and better division of various programs, and these requirements give rise to the concept of a process.

Why introduce threads

Process has two basic characteristics:

  • Independent Unit of Resource Allocation

  • basic unit of scheduling

Separate process resource allocation and scheduling, and introduce threads.

Distinguish and compare processes and threads in terms of scheduling, concurrency, owned resources, and system overhead

  • Scheduling. In the traditional OS, the basic unit of owning resources and the basic unit of independent scheduling and dispatching are processes. In the OS that introduces threads, threads are regarded as the basic unit of scheduling and dispatching, and processes are regarded as the basic unit of resource ownership.
  • concurrency. Processes can execute concurrently, and multiple threads of a process can also execute concurrently.
  • own resources. A process is always the basic unit that owns resources. A thread only owns essential resources at runtime, and basically does not own system resources, but can access resources belonging to a process.
  • System overhead. The operating system pays significantly more overhead than threads when creating, destroying, and switching processes.

Process Status (Test!!)

  • new status
  • Operating status
  • Wait state (blocking, pending)
  • ready state
  • terminated state

insert image description here

①Mainly do two things: 1) Select a process from the ready queue. 2) Context switching (smaller PCBs switch faster, too small and less information)

③, ④ are one-way, ③, ④ may cause scheduling

insert image description here

example:

insert image description here

3->1: Possible. The current process is blocked, making the CPU idle, and the scheduler will pick one of the processes in the ready state to run.

3->2: Impossible. A process occupying the CPU cannot enter two states at the same time.

2->1: Possible: the priority of the current running process drops or the time slice is used up, and the scheduler selects a process with the highest priority to occupy the processor.

4->1: Possible. When the processor is idle and the ready queue is empty, transition 4 of a process causes transition 1 of that process.

process composition

program+data+PCB+···

  • PCB

  • program

  • data segment

  • stack segment

Process Control Block (PCB)

PCB

is the only indication that the process exists

PCB table

1. The system organizes all PCBs together and puts them in the fixed area of ​​memory to form the PCB table

  • linked list
  • direction chart

2. The size of the PCB table determines the maximum number of processes that can exist in the system at the same time, which is called the concurrency of the system

relationship between processes

A synchronization or mutual exclusion relationship may exist between any two concurrent processes .

process synchronization

  • It refers to the constraint relationship between the partner processes that complete the same task, because they need to coordinate their work in some positions and wait for each other and exchange information with each other.

  • It can also be said to be a direct constraint caused by concurrent processes sharing each other's private resources .

process mutual exclusion

  • The indirect constraint relationship caused by the competition and sharing of common resources between processes is called mutual exclusion.

  • Indirect means: the speed of each concurrent process is constrained by public resources, rather than directly constrained by processes.

critical section

critical resource

Some resources in the system are only allowed to be used by one process at a time. Such resources are called critical resources or mutually exclusive resources.

critical section

A program segment involving critical resources in a process is called a critical section. Each process has a section of code called a critical section .

Principles of use:

  • let in
  • No time to wait
  • choose one
  • Bounded waiting: From the time a process makes a request to enter a critical section until the request is granted, there is an upper limit to the number of times other processes are allowed to enter its critical section.
  • Give up the right to wait: The process in the waiting state should give up occupying the CPU so that other processes have the opportunity to get the right to use the CPU.

Solution:

  • Software method: check and set some flags in the entry area; if the existing process is in the critical area, wait through the loop check in the entry area; modify the flags in the exit area.

    • Key questions: what flag to set and how to check it .

    • Disadvantages: busy waiting; the implementation is too complex and requires superb programming skills

  • Hardware method: Test-and-Set command, Swap command, switch interrupt command.

amount of signal

meaning

The semaphore represents the entity of the resource and is an integer variable related to the queue.

  • Semaphores can only be accessed through initialization and P/V primitives ;
  • Processes that access semaphores are not interrupted by process scheduling.

Physical meaning:

  • S>0: Indicates that S resources are available

  • S=0: means no resources are available

  • S<0: Indicates the number of processes in the S waiting queue

How to define the initial value of the semaphore

If it is a mutual exclusion (binary) semaphore, the initial value is generally fixed at 1.
If it is a resource (counting) semaphore, it depends on the number of resources and how much the initial value is.

The meaning of P/V operation

The two operations defined on the semaphore are an effective process synchronization mechanism.

P primitives P(S)

  1. S=S-1
  2. If S>=0, the process calling P(S) continues to run
  3. If S<0, the process calling P(S) is blocked and inserted into the blocking queue waiting for semaphore S

Executing the P operation means requesting the allocation of one unit of resources.

V primitive V(S)

  1. S=S+1
  2. If S>0, the process calling V(S) continues to run
  3. If S<=0, wake up the first process from the blocking queue waiting for semaphore S to the ready queue, and then the process calling V(S) continues to run.

Performing a V operation means freeing one unit of resources.

How to use P/V operation to realize synchronization and mutual exclusion between multiple processes?

Implement process mutual exclusion

  • Set a mutual exclusion semaphore mutex for critical resources, the initial value is 1;
  • In each process, place the critical section code between the P(mutex) and V(mutex) primitives.
    insert image description here

insert image description here

When n processes start, S=1, the smallest possible S=1-n.

Realize process synchronization

For the predecessor relationship, a synchronization semaphore S12 is set for each predecessor relationship, and its initial value is 0.

insert image description here

P2 executes C2 only after P1 executes C1.

insert image description here

Typical Synchronization Problems

producer consumer problem

Several processes exchange data through a limited shared buffer; there are N shared buffers; only one process can operate on the shared buffer at any time.

insert image description here

full is the "full" number, the initial value is 0; empty is the "empty" number, the initial value is N. mutex is used for mutual exclusion when accessing the buffer, and the initial value is 1. The producer produces full buffer items for the consumer, and the consumer produces empty buffer items for the producer.

insert image description here

reader writer problem

dining philosophers problem

process communication

Advanced communication methods:

  • shared memory system

  • Messaging system: The broadest communication mechanism.

    • Direct communication: such as message buffer communication.

    • insert image description here

    • Indirect communication: such as mailbox communication.

    insert image description here

    insert image description here

  • Pipeline Communication Mode·

CPU scheduling

What are the events that cause process scheduling

  • When a process switches from the running state to the waiting state

  • When a process switches from the running state to the ready state

  • When a process switches from the waiting state to the ready state

  • When a process terminates.

What are the commonly used scheduling algorithms

  • First Come First Serve Scheduling (FCFS)
  • Shortest Job First (SJF): For a given set of processes, the average waiting time is the smallest
    • non-preemptive
    • Preemptive: shortest remaining time job first (SRTF)
  • Priority scheduling algorithm (SJF is a specific priority scheduling method): may cause starvation problems (solution: aging)
  • RR round-robin scheduling algorithm:
    • Turnaround time is greater than SJF algorithm
    • Response time is better than SJF algorithm
  • Multilevel Feedback Queue Scheduling Algorithm

Analysis of Multilevel Feedback Queue Scheduling Algorithm

insert image description here

insert image description here

deadlock

What are the four characteristics that cause a deadlock

  • Mutual exclusion: at least one resource must be in mutual exclusion mode: that is, only one process can use it at a time. If another resource requests the resource, the request process must be delayed until the resource is released.
  • Hold and wait: A process must hold at least one resource and wait for another resource, which is held by another process.
  • Non-preemptive: resources cannot be preempted: that is, resources are released only after the process completes its tasks.
  • Circular waiting: process {P0, P1, ..., Pn}, the resource waiting for P0 is occupied by P1, the resource waiting for P1 is occupied by P2, the resource waiting for Pn-1 is occupied by Pn, and the resource waiting for Pn is occupied by P0 .

If the above four conditions are met at the same time, a deadlock will occur.

How to overcome deadlock for these four characteristics

Deadlock prevention : When there are four necessary conditions for deadlock, as long as at least one of the necessary conditions is not satisfied, deadlock can be prevented.

Possible problems:

  • Mutual exclusion: Deadlocks cannot usually be prevented by mutual exclusion conditions, and some resources themselves are not shared.
  • Hold and wait: Resource utilization may be low and starvation may occur.

Deadlock avoidance :

  • Avoid deadlocks by adding information about resource allocation requests.

  • The simplest and most effective model requires each process to declare in advance the maximum amount of each resource it needs;

  • The deadlock avoidance algorithm dynamically checks the resource allocation status to ensure that there is no circular waiting condition.

  • The resource allocation status is defined by the number of available resources, the number of allocated resources, and the maximum number of applications for a process.

deadlock detection

Deadlock recovery : Manually handle deadlocks, allowing the system to automatically recover from deadlocks.

There are two ways to break out of a deadlock state:

  • Terminate process method: simply terminate one or more processes to break the circular wait;

  • Resource preemption method: preempt one or more resources from one or more deadlocked processes.

The method of resource allocation diagram to determine deadlock

  • If the graph contains no cycles, there is no deadlock

  • If the graph contains cycles, then:

    • Deadlock if there is only one instance of each resource type
    • Deadlock is only possible if several instances of each resource type exist.

insert image description here

Guess you like

Origin blog.csdn.net/m0_61443432/article/details/131608493