A process is an active program i.e. a program that is under execution. It is more than the program code as it includes the program counter, process stack, registers, program code etc. Compared to this, the program code is only the text section.
A thread is a lightweight process that can be managed independently by a scheduler. It improves the application performance using parallelism. A thread shares information like data segment, code segment, files etc. with its peer threads while it contains its own registers, stack, counter etc.
The major differences between a process and a thread are given as follows −
|Definition||A process is a program under execution i.e an active program.||A thread is a lightweight process that can be managed independently by a scheduler.|
|Context switching time||Processes require more time for context switching as they are more heavy.||Threads require less time for context switching as they are lighter than processes.|
|Memory Sharing||Processes are totally independent and don’t share memory.||A thread may share some memory with its peer threads.|
|Communication||Communication between processes requires more time than between threads.||Communication between threads requires less time than between processes .|
|Blocked||If a process gets blocked, remaining processes can continue execution.||If a user level thread gets blocked, all of its peer threads also get blocked.|
|Resource Consumption||Processes require more resources than threads.||Threads generally need less resources than processes.|
|Dependency||Individual processes are independent of each other.||Threads are parts of a process and so are dependent.|
|Data and Code sharing||Processes have independent data and code segments.||A thread shares the data segment, code segment, files etc. with its peer threads.|
|Treatment by OS||All the different processes are treated separately by the operating system.||All user level peer threads are treated as a single task by the operating system.|
|Time for creation||Processes require more time for creation.||Threads require less time for creation.|
|Time for termination||Processes require more time for termination.||Threads require less time for termination.|