[OS] Program/Process/Thread
1 min readDec 28, 2021
Program
- The executable file or code that we define in IDE and editor.
- Program would not be loaded into the primary memory until it was executed.
Process
- Process is an executing instance of a program, and would be loaded into the primary memory.
- The OS helps to create, schedule, and terminate the processes which is used by CPU.
- Each process are independent, and they would not share the memory.
- The other processes created by the main process are called child process.
- Inter process communication is slow as processes have different memory address.
- Context switching between the process is more expensive, because it involves OS resource.
Thread
- Thread is the smallest executable unit of a process.
- Threads in the same process share memory of that process.
- Inter thread communication is fast as threads in the same process share the same memory address.
- Context switching between threads in the same process is less expensive.
- If two threads access or change the same resource at the same time, synchronization or deadlock problems may occur.