Interpretation of the basic concept of process

Table of contents

what is a process

PCB

Data structures for supervisory control in the OS

The role of process control block PCB

information in the process control block

forward trend graph

background 

effect 

express

example

 sequential execution of programs

Characteristics of program execution sequence 

concurrent execution of programs

 Characteristics of concurrent execution of programs

Interpretation of examples 

 Three basic states of a process

Transitions between the three states of a process

process creation state

The termination status of the process

Suspended Operations and Process State Transitions 


what is a process

For the definition of a process, there are different definitions from different perspectives, among which the more typical definitions are:
(1) A process is an execution of a program.
(2) A process is the activity that occurs when a program and its data are executed sequentially on a processor.
(3) A process is a process in which a program with independent functions runs on a data set, and it is an independent unit for the system to allocate and schedule resources.
 

PCB

The system uses PCB to describe the basic situation and activity process of the process

Note: PCB is the unique identification of the process in the computer (including identification information), and the computer perceives the existence of the process by looking at the PCB.

The composition of the process
program + data collection + process control block (PCB)

Data structures for supervisory control in the OS

In the computer system, a data structure is set for each resource and each process to represent its entity, which we call resource information table or process information table, which contains the identification, description, status of resources or processes and other information and a batch of pointers. Through these pointers, information tables of similar resources or processes, or resource information tables occupied by the same process can be classified and linked into different queues, which is convenient for the operating system to search.
These data structures managed by the OS are generally divided into the following four categories: memory table, device table, file table, and process table for process management. Usually, the process table is also called the process control block PCB.

The role of process control block PCB

(1) As a sign of an independently operating base unit.
(2) It can realize intermittent operation mode.
(3) Provide information required for process management.
(4) Provide information required for process scheduling.
(5) Realize synchronization and communication with other processes.

information in the process control block

The process control block mainly includes four parts of information:
1) Process identifier
The process identifier is used to uniquely identify a process. A process usually has two identifiers:

 a) External identifier (equivalent to the file name of the executable program, provided by the creator, usually composed of letters and numbers, often used by users to access the process).
 b) Internal identifier (set for the convenience of the system, each process is assigned a unique integer as an internal identifier, PID).

2) Processor state
Processor state information is also called the context of the processor, which is mainly composed of the contents of various registers of the processor.

3) Process scheduling information
When the OS schedules, it is necessary to understand the status of the process and information about process scheduling, which includes:
① Process status, indicating the current status of the process, which is used as the basis for process scheduling and swapping;
② Process priority is an integer used to describe the priority level of the processor used by the process. Processes with high priority should obtain the processor first; ③
Other information required for process scheduling, which are related to the process scheduling algorithm adopted, such as , the sum of the time that the process has been waiting for the CPU, the sum of the time that the process has been executed, etc.;
④ event, refers to the event that the process is waiting to happen when the process changes from the execution state to the blocking state, that is, the cause of blocking.

4) Process control information
refers to the information necessary for process control, which includes:
① The address of the program and data, the memory or external memory (first) address of the program and data in the process entity, so as to be rescheduled to the process When executing, its program and data can be found from the PCB;
② Process synchronization and communication mechanism, which is a necessary mechanism for realizing process synchronization and process communication, such as message queue pointers, semaphores, etc., which may be placed in whole or in part In the PCB;
③ resource list, which lists all the resources (except CPU) required by the process during operation, and there is also a list of resources allocated to the process; ④ link pointer, which
gives The first address of the PCB of the next process in the queue where the current process (PCB) is located.

forward trend graph

background 

In early systems without OS configuration and single-channel batch processing systems, the program execution mode is sequential execution, that is, only one user program is loaded in the memory, and it monopolizes all resources in the system, and only when one user program is executed is completed. After that, another program is allowed to be loaded and executed. It can be seen that this method wastes resources and has disadvantages such as low system operation efficiency.

Single-channel batch processing system: the execution mode of the program is sequential execution, that is, only one user program is loaded in the memory, and it monopolizes all the resources in the system. Only after the execution of one user program is completed, another program is allowed to be loaded and implement.
Disadvantages: This method wastes resources, low system operation efficiency and other disadvantages 

effect 

 In order to better describe the sequence and concurrent execution of programs, we first introduce the predecessor graph used to describe the sequence of program execution. The so-called Precedence Graph refers to a directed acyclic graph, which can be recorded as DAG (Directed Acyclic Graph), which is used to describe the sequence of execution between processes. Each node in the graph can be used to represent a process or a program segment, or even a statement, and the directed edge between the nodes represents the partial order (Partial Order) or Precedence Relation (Precedence Relation) between the two nodes. ).

express

