Operating System Chapter 2—Description and Control of Processes

2.1 Precursor graph and program execution

2.1.1 Precursor diagram

Precursor graph is adirected acyclic graph, denoted as DAG, which can be used a>Describe the execution context between programs/processes.

Note: Loops are not allowed in the precursor graph.

2.1.2 Program sequence execution

Sequential execution of programs: There is only one program running in the computer system. This program monopolizes all resources in the system, and its execution is not affected by the outside world. After one program is executed, another program Just started together.

Special points:

Sequentiality: The processor executes strictly in the order specified by the program

Closedness: The program runs in a closed environment and monopolizes the entire machine's resources. Once started, it is not affected by the outside world.

Reproducibility: (The results of the program have nothing to do with the running time, only the initial conditions) As long as the environment and initial conditions are the same, the same results can be obtained

2.1.3 Concurrent program execution

Concurrent execution of programs: Several programs are executed in the system at the same time. The execution of these programs overlaps in time. The execution of one program has not yet ended, and the execution of another program The execution has begun.

Features: Intermittent (when programs are executed concurrently, because they share resources or cooperate to complete a certain task, there is a mutual restriction relationship between concurrent programs ), losing the closure of the program (when a program is executed concurrently, multiple programs share various resources in the system, so the status of these resources will be changed by multiple programs, causing the program to lose its closure.), cannot Reproducibility (When a program is executed concurrently, it also loses reproducibility due to the loss of closure.)

2.2 Description of the process

2.2.1 Definition and characteristics of process

Definition of process: A process is the execution process of a program and an independent unit for resource allocation and scheduling in the system.

Special Expedition

(1) Dynamic: The process has a life cycle. It is born by being "created" by the system, executed by "scheduling", suspended due to lack of resources, and finally dies due to being "revoked".

(2) Concurrency: The actions of different processes can overlap in time, that is, multiple processes in the system can be executed concurrently.

(3) Independence: The process entity is a basic unit that can operate independently. It is also the basic unit that independently obtains resources and mobilizes resources independently in the system. In today's operating systems that have both processes and threads, a process is still an independent unit with resources, but it is no longer an executable entity. The basic unit of independent operation of the system becomes a thread.

(4) Asynchronous: Processes move forward at independent and unpredictable speeds. The reason for the unpredictability is concurrent execution.

2.2.2 Basic status and transition of process

Ready state (Ready): When the process has been allocated all required resources except the CPU, it can be executed immediately as long as the processor (CPU) resources can be obtained.

Some systems introduce a suspend state in order to temporarily relieve memory tension or to adjust system load. That is to temporarily swap out some processes from the memory to external memory, so that they are temporarily disconnected from the system. In this way, the readiness state of the process can be subdivided into: active ready state (not suspended), static ready state (suspended); blocking state is subdivided into: active blocking state (not suspended), static blocking state (not suspended) hang)

Execution status (Running): When the process has obtained processor resources, its program is being executed on the processor.

Blocked state (Blocked) or waiting state: When the executing process cannot be executed because it is waiting for an event to occur, it gives up the processor resources and is in a suspended state.

In many systems, two basic states have been added: (1) New state: when the process has just been created and resources are allocated; (2) Termination state: the process will not be revoked immediately after the process ends, and the corresponding process will temporarily Remain on the system to collect information about the process.

2.2.3 Suspended operations and process state transitions

The difference between suspending and blocking

Different usage of system resources: Although the CPU is released, the blocked process is still in the memory, and the suspended process is swapped out to external memory (disk) through "swap" technology.

The timing of occurrence is different: blocking generally occurs when the process is waiting for resources (IO resources, semaphores, etc.); while suspension is due to the needs of the user and the system. For example, the end user needs to pause the program to study its execution or modify it, the OS In order to improve memory utilization, temporarily inoperable processes (processes in the ready or blocking queue) need to be transferred to disk.

The recovery timing is different: blocking will not enter the ready state until the resource it is waiting for is satisfied (for example, a lock is obtained), waiting to be scheduled for execution; the suspended process is controlled by the object that suspended it (such as user, system) Actively activate it when the time is right (debugging is completed, selected by the scheduled process and needs to be re-executed)

The purpose of the suspend operation

  • End user needs: Modify, inspect processes

  • The needs of the parent process: modify and coordinate the child process

  • The need for swapping: buffering memory

  • The need for load regulation: ensuring the execution of real-time tasks

2.2.4 Data structure in process management

Data structures used for management control in operating systems

In order to facilitate the management of the process, it is abstracted into various data structures;

In order to coordinate the use of shared resources in the system by many users, it is necessary to record and query the use of various resources and various types of operating information.

For each resource and process, a data structure is set up to represent its entity, called a resource information table or process information table (identification, description, status, etc.)

PCB function

In order to facilitate system description and process management, the OS specifically defines a data structure-PCB for each process.

As part of the process entity, PCB records all the information required by the operating system to describe the current situation of the process and manage the operation of the process. It is the most important record-type data structure in the operating system.

The function of PCB is to make a program (including data) that cannot run independently in a multiprogramming environment become a basic unit that can run independently, a process that can be executed concurrently with other processes.

(1) As a symbol of an independent operating basic unit. When the system creates a new process, it creates a PCB for it. When the process ends, its PCB is recycled, and the process dies. PCB has become the only sign that a process exists in the system.

(2) Intermittent operation can be achieved. When a process suspends execution due to blocking, the CPU context information of the process can be retained in the PCB of the interrupted process for restoration when the process is called again.

(3) Provide information required for process management. When the scheduler schedules a process for execution, the program and data can be accessed according to the first address of the program and data in the PCB.

(4) Provide information required for process scheduling. The status, priority, waiting time and other information of the process need to be recorded in the PCB for reference by the scheduler.

(5) Realize synchronization and communication with other processes. The PCB needs to set up the semaphore for synchronization, the area to implement process communication, and the communication queue pointer, etc.
Information in PCB

(1) Process identifier

(2) Processor status

(3) Process scheduling information

(4) Process control information

How PCB is organized

(1) Linear method:All PCBs are organized in a linear table, and the first address of the table is stored in a dedicated area of ​​​​the memory.

(2) Linking method:PCBs of processes in the same state form a linked list, and different states correspond to multiple different linked lists, thus forming various queues. Divided into ready linked list and blocking linked list.

(3) Index method: For processes with the same status, set their own PCB index tables respectively, indicating the address of the PCB in the PCB table.

2.2.5. The difference between process and program

1) A program is an ordered collection of instructions, which itself does not have any running meaning. It is a static concept. A process is an execution process of a program on a processor, and it is a dynamic concept.

2) The existence of a program is permanent, while a process has a life span. It is generated due to creation, executed due to scheduling, suspended due to lack of resources, and dies due to cancellation.

3)程序仅是指令的有序集合,而进程则由程序段、相关数据段、进程控制块(PCB)组成。

4)进程与程序之间不是一一对应。

2.3进程控制

进程控制是进程管理中最基本的功能,它可用于创建一个新进程;终止一个无法运行下去的进程;转换进程的运行状态;进程控制一般由OS的内核中的原语来实现

2.3.1进程的创建

2.3.2进程的终止

2.3.3进程的阻塞与唤醒

2.3.4进程的挂起与激活

Guess you like

Origin blog.csdn.net/CYwxh0125/article/details/129567851