1. Introduction of processes
In a multi-programming system, programs have the characteristics of parallelism, constraints and dynamics. The concept of program is difficult to describe and reflect the situation in the system:
1. Program is a static concept
A program is a set of instructions to complete a certain function. The system is actually in a constantly changing state, and the program cannot reflect this dynamic nature.
2. The program concept cannot reflect the parallel characteristics of the system
For example: two C language source programs are compiled by a compiler. If you use the program concept to understand it, there is only one in the memory. The compiler runs (the two source programs are regarded as input data to the compiler), but this cannot explain that there are two tasks running in the memory. The concept of program cannot represent this parallel situation and cannot reflect the rules of their activities and state changes. Just like you cannot use a recipe (program) to replace cooking (the process of program execution) (I have slightly modified this sentence, I feel it should be expressed in this way).
2. Definition of process
Process: A program with certain independent functions is a running activity for a certain data collection. It is the basic unit for resource allocation and scheduling operation of the system.
3. The difference between process and program
1. Process is a dynamic concept
A process is an execution process of a program and is a dynamic concept.
A program is an ordered set of instructions and is a static concept.
2. Different processes can execute the same program
Conditions for distinguishing processes: the executed program and data set.
Even if two processes execute on the same program, as long as they run on different data sets, they are two processes. For example: multiple users call the same compiler at the same time to compile the C language source programs they wrote. Since the compiler runs on different data sets (different C language source programs), different processes are generated.
3. Each process has its own life cycle
When the operating system wants to complete a certain task, it creates a process. When the process completes its task, the system will cancel the process and reclaim the resources it occupied. The time period from creation to cancellation is the life cycle of the process.
4. Concurrency exists between processes
In a system, there will be multiple processes at the same time. They take turns occupying the CPU and various resources.
5. Processes will restrict each other
Processes are the units for resource allocation and operation scheduling in the system. In the sharing and competition of resources, they will inevitably restrict each other and influence each other. The speed at which each moves forward.
6. A process can create subprocesses, but a program cannot create subprograms
7. Structurally, each process consists of programs, data and a process control block (Process Control Block) Block, PCB) composition
IV. Important characteristics of the process
1. Dynamic characteristics: The process corresponds to the running of the program, dynamically generates and dies, and the process is also dynamic during its life cycle of.
2. Concurrency characteristics: Any process can move forward together with other processes.
3. Independent characteristics: The process is a relatively complete scheduling unit that can obtain the CPU and participate in concurrent execution.
4. Interaction characteristics: A process can have direct or indirect relationships with other processes during execution.
5. Asynchronous characteristics: Each process moves forward at a relatively independent and unpredictable speed.
6. Structural characteristics: Each process has a PCB as its data structure.
The most basic characteristics of a process are concurrency and sharing.
5. Process states and transitions
1. Three basic states of processes
a. Running state: The process that obtains the CPU is in this state, corresponding to program is running on the CPU.
b. Blocking state: In order to wait for the occurrence of an external event (such as waiting for the completion of an I/O operation, waiting for a message from another process), it is temporarily unable to run. It also becomes a waiting state.
c. Ready state: All conditions required for operation are met, but it is temporarily unable to run because other processes occupy the CPU.
2. Process state transition
a. Running state ===> Blocking state: For example, a running process makes an I/O request and is converted from running state to blocking state.
b. Blocking state ===> Ready state: For example, after the I/O operation is completed, the blocking state is converted to the ready state.
c. Ready state ===> Running state: For example, a process in the ready state is selected by the process scheduler, assigned to the CPU for running, and converted from the ready state to the running state.
d. Running state ===> Ready state: The time slice of the process in the running state has been used up and it has to give up the uCPU and transform from the running state to the ready state.
3. Types of processes
a. System process: The process used by the operating system to manage resources. When the system process is in the running state, the CPU is in the management state, and the communication between the systems The relationship is taken care of by the operating system.
b. User process: A user program segment that the operating system can execute independently. When the user process is in the running state, the CPU is in the target state, and the relationship between user processes is the responsibility of the user.
6. Process control block
1. Three components of the process
a. Program
b. Data
c. Process Control Block (PCB): In order to manage and control processes, when the system creates each process, it opens a dedicated storage area for it to record its dynamic characteristics in the system. The system controls and manages the process based on the information in the storage area. After the process task is completed, the system takes back the storage area and the process dies. This storage area is the process control block.
PCB is established when the process is created and disappears when it is revoked. The system perceives the existence of a process based on the PCB, which is the only physical identifier of the process's existence (this can be compared to the job control block JCB).
2. The content of the process control block
PCB may be represented by different data structures in different languages. For the convenience of system management and process control, the system often stores the PCBs of all processes in the system table area in the memory (what area is this? I don’t know, wait for me to check carefully), and stores them in order from small to large according to the internal labels of the processes.
The PCB collection of each process in the entire system can be represented by an array. At this time, the internal label of the process can be associated with the subscript of the array element.
The PCB space reserved by each system is often fixed. For example, UNIX systems stipulate that the number of processes does not exceed 50 (I have some doubts about this).
The format, size and content of PCB are also different depending on the operating system. Generally, it should contain the following four pieces of information.
a. Identification information: process name.
b. Description information: process status, program storage location.
c. On-site information: general register memory, control register memory, breakpoint address.
d. Management information: process priority number, queue pointer.
7. Organization of process control blocks
In the system, there are many processes in different states. Processes in the blocked state are blocked for different reasons. In order to facilitate scheduling and management, they are often The process control block PCB is organized in an appropriate manner.
1. Linear structure
Organize the PCBs of all processes in different states in a table.
The simplest, suitable for operating systems with a small number of processes, such as UNIX systems. The disadvantage is that when calling, the entire PCB table often needs to be queried, and the time complexity is slightly higher.
2. Index structure
Organize process PCBs with different states in the same table, so there are ready process table, running process table (in multi-machine systems, and Today's multi-core systems should also have it) and blocking process tables for various waiting events.
Some fixed units in the system respectively indicate the starting address of each table.
3. Chain structure
When using the queue form, a chain pointer entry is added to the PCB of each process to point to the next PCB starting address of the queue.