The predecessor relationship between processes (or programs) can be represented by "→". If there is a predecessor relationship between processes Pi and Pj, it can
be expressed as (Pi, Pj)∈→, or it can also be written as Pi→Pj, which means that in Pi must complete before Pj begins execution. At this point Pi is said to be the immediate predecessor of Pj, and Pj is said to be the immediate successor of Pi. In the predecessor graph, a node without a predecessor is called an initial node, and a node without a successor is called a final node. In addition, each node also has a weight (Weight), which is used to represent the amount of program contained in the node or the execution time of the program.

example

 Figure (a) has the following predecessor relations:
P1→P2, P1→P3, P1→P4, P2→P5, P3→P5, P4→P6, P4→P7, P5→P8, P6→P8, P7→
P9 , P8→P9
or expressed as:
P={P1, P2, P3, P4, P5, P6, P7, P8, P9}
={(P1, P2), (P1, P3), (P1, P4), ( P2, P5), (P3, P5), (P4, P6), (P4, P7), (P5, P8), (P6, P8), (P7,P9), (P8, P9)}

 Cycles are not allowed in the predecessor graph, otherwise an impossible predecessor relationship will inevitably be generated .
There is a cycle in the predecessor relationship shown in figure (b) . On the one hand, it requires that S2 must be completed before S3 begins to execute, and on the other hand, it requires that
S3 must be completed before S2 begins to execute. Obviously, such a relationship is impossible to achieve.

S2→S3,S3→S2

 sequential execution of programs

Usually, an application program is composed of several program segments, and each program segment completes a specific function. When they are executed, they need to be executed in a certain order. Only after the previous program segment is executed, the next program is run. part. For example, when performing calculations, the input program should be run first to input user programs and data; then the calculation program should be run to calculate the input data; finally, the printing program should be run to print the calculation results. We use nodes (Node) to represent the operations of each program segment (indicated by circles in the figure on the previous page), where I represents input operations, C represents calculation operations, P represents printing operations, and arrows indicate the sequence of operations.

 In this way, there is such a predecessor relationship among the above three program segments: Ii→Ci→Pi, and the execution sequence can be
described by the predecessor graph (a).

 Even if it is a program segment, there may be an execution sequence problem. The following shows a program segment containing three statements:
S1: a :=x+y;
S2: b :=a-5;
S3: c := b+1;
among them, statement S2 must be executed after statement S1 (that is, a is assigned a value), and statement S3 can only be executed after b is assigned a value. Therefore, there is such a predecessor relationship among the three statements: S1→S2 →S3, should be executed in the order shown in the preceding graph (b) 

Characteristics of program execution sequence 

When the program is executed sequentially, it has the following three characteristics:
① Sequence: means that the processor executes strictly in accordance with the order specified by the program, that is, each operation must be completed before the next operation starts;
② Closedness: means that the program is executed in a closed Run in the environment, that is, when the program is running, it monopolizes the resources of the whole machine. Only the program can change the state of the resources (except the initial state). Once the program starts to execute, its execution result will not be affected by external factors
; The environment and initial conditions are the same when the program is executed. When the program is executed repeatedly, no matter whether it is executed from the beginning to the end without stopping or "stop and go", the same result can be obtained. This characteristic of program execution in sequence brings great convenience for programmers to detect and correct program errors.

concurrent execution of programs

We use a common example to illustrate the sequential execution and concurrent execution of programs. It is known that there is a predecessor relationship such as Ii→Ci→Pi between the aforementioned input program, calculation program and printing program, so that the three program segments of input, calculation and printing of a job must be executed sequentially. However, when processing a batch of jobs, the execution of the input, calculation and printing program segments of each job is shown in the figure

Observing the above figure, it can be seen that there is a predecessor relationship Ii→Ci, Ii→Ii+1, Ci→Pi, Ci→Ci+1, Pi→Pi+1, and Ii+1 overlaps with Ci and Pi-1 , that is, there is no predecessor relationship between Pi-1 and Ci and Ii+1, and they can be executed concurrently.
Looking at the figure below, it can be seen that for a program segment with the following four statements:
S1: a :=x+2
S2: b :=y+4
S3: c :=a+b
S4: d :=c+b
can be Draw the predecessor relationship as shown above. It can be seen that: S3 must be executed after a and b are assigned; S4 must be executed after S3
; but S1 and S2 can be executed concurrently because they are independent of each other. 

 Characteristics of concurrent execution of programs

After the introduction of the concurrent execution function among programs, although the throughput and resource utilization of the system have been improved, because they
share system resources and they cooperate with each other to complete the same task, there is a problem between these concurrently executed programs. There will
be a mutually restrictive relationship between them, which will bring new features to the concurrent execution of the program.

(1) Intermittent.
(2) Loss of closure.
(3) Irreproducibility.

Interpretation of examples 

