Skip to content

Processes & Threads

A process is an independent program in execution with its own memory space. A thread is a lightweight unit of execution within a process, sharing the same memory. Processes are isolated (safer), threads share memory (faster communication but need synchronization). Context switching between processes is costly; between threads, less so. Modern systems use multi-threading for concurrency within a process.

Key Concepts

Deep Dive: Process vs Thread
Feature Process Thread
Memory Own address space Shared with process
Creation cost High Low
Context switch Expensive Cheaper
Communication IPC (pipes, sockets) Shared memory
Crash impact One process only Can crash entire process
Isolation Full None (shared memory)
Deep Dive: Process States
New → Ready → Running → Waiting → Ready → ...
            Terminated
State Description
New Process created
Ready Waiting for CPU
Running Executing on CPU
Waiting Blocked on I/O or event
Terminated Execution complete
Deep Dive: Inter-Process Communication (IPC)
Method Description Use Case
Pipes One-way byte stream Parent-child processes
Message Queues Structured messages Decoupled communication
Shared Memory Shared memory region Fastest IPC
Sockets Network communication Distributed systems
Signals Asynchronous notifications Process control
Common Interview Questions
  • What is the difference between a process and a thread?
  • What is context switching?
  • What are user threads vs kernel threads?
  • What is IPC? Name some methods.
  • What is a zombie process? Orphan process?