Shared memory Processes that communicate with each other in a system share certain data structures or share storage areas

Messaging System processes pass messages through a set of communication programs provided by the operating system

Pipeline communication Information is communicated between processes through pipes (special files connected to read and write processes)

Message buffer queues use message buffers, send primitives and receive primitives to communicate information

Added: Shared memory systems, messaging systems, and pipe communication are among the advanced communication mechanisms

What is a thread? In fact, a thread is a subdivision of the process

Definition: a thread is an entity in a process. It is the basic unit that is independently scheduled and dispatched by the system

A thread can own only the resources necessary to run, including program counters, a set of registers, and stacks, but it can share all the resources owned by the process with other threads of the same process

Note: Threads cannot apply for resources independently!

Classification of threads 1. Kernel level threads

2. User-level threads

The states of a thread are running, blocked, and ready

Thread control block (TCB) Each thread is represented by a data structure, including its basic state and so on. This data structure is the TCB

The TCB records all the information needed by the operating system to describe a thread and control its execution

1. Resources and scheduling: Thread is the basic unit of program execution, process is the basic unit of owning resources

2. Address space: The address space of different processes is independent of each other, but all threads in the same process share the same address space

3. Communication relationship: the communication between processes must be provided by the interprocess communication mechanism provided by the operating system, and the threads in the same process can communicate with each other in bytes

4. Concurrency: Multiple processes can be executed concurrently, and multiple threads can be executed concurrently

5. System overhead: The overhead of switching between threads is less than that of switching between processes

Thread control 1. Creation (1) Kernel-level thread creation

(2) The creation of user and level threads

2. Termination (1) Normal termination

(2) Abnormal end

(3) External interference

3. Block (1) Requests system services

(2) Start an operation

(3) New data have not arrived yet

4. Wake up

5. The scheduling

6. Switch

The function and timing of process scheduling and deadlocked process scheduling The function of process scheduling is accomplished by the process scheduler of the operating system

Specifically, process scheduling is to select a new process to run on the currently idle CPU from the ready process according to some strategy and algorithm

Scheduling timing:

(1) The process ends normally

(2) The process is blocked

(3) A process with a higher priority arrives

(4) Time slice is used up

(5) The process ends abnormally

Process scheduling algorithm selection 1. How to measure a good algorithm?

(1) Short turnaround time: it takes a short time for an operation to be submitted to the operating system until it is completed;

(2) Fast response time: it takes a short time from the beginning of the user’s job submission to the beginning of the system response;

(3) Deadline guarantee: Ensure that the work is started before the start deadline and completed before the completion deadline;

(4) Large throughput: the system can complete the most tasks per unit time;

(5) Processor utilization rate is good: CPU utilization rate is as high as possible.

Supplement:

Turnaround time: waiting time for external storage + waiting time for ready queue + execution time +I/O completion

## Process scheduling algorithm 1. First come first served FCFS

Allocate CPU to the first arriving process directly from the ready queue

2. SPF is preferred for short processes

Select the process with the shortest running time from the ready queue and allocate CPU to it

Advantages: It can effectively reduce the average process waiting time and improve system throughput

Disadvantages: Not conducive to long processes