[2019 Topic Question No. 30: Green]
30. The predecessor graph is a directed acyclic graph, recorded as →={(Pi, Pj) the completion time of pi is before the start time of Pj}. Assume that P={P1, P2, P3, P4, P5, P6, P7, P8} in the system, and the predecessor graph of the process is as follows:

 A.→={(P1,P2),(P1,P3),(P1,P4),(P2,P5),(P3,P2),(P3.P4).(P3,P6).(P4, P7), (P5, P8)
B. → = {(P1, P2), (P1, P4), (P2, P3), (P2, P5), (P3, P4), (P3, P6), ( P4, P7), (P5, P6), (P6, P8), (P7, P6)}
C.→={(P1, P2), (P1, P4), (P2, P5), (P3, P2 ), (P3, P4), (P3, P6), (P4, P6), (P4, p7), (p6, p8), (p7, P8) } D.→={P1, P2), (
P1 , P3), (P2, P4), (P2, P5), (P3, P2), (P3, P4), (P3, P5), (P4, P7), (P6, P8), (P7, P8 )}

A. There are 10 predecessor relationships, P1 is the initial node, and P2P4 is the termination node
B. There are 2 predecessor relationships, P6 is the initial node, and P2P4 is the termination node
C. There are 9 There are 10 predecessor relationships, P6 is the initial node, P8 is the termination node
D. There are 10 predecessor relationships, P1 is the initial node, and P8 is the termination node

Answer: Answer choice B|D.
In the predecessor graph, the arrow represents the predecessor relationship, and the node represents the process. In this figure, P1 is the starting point, and P8 is the end point. There are 10 predecessor relationships in total. Each predecessor relationship can be expressed in the form of (node ​​1, node 2), such as: the predecessor relationship between P1 and P2 can be expressed by: (P1, P2).

 Three basic states of a process

Because multiple processes share system resources during concurrent execution, resulting in intermittent operation patterns during their operation, a process may have multiple states during its life cycle. Generally speaking, each process should be in at least one of the following three basic states: (1) Ready (Ready) state.
(2) Execution (Running) status.
(3) Blocking (Block) state.

Transitions between the three states of a process

Processes often undergo state transitions during execution. For example, a process in the ready state can be executed after the scheduler allocates a processor for it, and correspondingly, its state changes from the ready state to the execution state; When the time slice is over and the execution of the deprived processor is suspended, its state is changed from execution to ready; if an event occurs, the execution of the current process is blocked (for example, the process accesses a critical resource, which is being accessed by other processes) ), so that it cannot continue to execute, the state of the process will change from executing to blocking. Figure 2-5 shows the three basic states of the process and the transition relationship between each state.

process creation state

Processes are spawned by creation. Creating a process is a very complicated process, and it usually needs to be completed through multiple steps: first, the process applies for a blank PCB, and fills in the PCB with information for controlling and managing the process; resources; finally, the process is transferred to the ready state and inserted into the ready queue. However, if the resources required by the process cannot be met, for example, the system does not have enough memory to allow the process to be loaded into it, the creation work has not been completed at this time, and the process cannot be scheduled to run, so the state of the process at this time is called Create state.

The termination status of the process

The termination of the process also goes through two steps: first, it waits for the operating system to deal with the aftermath, and finally clears its PCB and returns the PCB space to the system. When a process reaches its natural end point, or has an insurmountable error, or is terminated by the operating system, or is terminated by another process with termination rights, it will enter the terminated state. A process that enters the terminated state can no longer be executed, but a record is still kept in the operating system, which saves the status code and some timing statistics for other processes to collect. Once other processes have finished extracting their information, the operating system will delete the process, that is, clear its PCB, and return the blank PCB to the system.

Suspended Operations and Process State Transitions 

The introduction of suspended operation
The reason for introducing suspended operation is based on the following needs of the system and users:
(1) The needs of end users.
(2) Parent process request.
(3) The need for load regulation.
(4) The needs of the operating system.

The transition of the three process states after the introduction of the suspend primitive operation
After the suspend primitive Suspend and the activation primitive Active are introduced, under their action, the process may undergo the following state transitions:
(1) Active Ready → Stationary ready.
(2) Active blocking → static blocking.
(3) Standby Ready → Active Ready.
(4) Static blocking → active blocking.

Transitions of five process states after introducing suspend operations
The figure below (right) adds process states and transition diagrams with suspend states after creation and termination states.
After the creation and termination states are introduced, when the process state transitions, compared with the five state transitions of the process in the figure below (left), the following
situations should be considered:
(1) NULL→Create:
(2) Create→Activity Ready :
(3) Create → Standby Ready:
(4) Execute → Terminate:

Guess you like

Origin blog.csdn.net/m0_62436868/article/details/131465213