Computer Operating System Fundamentals (2) --- Process Entity of Process Management

introduction

This article is the second article, the process entity of process management , let everyone familiarize yourself with why you need to use a process and what the process entity is

1. Why process is needed

From the previous article, we know that the basic function of the operating system is to manage the underlying hardware resources, including the following parts
image

With the operating system , these resources can be easily managed. So if there is no operating system, how are these computer resources managed?
Before the OS is configured, the resource only belongs to the currently running program, and the computer can only run one program . At this time, because of some resources, the currently running program cannot be fully and reasonably used, so multiple programs are introduced The concept is also configured with related OS. After the operating system, the process appears. The role of the process is to reasonably isolate resources, operating environment, and improve resource utilization.

Process is the basic unit of system resource allocation and scheduling (with the concept of multi-channel programs, the operating system can allocate resources for each program)
process as a vehicle to protect the programs that run independently normal execution (because there are multi-channel The concept of a program , so there may be multiple processes in a computer that use a physical device, such as memory. Then the process is to play the role of running resource isolation )
The existence of the process makes the utilization of operating system resources Significant improvement (this also relies on the concept of multi-program design)

Therefore, based on the above reasons, the operating system needs processes to run more reasonably and efficiently

Second, the entity of the process

Process form in main memory

In the main memory, the process is also a continuous storage space. This space is called the process control block . There are some important information in the process control block: such as identifiers, status, priority, program counter, memory pointer, context data , Some important information such as IO status information, accounting information, etc.
image

Identifier : A symbol that uniquely marks a process and is used to distinguish other processes. For example, our common process ID is this unique identifier

Status : Mark the process status of the process . Such as running state or blocking state

Program counter : the address of the next instruction that the process is about to execute

Memory pointer : pointer to program code or process data. There may be multiple memory pointers, which point to the specific logic code of the program, or the address related to the execution process data

Context data : This is an important area in the process control block. This area stores the data stored by the processor when the process is executed (there are registers and caches in the processor, then these data are the context data of the process)

IO status information : a list of files occupied by process IO operations (in Linux, all information exists in the form of files , such as the disks we operate, the memory or files we operate, are stored in the form of files IO status information)

Accounting information : CPU time used by the process , or the total number of clocks

The above process control block information can be summarized into the following four categories:
image
these are the forms of processes in main memory

Process Control Block (PCB)

The process control block is the most important content in the process , so what is the process control block ?

  • A general data structure used to describe and control the operation of a process (each process has a process control block)
  • Record the current state of the process and all information about the operation of the control process
  • PCB is the basic unit that enables processes to run independently (that is, each process relies on the process control block to be scheduled by the operating system , or controlled)
  • PCB is information that is often read during scheduling by the operating system, so PCB is resident in memory and stored in the PCB area specially developed by the system

Process and thread

The difference between process and thread

image

For a process, there may be multiple threads executing in it, which means that there is a one-to-many relationship between a process and a thread, and a process can have multiple threads

So how are the threads in the process defined?

A thread is the smallest unit of operating system scheduling (recall what is a process: a process is the basic unit of system resource allocation and scheduling ), one is the smallest unit of scheduling, and the other is the basic unit of scheduling, meaning: operating system pair Process scheduling is actually scheduling of threads in the process

Thread is included in the process, which is the unit that actually runs the work in the process . That is to say, the logic in the process actually runs the thread in the process, not the process.
A process can have multiple threads concurrently, and each thread executes differently. Task. If a process is compared to a relatively large task, then multiple threads can complete different tasks in the process separately, so that multiple threads run faster, which is also the advantage of multiple threads in one thread

In the previous introduction, the process is the basic unit of the operating system for resource allocation , that is to say, a process has considerable resources, and the thread does not own the resources, but shares the resources of the process, so the threads share the resources of the process

image

Suppose there are three threads in a process, thread 1, thread 2, thread 3, these three threads all use the resources allocated by the threads, that is to say, these three threads share the resources of the process

Compare processes and threads:
image

Because the process needs to manage multiple processes and allocate related resources , its system overhead is relatively large. Communication is inter-process communication ( IPC ) for processes , while for threads, it communicates by reading and writing data from the same process. For example, for example, there are two threads in a process. Thread 1 can write in a certain area in the process resources [After I finish processing, how much data is equal to], then thread 2 can also read this area and put The corresponding data is read. At this time, thread 1 and thread 2 communicate by reading and writing process data

It is the core competitiveness of a technical person to find the constant in the rapidly changing technology. Unity of knowledge and action, combining theory with practice

image

Standing on the shoulders of giants and learning, paying tribute to the predecessors
Reference: https://coding.imooc.com/class/355.html

Guess you like

Origin blog.csdn.net/self_realian/article/details/106957180