Process refers to an application that is running in the system. Once the program is running, it is a process. For example, open a QQ music is to start a QQ music process, open a Word will start a Word process. A process is the smallest unit of resources allocated by the operating system. As shown below, each process has its own memory unit.
Within a process, you can run multiple “subtasks,” or threads, simultaneously. As shown above, in one process, while multiple threads share memory. A thread is the smallest unit of program execution within a process.
A process can be thought of as an assembly line in a factory, where the threads are the workers on the assembly line.
If we need to complete a batch of a series of certification before drugs leave the factory inspection, we can open a line (process), and allocate resources needed, such as the workbench, inspection tools, drugs and so on, with these resources, you can arrange workers (thread), workers take these resources for product inspection, also is the equivalent of threads execute a program.
As shown in the figure above, there are four steps to complete the inspection: raw material inspection, manufacturing process inspection, GMP certification, and drug supervision and administration. When the number of drugs to be tested is small, these four steps, or single-threaded processing, can be completed by a single worker.
When the number of drugs becomes too large, one worker is too slow. In this case, one worker can be arranged for each kind of test. These four workers work on the same production line, share resources such as workbench, and process their tasks in parallel, which is equivalent to multi-threading.
In short, the relationship between processes and threads has the following characteristics:
-
Threads must exist in processes, and a process has at least one thread —- Workers need to work on the assembly line, and at least one worker is needed to complete validation.
-
Any thread execution error in the process will lead to the collapse of the entire process —- any circuit in the pipeline short circuit, the entire pipeline will be outage.
-
Threads share data in the process —- Workers share tools, resources, and so on on the pipeline.
-
When a process is shut down, the operating system will reclaim the memory occupied by the process —- once the inspection is completed, the factory can shut down the pipeline, and the resources of the pipeline will be recovered and allocated to other pipelines.
-
The content between processes is isolated —- The resources and tasks of the two pipelines are independent.