The difference between threads & processes:
What is a Process?
- A process is the execution of a program that allows you to perform
the appropriate actions specified in a program. - It can be defined as an execution unit where a program runs.
- The OS helps you to create, schedule, and terminates the processes
which is used by CPU. - The other processes created by the main process are called child
process.
What is Thread?
- Thread is an execution unit that is part of a process.
- A process can have multiple threads, all executing at the same time.
- It is a unit of execution in concurrent(同时) programming.
- A thread is lightweight and can be managed independently by a scheduler.
- It helps you to improve the application performance using parallelism.
Process: Refers to an application program running in the system; once the program runs, it is a process;
process-the smallest unit of resource allocation.
Thread: The basic unit that the system allocates processor time resources, or a unit execution flow that executes independently within a process.
Thread-the smallest unit of program execution.
summary:
1. The process needs to allocate a large part of the memory, and the thread only needs to allocate a part of the stack.
2.A program has at least one process, and a process has at least one thread.
3. The process is the smallest unit of resource allocation, and the thread is the smallest unit of program execution.
4. One thread can create and cancel another thread, and multiple threads in the same process can execute concurrently.