Thursday, December 19, 2019

Difference between Process and Thread

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:
Comparison BasisProcessThread
DefinitionA 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 timeProcesses 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 SharingProcesses are totally independent and don’t share memory.A thread may share some memory with its peer threads.
CommunicationCommunication between processes requires more time than between threads.Communication between threads requires less time than between processes .
BlockedIf 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 ConsumptionProcesses require more resources than threads.Threads generally need less resources than processes.
DependencyIndividual processes are independent of each other.Threads are parts of a process and so are dependent.
Data and Code sharingProcesses have independent data and code segments.A thread shares the data segment, code segment, files etc. with its peer threads.
Treatment by OSAll 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 creationProcesses require more time for creation.Threads require less time for creation.
Time for terminationProcesses require more time for termination.Threads require less time for termination.

No comments:

Post a Comment