Process and thread the differences and connections

Original from Baidu experience

I am here only when the beat is to practice typing, and then focus on when they think red mark

https://jingyan.baidu.com/article/624e74598efcc834e9ba5a66.html

A thread is introduced in order to reduce overhead time and space program, when executed concurrently paid.

Attributes:

  1. Light entities. It does not have the system resources, just a little essential to ensure that resources independently.
  2. The basic unit of scheduling and dispatching of independence. In a multithreaded OS, the thread is the basic unit operate independently, thus also independent of the scheduling and dispatch of the basic unit, but because the thread is very light, so switching threads quickly and very little overhead.
  3. It can be executed concurrently. You can execute concurrently across multiple threads in a process, or even allow all the threads in a process can be executed concurrently; Similarly, different threads in the process can be executed concurrently.
  4. Shared process resources. Various threads in the same process can share the resources owned by the process, which first manifested in: All threads have the same address space (process's address space), which means that threads can access the address space each virtual address; You can also access the file has been opened, timers, semaphores owned by institutional processes and so on.

Process is a program having individual functions, run on a data collection activity . It can apply to have the systems and resources, it is a dynamic concept . It is a living body. It is not only the program code further comprising a current activity represented by a processing register contents and the value of the program counter.

Process is an "execution procedures." Program is a lifeless entity, only the processor attached to the program of life, he can become an entity of an activity , we call for the process .

Generally it can contain several threads in a process that can take advantage of the resources owned by the process. In the introduction of the thread operating system, usually the process as the basic unit of resource allocation, and the thread as a basic unit operate independently and scheduled separately . Since the thread is smaller than the process, basically it does not have the system resources, so its schedule will pay the cost of the smaller, higher degree of internal energy to improve the system across multiple programs concurrently executing.

The difference between threads and processes is that the child and parent processes have different code and data space, while the multiple threads share data space, each thread has its own execution stack and program counter to its execution context. Multithreading is mainly to save cpu time, using the play, as the case may be. Running threads need to use the computer's memory resources and cpu.

The difference between threads and processes are summarized:

a: address space and other resources: inter-process independent of each other, among the threads of the same process of sharing. Threads within a process is not visible in the other process.

b: Communication: inter-process communication ipc, between threads can read and write directly process data segment (such as global variables) to communicate - need aid process synchronization and mutual exclusion means to ensure data consistency.

c scheduling and switching: thread context switching than the process context switch much faster.

In multi-threaded os, the process is not an executable entity.

Process is a program with a certain individual functions on a set of data on the activities of the first run, the system process is an independent unit of resource allocation and scheduling. A thread is a physical process, is the basic unit of CPU scheduling and dispatching, which is smaller than the process of the basic unit can operate independently. Basically thread does not own its own system resources, has only a little in the operation of essential resources (such as a program counter, a set of registers and stack), but it may have to share the process with other threads belonging to the same process of all resources .

definition:

First, the process is a program with a certain separate functions run on one activity on a data collection system is an independent unit of resource allocation and scheduling.
Second, the thread is a physical process, is the basic unit of CPU scheduling and dispatching, he is smaller than the process of the basic unit can operate independently, basically does not own its own thread system resources, with only essential point in the operation resources (e.g., program counter, a register set and stack), a thread can be created and destroyed another thread;

Processes and threads of relationship:

(1) a thread can belong to only one process, and a process can have multiple threads, but there is at least one thread.
(2) the resources allocated to the process, all threads in the same process of sharing all the resources of the process.
(3) threads in the implementation process, the need to work in sync. Between threads of different processes to make use of synchronized way messaging.
(4) points to the thread handling machine, i.e. the real processors running on a thread.
(5) a thread refers to a scheduling entity within the process execution unit, but also the process.
The difference between threads and processes:
(1) Scheduling: the thread as a basic unit of scheduling and allocation, process as the basic unit of own resources.
(2) Concurrency: concurrent execution process can not only between but also can execute concurrently across multiple threads of the same process.
(3) have the resources: the process is an independent unit with the resources, the thread does not have the system resources, but can access resources belong to the process.
(4) overhead: when creating or revocation process, due to system resource allocation and deallocation of whom have led to significantly greater than the cost of creating or revoked when the thread system. But the process has a separate address space, the process crashes, will not have an impact on other processes in protected mode, but just different threads of execution paths in a process. Thread has its own stack and local variables, but there is no separate address spaces between the threads, a thread to die is tantamount to the whole process dies, so the program than multi-process multi-threaded programs robust, but in the process of switching, consuming greater resource efficiency to be satisfactory.

Division of thread scales smaller than the process, so that multithreaded programs concurrency high.

In addition, the process has a separate memory unit in the implementation process, and multiple threads of shared memory, which greatly improves the efficiency of the program.

During execution threads, each thread has a separate inlet for running, and a program execution sequence order outlet. But the thread is not able to execute independently, must exist in accordance with the application, there are applications to provide multiple threads of execution control.

From a logical standpoint, multithreaded meaning with a sub ah application execution section may perform a plurality of simultaneously. But the operating system will not be seen as multiple threads multiple independent applications to achieve scheduling and management and resource allocation processes. This is an important difference between processes and threads.

Guess you like

Origin www.cnblogs.com/littleswan/p/11369737.html