SystemsOperating Systems
Process & Thread
Summary of differences between Process, Thread, and Context Switching
Process & Thread (Quick Summary)
1. Process
A Process is a Program that is currently executing in Memory.
- Resource Allocation: Each Process receives its own Memory Space (Isolated). If it crashes, it will not affect other Processes.
- Process Control Block (PCB): A Data Structure used by the OS to store the state of a Process (e.g., State, Program Counter, CPU Registers, Memory Limits).
- States:
New->Ready->Running->Waiting/Blocked->Terminated
2. Thread
A Thread is a sub-unit of processing within a Process.
- Shared Resources: Threads within the same Process share the same Memory Space (Code, Data, Heap) but have their own Stack and Registers.
- Advantages: Creation and Switching consume significantly fewer resources compared to Processes.
- Precautions: Because memory is shared, there is a risk of Race Conditions if Synchronization is not handled properly.
3. Context Switching
The process where the CPU stops executing one Process/Thread to switch to another.
- Mechanism: The OS saves the current state into the PCB (or TCB for Threads) and loads the state of the next item in the queue.
- Overhead: This is a high-cost operation because the CPU is not performing actual Computation during a context switch (Threads have lower overhead than Processes).