[Operating system] 02. Process management

multiprogramming system

Multi-programming is to load multiple programs into memory at the same time so that they can run concurrently. The operating system is also generated based on multiple channels, which improves resource utilization and system throughput.

process

definition

A process is an execution of a program. A
process is the running process of a process entity. It is an independent unit for the system to allocate and schedule resources.

After the thread is introduced, the thread becomes the basic unit of scheduling, and the process is still the basic unit of resource allocation.

Composition of Process Entities

Program: is a combination of a set of instructions

Process: It is an execution process of a program and an independent unit for resource allocation and scheduling by the system

Process entity: During one execution of the program, three parts, program block, data block, and program control block, will be generated in the memory. These three parts constitute the process entity, also known as the process image.

image.png

program block

Also commonly referred to as a code segment.
The code segment is the location of the program instructions of the process in memory, including the set of instructions that need to be executed;

data block

It is the location of the operation data of the process in memory, including the data set that needs to be operated

Program Control Block PCB

(Program Control Block, PCB)
contains the description information and control information of the process, and is the only sign of the existence of the process.

image.png

How the PCB is organized

image.png

  • link method
    image.png
  • index method
    image.png

process characteristics

image.png

state of the process

state

image.png
In addition, there are suspension states: ready suspension and blocking suspension

image.png

Process State Transitions

image.png

image.png

process control

Process control is mainly to realize the transition between process states

image.png

image.png

primitive language

Process control is generally implemented by primitives in the OS kernel

In order to ensure that the status of the PCB is consistent with the queue and other information, it is necessary to complete these modification operations in one go.

image.png
image.png

image.png

Process creation and termination

image.png

image.png

process switching

image.png

Process blocking and waking up

image.png

Process suspension and activation

process communication

Process communication refers to the exchange of information between processes

image.png

shared storage

image.png

pipe communication

image.png

messaging

image.png

CS system

Communication of processes between different computers of the primary user

  • socket

  • remote procedure call and remote method call

process synchronization

image.png

Process synchronization and mutual exclusion

The realization of process mutual exclusion is the realization of process synchronization in the same process first P and then V
, which is the first V and then P in two processes

image.png

image.png

access to critical resources

image.png
image.png

Hardware Implementation

image.png

interrupt mask method

image.png

TestAndSet command

image.png

Swap command

image.png

Semaphore mechanism

image.png

Classification

  • integer semaphore
    image.png
    image.png

  • record semaphore
    image.png
    image.png
    image.png

Semaphore applications

image.png

  • Implement process mutual exclusion

image.png

  • Realize process synchronization

image.png

  • Realize the predecessor relationship of the process
    image.png

Monitor mechanism

image.png

image.png

image.png

eg. synchronized
image.png

common problem

producer and consumer problem

image.png

image.png

image.png

image.png

The multi-producer and multi-consumer problem

image.png

image.png

When the capacity of the plate is 1, you don’t need to write mutex; when the capacity of the plate is greater than 1, you need mutex

smoker problem

image.png

image.png

reader and writer problem

image.png

image.png

image.png

image.png

dining philosophers problem

image.png

image.png

image.png

image.png

thread

image.png

  • Process is the basic unit of resource allocation, thread is the basic unit of scheduling
  • A process can have multiple threads

properties of threads

image.png

Implementation of threads

image.png

The Java language uses the many-to-many model

processor scheduling

When there are a bunch of tasks to be processed, but due to limited resources, these things cannot be processed at the same time. This requires determining some kind of rules to determine the order in which these tasks are processed, which is the problem of "scheduling" research.

image.png

Processor Scheduling Hierarchy

image.png

Advanced (Job) Scheduling

image.png
Advanced scheduling is mainly used in multi-batch-to-batch systems, while advanced scheduling is not set in time-sharing and real-time systems.

Intermediate (memory) scheduling

image.png

low-level (process) scheduling

image.png

Scheduling Guidelines

  • short turnaround time
  • short response time
  • High system throughput
  • High resource utilization
  • fair
    image.png

process scheduling

image.png

Timing of process scheduling

image.png

kernel program critical section
image.png

Ordinary code (ordinary critical section) accesses ordinary critical resources (such as IO devices), and processor scheduling can be performed. Kernel
program (kernel program critical section) accesses kernel data structures (such as ready queue), and processor scheduling cannot be performed.

The method of process scheduling

image.png

Process switching and process

image.png

Generalized process scheduling:

  • Select a process (narrow process scheduling)
  • Process switching:
    • Save the data of the original process
    • Restore data for new processes

Scheduling Algorithm

Evaluation index

image.png

  • CPU utilization
    image.png

  • system throughput

image.png

  • Turnaround time
    image.png

  • Turnaround time with entitlement
    image.png

  • waiting time

image.png

  • Response time

image.png

Early Batch Algorithm

The following three algorithms are suitable for early batch processing algorithms

image.png

first come first serve

FCFS is the simplest scheduling algorithm, which can be used for both job scheduling and process scheduling
image.png

eg
image.png

short job first

image.png

  • non-preemptive
    image.png

  • seize
    image.png

image.png

Precautions
image.png

High Response Ratio Priority

image.png

eg

image.png

modern interactive algorithm

image.png

Time slice rotation

image.png
image.png

Generally speaking, when designing time slices, the overhead of switching processes should not exceed 1%.

eg
image.png

priority scheduling

image.png

  • non-preemptive
    image.png

  • Preemptive
    image.png
    Notes
    image.png

multi-level feedback queue

image.png

eg
image.png

For real-time scheduling:

  1. Earliest deadline first: The earlier the task deadline, the higher the priority
  2. Lowest Slack First: The more urgent the task, the higher the priority

deadlock

image.png

image.png

Conditions that cause a deadlock

image.png

image.png

processing strategy

deadlock prevention

image.png

  • break the mutex condition

image.png

  • break the non-deprivation condition

image.png

  • Destroy requests and hold conditions

image.png

  • break loop wait condition
    image.png

avoid deadlock

security sequence

image.png
image.png

banker's algorithm

image.png

Deadlock detection and resolution

image.png

Deadlock Detection Algorithm

image.png

remove deadlock

image.png

Guess you like

Origin blog.csdn.net/weixin_50799082/article/details/130943854