first, the process 1. Concept
A program is an ordered set of instructions . A process is a running activity on a data set by a program with a certain independent function . is a system for resource allocation and scheduling of an independent unit.
The program itself does not have any meaning to run, just a static entity. The process is different, it is the execution of a program on a data set, is a dynamic entity. It is created because it is scheduled to run, waiting for a resource or event to be in the waiting state, because the completion of the task is undone, reflecting a program on a certain set of data run on the entire dynamic process.
2. Characteristics
(1) Structural
processes contain programs and their related data structures . The entity of a process contains process control blocks (PCBS), blocks, blocks, and stacks, also known as process images
(2) dynamic Nature
A process is a process of execution of a program on a data set, which has a life cycle , which is generated by creation, run by schedule, and dies out by the end, which is a dynamic and changing process. And the program is not, the program is a file, static and persistent existence.
(3) Independence
A process is the basic unit of operating system resource allocation, protection, and dispatch, and each process has its own set of running data that runs asynchronously at its own independent, unpredictable schedule. The running environment of the process is not closed, and the process can share data and communicate with the operating system.
(4) Concurrency
during the same period of time. Several processes can share a single CPU. the concurrency of the process can improve the resource utilization of the system and improve the efficiency of the computer. The process executes concurrently in a single CPU system and executes in parallel in a multi-CPU system. Concurrent execution of a process means that the execution of the process can be interrupted, potentially causing some unexpected problems, and therefore the process of concurrent execution must be reconciled.
second, the thread 1. Concept
A thread is a child task that can be executed independently in a process . Sometimes called a lightweight process (lightweight PROCESS,LWP), is the smallest unit of program execution flow.
2. Advantages
(1) easy to dispatch.
(2) Improve concurrency.
Concurrency can be easily and efficiently achieved through threading. A process can create multiple threads to perform different parts of the same program.
(3) less overhead.
Creating a line turndown creates a process that is fast and requires little overhead.
(4) Facilitate the full use of multi-processor functions.
By creating a multithreaded process (that is, a process can have two or more threads), each thread runs on a single processor, enabling the concurrency of the application so that each processor is fully operational
Third, Comparison 1. relationship of processes and threads
(1) A thread can belong to only one process, while a process may have multiple threads, but at least one thread.
(2) A resource is allocated to a process, and all the threads of the same process share all the resources of that process.
(3) The processor is assigned to a thread, that is, a thread that is actually running on the processing machine.
(4) Threads need to be synchronized during execution. Synchronization is achieved between threads of different processes using the means of message communication.
2. the difference between a process and a thread:
(1) Dispatch: The thread acts as the basic unit of dispatch and allocation, and the process as the basic unit of resources
(2) Concurrency: not only can concurrent execution between processes, but also concurrent execution between multiple threads of the same process
(3) Owning a resource: a process is an independent unit that owns resources, and threads do not own system resources, but they can access resources that belong to the process.
(4) Overhead: When you create or revoke a process, the overhead of the system is significantly greater than the cost of creating or revoking a thread, because the system allocates and reclaims resources for it.
Summary: The process is introduced to improve the utilization of resources, and can correctly describe the execution of the program. Threading is introduced to avoid some of the shortcomings of the process, such as large overhead, slow speed, scheduling is more complex. The fundamental difference between a process and a thread is that the process is a resource allocation unit, and the thread is the dispatch and execution unit.
Suppose a hotel has 10 rooms, and if a waiter is hired to serve all the rooms, then we can take the hotel from opening to closing as a process, and the waiter serves all the rooms as a thread, at which point the thread is monopolizing all the resources of the hotel. Now the hotel recruit three waiter, at this time the equivalent of multi-threading, these attendants shared the hotel's resources, independent operation independently of each other. This is the process and thread.
Soft Test road--process and thread