Understanding and difference between process and thread

concept

Process: the smallest unit of resource allocation
Thread: the smallest unit of program operation (the smallest unit of resource scheduling )

  • A process has its own address space . When a process is established, the system allocates an address space for it. The threads share the data and memory addresses of the process and use the same address space.

  • A process can contain multiple threads, but there is at least one thread.

  • The death of a process does not affect other processes. Processes are independent of each other , but if a thread dies, the entire process is dead.

  • Communication between threads is more convenient. Threads in the same process share global variables, static variables, etc., while inter-process communication needs to be carried out in IPC mode.

the difference

A thread refers to an execution unit within a process, and is also a schedulable entity within a process.

The difference with the process:

  1. Scheduling: thread as the basic unit of scheduling and allocation, process as the basic unit of resources
  2. Concurrency: processes can be executed concurrently to complete multitasking operations, and multiple threads of the same process can also be executed concurrently
  3. Owning resources: A process is an independent unit that owns resources. A thread does not own system resources, but can access resources belonging to the process and share process resources
  4. System overhead: When creating and destroying a process, the system has to allocate and reclaim resources for it, resulting in a system overhead that is significantly greater than that of creating or canceling threads.

Guess you like

Origin blog.csdn.net/qq_30722795/article/details/108159587