Operating System concepts: processes, threads, memory management, scheduling, and synchronization — essential for systems interviews.
5 Questions Detailed Answers
1What is the difference between a process and a thread?
Easy
View Answer
Process: independent program with own memory space, heavier to create (fork). Thread: lightweight unit within a process, shares memory space. Processes communicate via IPC (pipes, sockets). Threads share heap but have separate stacks. Multi-threading is faster but riskier (race conditions).
2Explain virtual memory and paging.
Medium
View Answer
Virtual memory lets programs use more memory than physically available. Pages (fixed-size blocks, typically 4KB) are mapped from virtual to physical addresses via page table. When a page isn't in RAM → page fault → OS loads it from disk (swap). Benefits: isolation, larger address space, memory sharing.
3What are the CPU scheduling algorithms?
Medium
View Answer
FCFS: first come, first served (convoy effect). SJF: shortest job first (optimal avg wait). Round Robin: time quantum rotation (good for interactive). Priority: highest priority first (starvation possible, solved with aging). MLFQ: multiple queues with feedback. Most modern OS use MLFQ/CFS variants.
4Explain mutex vs semaphore.
Hard
View Answer
Mutex: binary lock, only one thread can hold it. Owner must release it. Used for mutual exclusion. Semaphore: counting mechanism allowing N threads. sem_wait() decrements, sem_post() increments. Any thread can signal. Use mutex for exclusive access, semaphore for resource pools (e.g., connection pool of 10).
5What is thrashing?
Medium
View Answer
Thrashing occurs when the OS spends more time swapping pages than executing processes. Cause: too many processes competing for limited RAM → constant page faults. Solution: (1) Increase RAM, (2) Reduce degree of multiprogramming, (3) Use working set model, (4) Better page replacement algorithms (LRU).