The introduction

The second part of this article, Process Entities for process management, will familiarize you with why processes are used and what process entities are

Why process

As we know from the previous article, the basic function of an operating system is to manage the underlying hardware resources, including the following parts

With the operating system, these resources can be easily managed. Suppose there were no operating systems, how would these computer resources be managed? Before the OS is configured, resources only belong to the currently running program, and the computer can only run one program. At this time, because of some resources, the current running program can not be fully reasonable utilization, so the concept of multi-program is introduced, and related OS is configured. After the operating system, the process appeared, the role of the process is reasonable isolation of resources, running environment, improve the utilization of resources

Process is the basic unit of the system of resource allocation and scheduling (the concept of a multiprogramming operating system of each program can be the allocation of resources) process as a carrier of the program run independently, guarantee normal execution procedure (because the concept of a multiprogramming, so there may be multiple processes in computer is common to use a physical device, such as memory. So the process in this is to play the role of running resource isolation) the existence of the process, the operating system resource utilization greatly improved (this also depends on the concept of multi-programming)

Therefore, for these reasons, operating systems need processes to run properly and efficiently

2. Process entities

The shape of a process in main memory

In main memory, a process is also a contiguous piece of storage calledProcess control blockThere are some important information in the process control block, such as identifiers, status, priorities, program counters, memory Pointers,Context data, IO status information, accounting information and so on some important information

Identifier: A symbol that uniquely identifies a process to distinguish it from other processes. The common process ID, for example, is the unique identifier

Status: Indicates the process status of a process. Such as running or blocked state

Program counter: Address of the next instruction to be executed by the process

Memory pointer: a pointer to program code or process data. There may be multiple memory Pointers to specific logical code for the program or to addresses associated with the execution process data

Context data: This is an important area of the process control block. This area stores the data stored by the processor during the execution of the process (if there are registers and caches in the processor, this data is the context data of the process).

IO status information: a list of files that are occupied by process I/O operations. (In Linux, all information exists in the form of files, such as the disk we operate on, the memory we operate on, or the files we operate on, which are stored in the IO status information as files.)

Billing 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: These are the forms of processes in main memory

Process control block (PCB)

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

  • A common data structure for describing and controlling the execution of processes (each process has a process control block)
  • Record the current status of the process and all the information that controls the process running
  • The PCB is the basic unit that allows a process to run independently (that is, each process depends on a process control block to be scheduled, or controlled, by the operating system)
  • PCB is the information often read by the operating system for scheduling, so PCB is resident in memory, stored in the PCB area specially opened by the system

Processes and threads

The difference between processes and threads


In the case of a process, there may be multiple threads executing in it, which means that the process has a one-to-many relationship with threads. A process can have multiple threads

What about threads in a process?

Threads are the smallest units of the operating system to run scheduling (recall what is the process: the process is the basic unit of the system of resource allocation and scheduling), a is the minimum unit of scheduling, one is the basic unit of the schedule, which means: operating system process scheduling, is actually the process of inside thread scheduling

A thread is contained in a process and is the unit of work that actually runs in the process. That is to say, it is the thread in the process that actually runs the logic in the process, not the process. A process can have multiple concurrent threads, each thread performing different tasks. If a process is compared to a relatively large task, then multiple threads can complete different tasks in the process, so that multiple threads run faster, which is also the benefit of having multiple threads in one thread

As described above, a process is the basic unit of resource allocation in the operating system. That is to say, a process has considerable resources, while threads do not own resources, but share the resources of the process, so threads share the resources of the process


Suppose there are three threads in a process: thread 1, thread 2, and thread 3. All three threads use resources allocated by the thread. That is, they share the resources of the process

Compare processes and threads:

Because a process needs to manage multiple processes and allocate related resources, its system overhead is high. Communication, in the case of a process, is interprocess communication (IPC), while in the case of a thread, it communicates by reading and writing data from the same process. For example, for example, a process is punctuated with two threads, thread 1 can be in the process of resources inside a certain area to write after I complete the processing, the data is equal to how much 】 【, next, thread 2 can also read the area, the corresponding data read out, the thread thread 1 and 2 of data communication is through reading and writing process

It is the core competitiveness of a technician to seek invariance in the rapidly changing technology. Unity of knowledge and practice, theory and practice


Standing on the shoulders of giants to study, salute to predecessors reference: https://coding.imooc.com/class/355.html