What is a Process?
- A set of instructions
- Process has an isolated memory which can be accessed by only the process and its children.
- Process has a PID (Process Identifier)
- It gets scheduled in the CPU.
What is a Thread?
- It's a light weight process.
- It's also a set of instructions.
- It shares memory with its parent process.
- It has a unique ID.
- It also gets scheduled in the CPU.
Multi-Processes
- App has multiple processes
- Each has its own Memory
- Examples NGINX/Postgres
- Take advantage of multi-cores
- More memory but isolated
- Redis backup routine (COW)
Multi-Threaded
- One Process, multiple threads
- Shared Memory (compete)
- Take advantage of multi-cores
- Require less memory
- Race conditions
- Locks and Latches (SQL Server)
- Examples Apache, Envoy
Tips
Number of Cores = Number of Processes can work in parallel