2.2 processor management
Processor management, also known as process management, focuses on how to reasonably allocate processing time and improve system efficiency.
1. Features During Program Execution
This is a single program design technology
(1) sequence. Programs and segments are executed in strict accordance with the prescribed sequence
(2) Sealing. When the program is running, the resources in the system are only controlled by the program.
(3) reproducibility: as long as the execution environment of the program is the same as the initial conditions, the cold execution results of the program are the same.
Multi-channel Programming Technology
The main features of concurrent program execution are as follows:
(1) lost the closeness of the program
(2) The activities of programs and machine execution programs are no longer one-to-one correspondence
(3) concurrent programs are mutually restrictive.
2. Process Composition:
A process is an execution of a program, usually composed of a program, data, and a process control block (PCB ).
A process control block is the only identifier of a process.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + MS4gICAgICC9 + mixer + MaOpICDI/cysxKPQzaOoz9 + zzLXEu/mixer + jI + zwvcd4kpgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140429/2014042909095158.jpg" alt = "\">
Note: The process 5-state model is upgraded and optimized.
New State: the state in which the process has just been created and has not been submitted. Wait for the system to complete all necessary work and rest for the process to be created,
With the new state, the operating system can delay the submission of new State processes based on the system performance and memory capacity restrictions.
2. 2. Process Control
Main function: Create a new process, cancel a running process, change the process status, and implement process sound communication. process control is implemented by the operating system kernel (Kemel) implementation of the original code in
A Primitive is a program segment composed of several machine commands used to complete specific functions.
Feature: it is a transaction. Do not do it, or do it all.
Mainly include process control primitives, process revocation primitives, process initiation primitives, process activation primitives, and process blocking primitives.
2.2.3 Process Communication
Process communication refers to the process in which various processes exchange information.
1. Synchronization and mutex
1) Process Synchronization
For example, process A completes the operation of sending data to the buffer zone. process B extracts data from the buffer zone for processing. When process B retrieves data for processing, process A must have completed the operation of sending data to the buffer; otherwise process B must stop and wait until process A's operation ends.
Inter-Process Synchronization refers to the direct interaction between processes when a task is completed.
2) Mutual Exclusion between processes
In a multi-channel program system environment, each process can share all kinds of resources, but some resources can only be used by one process at a time, known as critical resources, such as printers and shared variables.
Mutual Exclusion between processes refers to the mutual exclusion of critical resources by various processes in the system.
3) Principles of critical section management
Enter
No blank rule, etc.
Limited wait
Waiting for permission
2. * semaphore mechanism
Semaphore mechanism is an effective tool for Process Synchronization mutex. At present, there have been many developments in credit mechanisms, mainly including integer semaphores, record semaphores, and semaphores.
1) integer semaphore and PV operations
Semaphores are integer variables, which are divided into the following two types:
Common semaphores. Mutual Exclusion between processes. The initial value is 1 or the number of resources.
Private semaphores. Implement inter-process synchronization. The initial value is 0 or a positive integer.
Physical significance of semaphores: If S> = 0, it indicates the number of available resources.
If S is <0, its absolute value indicates the number of processes waiting for this resource in the blocked queue.
PV operations are common methods to achieve process synchronization and mutual exclusion. P operations and v Operations are low-level communication primitives. It cannot be separated during execution. The P operation applies for a resource, and the V Operation releases a resource.
P operation definition: S = S-1, if S> = 0; then the process that executes P operation continues to execute;
If S <0; then the process is blocked (because there are no available resources) and inserted into the blocking queue.
The P operation can be expressed in the following process. Semaphore indicates that the defined variable is a Semaphore.
ProcedureP (Var S: Semaphore );
Begin
S: = S-1;
If S <0 then W (S ){
Process executing the P operation is inserted into the waiting queue
}
End;
V Operation definition: S: = S + 1; if S> 0; then the process that executes V Operation continues to execute
If S <= 0; then a process is awakened from the blocking status and inserted into the ready queue,
Then the process that executes the V operation continues.
The V operation can be expressed as follows:
ProcedureV (Var S: Semaphore ):
Begin;
S = S + 1;
If S <= 0 then R (S ){
Wake up a process from the blocked queue
}
End;
2) use PV operations to achieve mutual exclusion of processes
Set the initial value of the semaphore mutex to 1. The P operation is performed in the critical section, and the V operation is performed when the critical section is exited. This
Sample. The code for entering the critical section is as follows:
P (mutex)
Critical Section
V (mutex)
In this example, two concurrent programs are executed to collect traffic statistics. The number of vehicles identified by the observer P1 is,
When all reports are P2, the Count values of all observations are cleared to 0;
The procedure for calculating traffic flow with PV is as follows:
P1
L1: if a car passes then
Begin
P (mutex)
Count ++;
V (coutex)
End
Goto L1;
P2
L2: begin
P (mutex );
Print count;
Count: = 0;
V (mutex );
End
GOTO L2;
3) process synchronization using PV operations
Process Synchronization is a mutual constraint caused by the cooperation between processes. One way to achieve process synchronization is
A semaphore is associated with a message. When the semaphore value is 0, it indicates that the expected message is not generated. Otherwise, it indicates that you want
The message has arrived. Assuming that a message is represented by semaphores S, the process may call P to test whether the message is
No, call the V operation to notify message preparation. A typical application is that the producer and consumer of a single buffer zone are the same
Step question!
For example, the producer process P1 continuously produces the product and sends it to the buffer zone. The consumer process P2 continuously extracts
Output product consumption. To synchronize processes P1 and P2, you need to set a semaphore S1 to indicate a slow
Whether the dash zone is idle. The initial value is 1. It indicates that the product can be sent to the buffer zone, and another semaphore S2 is set to indicate a slow speed.
Whether there are products in the dashboard. The initial value is 0;
Assume that there is one producer and one consumer. The buffer zone can store n products, and the producer continuously produces products,
Consumers can continuously consume products and set three semaphores.
1. Advanced Communication
Process Communication methods are classified into low-level and advanced modes,
The Pv operation is a low-level communication method. If the PV operation is used to implement inter-process communication, the following problems exist:
(1 ). Difficult Programming
(2) Low Efficiency
Therefore, advanced communication methods are introduced.
It mainly includes shared storage, message transmission, and pipeline communication.
(1 ). Shared storage mode: processes that communicate with each other share certain data structures to implement inter-process communication.
(2 ). Message transmission mode: data exchange between processes is measured in messages. programmers can use a group of communication commands (primitives) provided by the system to implement communication.
(2) pipeline communication. A pipe is used to connect a read process and a write process.
4 .. Direct and indirect communication
Direct communication directly sends messages to the specified process. Therefore, the process name should be specified in the Send and Receive primitives.
The call format is as follows:
Send (Who, Meessage) sends a message to a specified process or a group of processes.
Receive (Who, Message) receives messages from the agreed process
Indirect communication is implemented by using the mailbox as the media. The process of receiving a mail only needs to set up a mailbox, and several processes can send a mail to the same process,
Send (N, M) Send mail M to mail N
Receive (N, X) fetches a letter from mailbox N and saves it to mailbox X
2.2.4 Process Scheduling
The process scheduling method is how to allocate CPU when a process with a higher priority arrives.
It can be divided into two types: detachable and non-deprived.
1. Three-Level Scheduling
In some operating systems, a job must undergo high, medium, and low level scheduling from submission to completion.
(1) Advanced scheduling, also known as long scheduling, job scheduling, and accept scheduling, decides to be in the input pool
Which backup job can be transferred to the master system to prepare for running and become one or more ready processes.
In the system, only one job needs to go through advanced scheduling.
(2) Intermediate scheduling. It is also known as medium-process scheduling or swap scheduling. It determines which of the ready processes in the SWAp zone can be transferred to the memory to directly participate in the competition for cpu. When memory resources are insufficient, in order to transfer the process to the memory, A blocked process in the memory must be called out to the swap zone to free up space for the incoming process. This is equivalent to swap the process in the memory and the process in the SWAp zone.
(3) low-level scheduling, also known as short-range scheduling or process scheduling, determines the CPU usage of a ready process in the memory. It is the most active and important high-level program in the operating system, it has a great impact on the system.
2. Common Process Height algorithms include first-come service, time slice rotation, priority scheduling, and multi-level worker scheduling algorithms.
1), first come first served (first come first served, FCFS)
FCFS is conducive to long jobs and CPU busy jobs, but not busy I/O jobs.
1) time slice Rotation
The time slice Rotation Algorithm is mainly used for the microscopic height. Its design goal is to improve resource utilization. Rotate by time slice
To improve process concurrency and response time. Which of the following methods can be used? Http://www.bkjia.com/kf/yidong/wp/ "target =" _ blank "class =" keylink "> memory + o6gyo6kgICAgICC/memory + memory/IvLa6zbavzKzTxc/IvLY8L3A + CjxwPqOoMaOp OaO + ssys08XPyLy2o7q9 + LPMtcTTxc/release + release/bPM1tC7ub/J0tS4xLHkoaM8L3A + release/W2zMHLxr2 + release 0M29 + LPM0tS78bXDvc + release/W2zM/release/g8L3A + release + O7 + s + release + LPMu6XP4NKqx/release + c69y8DL + release/release Export/zoaM8L3A + release + LPMzca9 + release/g8L3A + release + PC9wPgo8cD6/release + svAy/release/K3x7eotcTA77PMzca9 + release + 21xNfK1LSy Release/release + LPMttTXytS0tcS + release/release + svrJ + svAy/release + release/qGisru/ybD + tuHM9bz + release/release vcd4kpha + release/release + dKqx/release + NDQxcXL + export/Oxo7PWzPW8/qGjwePQx7XEx + vH89fK1LSjrLy00tG78bXDsr + 31tfK1LTT1sfrx/PX Authorization + authorization/ybD + tuHM9bz + oaO9 + authorization/authorization + authorization/Kx7cq + authorization + LPMo6w8L3A + cjxpbwcgc3jjjpq = "http :// Www.2cto.com/uploadfile/Collfiles/20140429/2014042909095160.jpg "alt =" n? ╧ Y "http://www.bkjia.com/ OS/" target = "_ blank" class = "keylink"> the system must pay a large amount of time overhead, therefore, the number of processes set in the system is small, and the frequency of process switching should not be too high, which limits the increase in concurrency. After the thread is introduced, the two basic attributes of the traditional process are separated. The thread serves as the basic unit for scheduling and resource allocation, and the process acts as the unit for independent resource allocation. You can create threads to complete tasks to reduce the time-space overhead of concurrent program execution.
Features:
A thread is an entity in a process and the basic unit of independent distribution and scheduling by the system. A thread basically has no resources, only have resources (such as program counters, a set of registers, and stacks) that are essential for a single running ). It can share all resources of a process with other threads of the same process. Because a thread has many characteristics of a traditional process, it is called a light process, and a traditional process is called a heavy process.