Difference Between Process and Thread in OS
Difference Between Process and Thread in Operating System
A thread is a path of execution within a process. A process can contain multiple threads.
Process: A process is basically a program in execution. The execution of a process must progress in a sequential fashion. In computing, a process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.
Thread: Thread is an execution unit that consists of its own program counter, a stack, and a set of registers where the program counter mainly keeps track of which instruction to execute next, a set of registers mainly hold its current working variables, and a stack mainly contains the history of execution.
Difference Between Process and Thread in Operating System
Paramete | Process | Thread |
---|---|---|
Definition | Process means a program is in execution. | Thread means a segment of a process. |
Lightweight | The process is not Lightweight. | Threads are Lightweight. |
Termination time | The process takes more time to terminate. | The thread takes less time to terminate. |
Creation time | It takes more time for creation. | It takes less time for creation. |
Communication | Communication between processes needs more time compared to thread. | Communication between threads requires less time compared to processes. |
Context switching time | It takes more time for context switching. | It takes less time for context switching. |
Resource | Process consume more resources. | Thread consume fewer resources. |
Treatment by OS | Different process are tread separately by OS. | All the level peer threads are treated as a single task by OS. |
Memory | The process is mostly isolated. | Threads share memory. |
Sharing | It does not share data | Threads share data with each other. |