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.
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.
How the PCB is organized
- link method
- index method
process characteristics
state of the process
state
In addition, there are suspension states: ready suspension and blocking suspension
Process State Transitions
process control
Process control is mainly to realize the transition between process states
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.
Process creation and termination
process switching
Process blocking and waking up
Process suspension and activation
process communication
Process communication refers to the exchange of information between processes
shared storage
pipe communication
messaging
CS system
Communication of processes between different computers of the primary user
-
socket
-
remote procedure call and remote method call
process synchronization
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
access to critical resources
Hardware Implementation
interrupt mask method
TestAndSet command
Swap command
Semaphore mechanism
Classification
-
integer semaphore
-
record semaphore
Semaphore applications
- Implement process mutual exclusion
- Realize process synchronization
- Realize the predecessor relationship of the process
Monitor mechanism
eg. synchronized
common problem
producer and consumer problem
The multi-producer and multi-consumer problem
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
reader and writer problem
dining philosophers problem
thread
- Process is the basic unit of resource allocation, thread is the basic unit of scheduling
- A process can have multiple threads
properties of threads
Implementation of threads
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.
Processor Scheduling Hierarchy
Advanced (Job) Scheduling
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
low-level (process) scheduling
Scheduling Guidelines
- short turnaround time
- short response time
- High system throughput
- High resource utilization
- fair
process scheduling
Timing of process scheduling
kernel program critical section
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
Process switching and process
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
-
CPU utilization
-
system throughput
-
Turnaround time
-
Turnaround time with entitlement
-
waiting time
- Response time
Early Batch Algorithm
The following three algorithms are suitable for early batch processing algorithms
first come first serve
FCFS is the simplest scheduling algorithm, which can be used for both job scheduling and process scheduling
eg
short job first
-
non-preemptive
-
seize
Precautions
High Response Ratio Priority
eg
modern interactive algorithm
Time slice rotation
Generally speaking, when designing time slices, the overhead of switching processes should not exceed 1%.
eg
priority scheduling
-
non-preemptive
-
Preemptive
Notes
multi-level feedback queue
eg
For real-time scheduling:
- Earliest deadline first: The earlier the task deadline, the higher the priority
- Lowest Slack First: The more urgent the task, the higher the priority
deadlock
Conditions that cause a deadlock
processing strategy
deadlock prevention
- break the mutex condition
- break the non-deprivation condition
- Destroy requests and hold conditions
- break loop wait condition
avoid deadlock
security sequence