Threads vs Processes in Linux

LinuxOperating SystemOpen Source

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 terminate the processes which are used by the CPU. The other processes created by the main process are called child processes.

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.

Consider the table shown below that depicts the differences between a process and a thread on different bases.

Comparison BasisProcessThread
DefinitionA process is a program under execution.Thread is the Execution unit.
Context switching timeProcesses require more time for context switching as they are heavier.Threads require less time for context switching as they are lighter than processes.
MemoryProcesses are totally independent and don’t share memory.Threads share memory.
CommunicationCommunication between processes requires more time than compared to threads.Communication between threads requires less time compared to processes .
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 OS.All user level peer threads are treated as a single task by the OS.
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.
raja
Published on 31-Jul-2021 12:17:40
Advertisements