The concept of process
The concept of thread
A process is a process in which a program runs on a data set, and it is an independent unit for the system to allocate and schedule resources. It consists of three parts: program block, process control block (PCB) and data block
PCB : the only sign of the existence of the process. The content includes process identifier, status, location information, control information, queue pointer (linking the process of the same status), priority, site protection area, etc.
The difference between a process and a program : a process is an execution process of a program, and there is no process without a program
Two basic attributes of a process : ① An independent unit that can own resources ② A basic unit that can independently schedule and allocate resources
state of the process
Running: When a process is running on the CPU
Ready: A process has obtained all the required resources except the CPU, and can run once it gets the processor
Blocking: Blocking is also called waiting or sleeping state, a process is waiting for an event to occur (such as requesting I/O to wait for I/O to complete, etc.) and temporarily stop running. At this time, even if the CPU is allocated to the process, it cannot run, so the process is in a blocked state
Three-state model
five state model
process scheduling
Process synchronization and mutual exclusion
Critical resources: resources that need to be shared among processes in a mutually exclusive manner. (The piece of code that accesses critical resources in a process is called a critical section)
Mutual exclusion: indirect constraint relationship, such as thousands of troops crossing a single-plank bridge
Synchronization: direct constraint relationship, speed difference, stop and wait under certain circumstances
PV operation
Realize the synchronization and mutual exclusion of processes
Semaphore: It is a special variable
①The semaphore can indicate the number of resources
②When the semaphore is negative, it can also indicate the number of queued processes
S=S-1 Apply to lock resources
S<0 Determine whether there are available resources
S=S+1 Release resources
S<=0 Determine whether there are processes in the queue
deadlock problem
The so-called deadlock refers to the phenomenon that two or more processes require each other's already occupied resources and cannot continue to run.
Four conditions for deadlock:
① Mutual exclusion
② Hold and wait
③ No preemption
④ Loop waiting
Deadlock prevention
① Breaking the four major deadlock conditions
Deadlock avoidance: banker's algorithm,
deadlock detection and release,
ostrich strategy (ignored)
Segmented paging
paging
Paging storage: Divide the program and memory into blocks of the same size, and load the program into the memory in units of pages
Logical address = page number + page address
Physical address = page frame number + page address
Page Replacement Algorithm
Optimal algorithm
Random algorithm
First-in-first-out algorithm: It may cause jitter
Least recently used algorithm: No jitter, the theoretical basis of LRU is "locality principle"
- Temporal locality: what is accessed just now is accessed again immediately
- Spatial locality: the content that has just been accessed, the adjacent space will be accessed soon
Segmented memory organization
Segment storage: divide the logical space according to the natural segments in the user's job, and then load it into the memory. The length of the segment can be different
Advantages: Multiple programs share memory, and the modification of each program does not affect each other
Disadvantages: Low memory utilization rate and large waste of memory fragments
Logical address (segment number, offset within the segment) The offset cannot exceed the segment length
Segment 0, the segment length cannot exceed 600
, and so on, to get B
disk management
Access time = seek time + waiting time, seek time refers to the time required for the head to move to the track; wait time is the time it takes for the sector waiting for reading and writing to go to the bottom of the head
The time to read disk data should include the following three parts:
① Time to find a track
② Time to find a block (sector), that is, rotation delay time
③ Transmission time
Disk Scheduling Algorithm
First-come-first-serve algorithm: Literally, access by first-come serial number
Shortest seek time first: starting from the current position, seek the nearest track
example
I/O management software
The response ratio of J2=(10+20)/20=1.5
The response ratio of J3=11/6
, so choose B