The difference between processes and threads (finishing)

Overall concept: the process is the basic unit of the operating system resource allocation, and the thread is the basic unit of task scheduling and execution of

In essence: Process and thread is a description of the time period, is to describe the work of CPU time, but different particle sizes.

  Let me talk about the process:

    background:

      ① on the computer system: CPU + RAM + various resources (such as graphics cards, optical drives, keyboard, GPS, etc. peripherals) constitute our computers, but the operation of the computer, is actually a matter between the CPU and associated registers and RAM.

      ② fact 1: CPU too fast, the register can only catch on in his footsteps, RAM, and other hanging on each bus device is completely offer. When multi-task execution, CPU always turns to perform those tasks.

      ③ Facts 2: CPU when executing a task, you need to load the task context of the program, and then execute, and finally save the application context (for next time to continue to perform the task load).

    In summary: the process is a context switch includes a program execution total time = CPU + CPU loader context + CPU executes the program stored program context

  Besides threads:

    A vivid metaphor: the process of particle size is too large, every time there is a context transferred, stored, recalled. If we put a process likened to a software running on the computer, then execute software can not be executed by a logic, there must be multiple branches and multiple program segments, like to implement the program A, actually divided into a, b , c, etc. a combination of a plurality of blocks. This specific implementation may become: Procedure A to give CPU = "CPU load context, subparagraph starts executing a program A, and then perform the A subparagraph b, then c subparagraph A is performed, and finally to save the context A the CPU.

    It is noted that: performing a, b, c are here of shared context A, CPU context switching is not performed during execution. This is where a, b, c is the thread, that thread is a shared process context, more small CPU time.
    Personal understanding: the introduction of the thread, essentially for efficient use of computing resources of multicore.
  
   The following summarizes some of the differences:

    In terms of overhead: each process has its own code and data space (application context), switching between programs have larger overhead; thread can be seen as lightweight processes, threads share the same type of code and data space each thread has its own independent runtime stack and program counter (PC), small switches between threads overhead.

    The environment: run multiple processes (programs) in the operating system at the same time; and there are multiple threads in the same process (program) simultaneously perform (by CPU scheduling, the film has only one execution thread at each time)

    Memory allocation: When the system is running a different memory space will be allocated for each process; and thread, in addition to the CPU, the system will not (from that resource belongs to the process of resource thread used) to allocate memory for the thread You can share resources, thread group.

    Containment relationship: the process is the thread of the container, if there are multiple threads within a process, perform the procedure is not a line, but a plurality of lines (threads) together to complete; the thread is part of the process, it is also known as the thread lightweight processes or lightweight processes.

————————————————

References:
1 The main difference between processes and threads (summary) https://blog.csdn.net/kuangsonghan/article/details/80674777

What is the difference between 2 threads and processes are? - zhonyong answer - know almost https://www.zhihu.com/question/25532384/answer/81152571

Guess you like

Origin www.cnblogs.com/x-x-736880382/p/11386641.html