Process is a program execution process, is the basic unit of resource allocation in the process of execution, each process has its own address space, the process has at least five states: initial state, execution state, waiting state, ready state, termination state.


A thread is the basic unit of CPU scheduling and can share all resources with other threads in the same process


Threads are part of a process. A process can have multiple threads, but threads can only exist in one process.

The difference between:

  1. Fundamental differences: The process is the basic unit of resource scheduling in the operating system, and the thread is the basic unit of task scheduling
  2. Overhead: processes have their own independent data space, switching between programs is costly; Threads also have their own run stacks and program counters, making switching between threads less costly.
  3. Shared space: Processes have independent address Spaces and resources. Therefore, sharing is complicated. Inter-process Communication (IPC) is required, but synchronization is simple. Threads share the resources of the owning process, so sharing is simple, but synchronization is complex, and requires locking.

Trains and carriages

  • The thread runs under the process (simple carriages cannot run)
  • A process can contain multiple threads (a train can have multiple cars)
  • It is difficult to share data between different processes (passengers on one train are difficult to transfer to another train, such as station transfers)
  • It is easy to share data between different threads in the same process (it is easy to change car A to car B)
  • Processes consume more computer resources than threads (multiple trains are more expensive than multiple cars)
  • Processes do not interact with each other, and a thread failure causes the entire process to fail (one train does not affect the other, but if a middle car on a train catches fire, all trains will be affected)
  • Processes can be extended to multiple machines, processes are suitable for multiple cores at most (different trains can run on multiple tracks, cars of the same train cannot travel on different tracks)
  • The memory addresses used by processes can be locked, meaning that when one thread uses some shared memory, other threads must wait for it to finish before they can use it. (like a bathroom on a train) -” mutex”
  • The memory address used by the process can be limited (e.g. the restaurant on the train, the maximum number of people allowed to enter, if it is full, you have to wait at the door until someone comes out) – “semaphore”