This is very basic but one of the important concept need to understanding, below are the some difference b/w process and thread
- Process is a program which is executing some code and a thread is an independent path of execution in the process.
- A process can have more than one thread for doing independent task.
- All thread from a process share same address space but a process has their own address space
- Context switching between processes is more expensive than context switching between threads.
All threads from the same process share memory space of the process that created it, on the other hand, each process has their own address space.
Threads can directly communicate with other threads of the same process. Many programming language e.g. Java provides tools for inter-thread communication (wait, notify, notifyAll methods). It’s much cheaper than inter-process communication, which is expensive and limited.
Threads have less overhead compared to Process in terms of metadata, context switch and CPU and memory requirement.
New threads can be easily created e.g. in Java you can create a new Thread by creating an object of Thread class and calling start() method on it, while new process requires duplication of the parent process.
Changes to the parent thread e.g. cancelation, priority, the daemon may affect the behavior of the other threads of the process, but changes to the parent process do not affect child process.
A thread cannot exist without process. Also, a process, at least, has one thread to do the job e.g. main thread for Java programs
Since all threads from the same process share same address space, inter-thread communication and context switching between them are much faster than inter-process communication and context switching between process.