This article was reproduced from: https://www.ezloo.com/2007/10/thread_process_program.html
My thread, process concept has been relatively vague, recently tidied up a bit. In summary, a thread is part of a process, and a process is part of the program.
Threading Introduction: For example, there is a way for a Web server to process Web Access requests from different users in a way that can create a parent process and multiple child processes, but it takes a large amount of overhead and resources to create a process. Except that these different user sub-processes involve process context switching at execution time, and context switching is a complex process. Therefore, in order to reduce the cost of process switching and creation, improve execution efficiency and save resources, people introduced the concept of "thread" in the operating system.
The role and definition of the process: the process is designed to improve the efficiency of the CPU execution, reduce the CPU idling due to the program waiting and the waste of other computer hardware and software resources. A process is an execution of a program segment that has a separate function that performs an activity on a dataset in order to complete the execution of a program that is required by a user task and to assign resources to it.
The difference between threads and processes:
1. Threads are part of a process, so threads are sometimes referred to as light weight processes or lightweight processes.
2, a non-threaded process can be considered single-threaded, if a process has more than one process, the process of execution is not a line (thread), but a number of lines (threads) to do together.
3. The system allocates a different memory area for each process at run time, but does not allocate memory for the thread (the resource used by the thread is the resource of the process it belongs to), and the thread group can only share resources. That is to say, out of the CPU (thread at run time to consume CPU resources), the computer's internal hardware and software resources allocated to the thread-independent, the thread can only share the resources of the process it belongs to.
4, similar to the Process Control table PCB, the thread also has its own control table TCB, but the TCB is saved in the state of the thread is much less than the PCB table.
5, the process is the system of all resource allocation when a basic unit, with a complete virtual space address, not dependent on the thread and independent existence.
The difference between a process and a program:
A program is a set of instructions, a static entity that has no meaning to execute. The process is a dynamic entity that has its own life cycle. Generally speaking, a process must correspond to a program, and only one, but a program can have multiple processes, or a process does not have or can have only one process. In addition, the process also has concurrency and communication. Simply put, a process is a part of a program that produces a process when it runs.
Summarize:
A thread is part of a process, and a process is part of a program.
Simple comparison of threads, processes, and programs "Go"