Classic Comparison Questions

Quick Reference (TL;DR)

Process vs Thread: Process = isolated address space, Thread = shared address space. Process context switch ~1-10 μs, Thread ~100-1000 ns.

Mutex vs Semaphore: Mutex = mutual exclusion (one thread), Semaphore = resource counting (N threads). Mutex has ownership, semaphore doesn't.

Deadlock vs Starvation: Deadlock = all blocked (circular), Starvation = some blocked (low priority). Deadlock permanent, starvation temporary.

Paging vs Segmentation: Paging = fixed size, Segmentation = variable size. Modern = paged segmentation.

Kernel Thread vs User Thread: Kernel = OS-managed, User = library-managed. Kernel = true parallelism, User = no parallelism (unless M:N).


1. Clear Definition

Classic Comparison Questions are fundamental distinctions that interviewers use to test deep understanding. These appear frequently in FAANG interviews.


2. Core Concepts

Process vs Thread

AspectProcessThread
Address SpaceIsolatedShared
MemorySeparateShared
Context Switch~1-10 μs~100-1000 ns
CreationExpensiveCheap
CommunicationIPC (complex)Shared memory (simple)
Crash ImpactOwn processEntire process
IsolationStrongWeak
Use CaseIsolation neededParallelism needed

Key Insight: Process = isolation, Thread = parallelism within process.

Mutex vs Semaphore

AspectMutexSemaphore
PurposeMutual exclusionResource counting
ValueBinary (0/1)Counting (0-N)
OwnershipYes (only holder unlocks)No
Use CaseProtect critical sectionLimit resource access
ReentrantCan beNo

Key Insight: Mutex = one thread, Semaphore = N threads.

Deadlock vs Starvation

AspectDeadlockStarvation
StateAll blockedSome blocked
CauseCircular waitLow priority
PermanencePermanent (until broken)Temporary (may eventually get resource)
AffectedAll in deadlockLow-priority processes
SolutionBreak cyclePriority aging

Key Insight: Deadlock = all stuck, Starvation = some stuck.

Paging vs Segmentation

AspectPagingSegmentation
SizeFixedVariable
StructureArbitraryLogical (code, data, stack)
FragmentationInternalExternal
AllocationSimpleComplex
ProtectionPer pagePer segment
Modern UsePrimaryCombined with paging

Key Insight: Modern = paged segmentation (segmentation for protection, paging for management).

Kernel Thread vs User Thread

AspectKernel ThreadUser Thread
ManagementOS kernelLibrary/runtime
SchedulingOS schedulerLibrary scheduler
ParallelismYes (multiple cores)No (one kernel thread)
Context SwitchSystem callUser space (fast)
BlockingOne thread blocksAll threads block
OS AwarenessYesNo

Key Insight: Kernel = OS-managed (parallelism), User = library-managed (no parallelism).

Blocking vs Non-blocking

AspectBlockingNon-blocking
BehaviorWaits for operationReturns immediately
Thread StateBlocked (sleeps)Ready (continues)
CPU UsageGives up CPUKeeps CPU
Use CaseI/O operationsEvent loops

Key Insight: Blocking = wait, Non-blocking = return immediately.

Synchronous vs Asynchronous

AspectSynchronousAsynchronous
ExecutionSequentialConcurrent
WaitingWaits for completionContinues, notified later
ReturnReturns resultReturns immediately, callback later

Key Insight: Synchronous = wait for result, Asynchronous = callback/notification.

Spinlock vs Mutex

AspectSpinlockMutex
WaitingBusy-wait (spins)Blocks (sleeps)
CPU UsageWastes CPUGives up CPU
OverheadLow (no context switch)Higher (context switch)
Use CaseShort critical sectionsLonger sections
ContentionLowHigh

Key Insight: Spinlock = busy-wait (fast for short), Mutex = block (efficient for long).

Cache vs Buffer

AspectCacheBuffer
PurposeSpeed up accessSmooth data flow
ContentFrequently used dataTemporary storage
LifecyclePersistentTemporary
LocationMultiple levelsSingle location
ExampleCPU cache, file cacheI/O buffer, print buffer

Key Insight: Cache = speed (frequently used), Buffer = flow (temporary storage).

VM vs Container

AspectVirtual MachineContainer
KernelSeparate (each VM)Shared (host)
IsolationStrongWeaker
OverheadHighLow
StartupSlow (minutes)Fast (seconds)
Use CaseDifferent OSes, strong isolationSame OS, efficiency

Key Insight: VM = strong isolation, Container = efficiency.


3. Use Cases

These comparisons help choose the right approach for different scenarios.


4. Advantages & Disadvantages

See comparison tables above.


5. Best Practices

  1. Understand trade-offs: Each has pros/cons
  2. Choose appropriately: Based on requirements
  3. Know when to use each: Context matters

6. Common Pitfalls

⚠️ Mistake: Confusing similar concepts

⚠️ Mistake: Not understanding trade-offs

⚠️ Mistake: Memorizing without understanding


7. Interview Tips

Common Questions:

  • "Compare X vs Y" (any of the above)
  • "When would you use X vs Y?"
  • "What are the trade-offs?"

Answer Structure:

  1. Define both clearly
  2. Compare key aspects (table format)
  3. Explain trade-offs
  4. Give use cases

All topics covered in previous sections.


9. Visual Aids

See individual topic sections for diagrams.


10. Quick Reference Summary

Key Comparisons:

  • Process vs Thread: Isolation vs Parallelism
  • Mutex vs Semaphore: One vs N
  • Deadlock vs Starvation: All vs Some
  • Paging vs Segmentation: Fixed vs Variable
  • Kernel vs User Thread: OS vs Library
  • Blocking vs Non-blocking: Wait vs Return
  • Synchronous vs Asynchronous: Sequential vs Concurrent
  • Spinlock vs Mutex: Busy-wait vs Block
  • Cache vs Buffer: Speed vs Flow
  • VM vs Container: Isolation vs Efficiency