Operating Systems Interview Questions — Set 1
25 OS interview staples — processes vs threads, scheduling, deadlock, paging and virtual memory — each with an interview-ready explanation.
One question at a time — answer, learn from the explanation, and keep your combo alive. Stuck? You have two 50:50s and one hint (each halves that question's XP).
Practice sheet: all 25 questions
Prefer reading first? Every question from this practice set, with the answer and a worked explanation. (Solving them in the practice set above earns XP — up to ≈150.)
-
Q1. What is a process?
- a. A program stored on disk
- b. A program in execution
- c. A compiled binary file
- d. A CPU scheduling algorithm
Show answer & explanation
Answer: B. A program in execution
A process is a program in execution — the program is passive code on disk; the process is that code loaded in memory with a program counter, registers, stack and heap. This one-line distinction opens most OS interviews.
-
Q2. Which structure does the OS use to store the state of each process (PID, program counter, registers, open files)?
- a. Page table
- b. Process Control Block (PCB)
- c. File Allocation Table
- d. Interrupt vector table
Show answer & explanation
Answer: B. Process Control Block (PCB)
The PCB is the kernel's per-process record: PID, process state, program counter, CPU registers, scheduling info, memory pointers and open-file handles. On a context switch, the CPU state is saved into and restored from the PCB.
-
Q3. What happens during a context switch?
- a. The CPU state of the running process is saved and another process's state is loaded
- b. A process is permanently terminated
- c. Memory is compacted to remove fragmentation
- d. The CPU switches from user code to a device driver
Show answer & explanation
Answer: A. The CPU state of the running process is saved and another process's state is loaded
A context switch saves the running process's registers and program counter into its PCB and loads the next process's saved state. It is pure overhead — the CPU does no useful user work during the switch — which is why too-frequent switching hurts throughput.
-
Q4. Threads of the same process share all of the following EXCEPT:
- a. Code section
- b. Heap memory
- c. Open files
- d. Stack and registers
Show answer & explanation
Answer: D. Stack and registers
Threads share the process's code, data, heap and open files, but each thread keeps its own stack and register set — that's what lets them execute independently. This shared/private split is the most-asked threads question in interviews.
-
Q5. Which of these CPU scheduling algorithms is non-preemptive?
- a. Round Robin
- b. Shortest Remaining Time First
- c. First Come First Served (FCFS)
- d. Preemptive Priority
Show answer & explanation
Answer: C. First Come First Served (FCFS)
FCFS runs each process to completion in arrival order — the CPU is never snatched away, so it's non-preemptive. Round Robin preempts on the time quantum, and SRTF/preemptive priority preempt whenever a better candidate arrives.
-
Q6. Which scheduling algorithm provably minimises average waiting time (when burst times are known)?
- a. First Come First Served
- b. Shortest Job First
- c. Round Robin
- d. Priority scheduling
Show answer & explanation
Answer: B. Shortest Job First
SJF is optimal for average waiting time: running short jobs first makes every queued process wait less. Its catch — burst times aren't known in advance in practice, and long jobs can starve — is the standard follow-up question.
-
Q7. Round Robin scheduling is characterised by:
- a. Running the longest job first
- b. Giving each process a fixed time quantum in turn
- c. Running processes strictly by priority
- d. Never preempting a running process
Show answer & explanation
Answer: B. Giving each process a fixed time quantum in turn
Round Robin cycles through the ready queue giving each process one time quantum — great for fairness and responsiveness in time-sharing systems. Quantum size is the trade-off: too small wastes time on context switches, too large degrades into FCFS.
-
Q8. Processes P1, P2, P3 arrive together in that order with burst times 24, 3 and 3 ms. Under FCFS, what is the average waiting time in ms?
Show answer & explanation
Answer: 17
Waiting times: P1 = 0, P2 = 24, P3 = 27 → average (0 + 24 + 27)/3 = 17 ms. This is the classic convoy effect — one long job in front inflates everyone's wait; scheduling P2 and P3 first would drop the average to 3 ms.
-
Q9. Which of the following is NOT one of the four necessary conditions for deadlock?
- a. Mutual exclusion
- b. Hold and wait
- c. Preemption
- d. Circular wait
Show answer & explanation
Answer: C. Preemption
The four Coffman conditions are mutual exclusion, hold-and-wait, NO preemption and circular wait. Preemption being possible actually breaks deadlock — the condition is its absence, and this inversion is exactly what the question tests.
-
Q10. The Banker's algorithm is used for:
- a. Deadlock detection
- b. Deadlock avoidance
- c. Deadlock recovery
- d. CPU scheduling
Show answer & explanation
Answer: B. Deadlock avoidance
The Banker's algorithm avoids deadlock by granting a resource request only if the resulting state is still "safe" — i.e. some order exists in which every process can finish. Avoidance decides before allocation; detection finds cycles after the fact.
-
Q11. A binary semaphore initialised to 1 is functionally most similar to:
- a. A mutex lock
- b. A condition variable
- c. A spin counter
- d. A message queue
Show answer & explanation
Answer: A. A mutex lock
A binary semaphore takes values 0/1 and enforces one-at-a-time access, just like a mutex. The interview-grade nuance: a mutex has an owner (only the locker may unlock), while any process may signal a semaphore.
-
Q12. A race condition occurs when:
- a. Two processes deadlock on the same resource
- b. The result depends on the unpredictable order in which processes access shared data
- c. The CPU runs faster than the memory bus
- d. A process exceeds its time quantum
Show answer & explanation
Answer: B. The result depends on the unpredictable order in which processes access shared data
A race condition is when correctness depends on interleaving — e.g. two threads doing x = x + 1 concurrently can lose one update because read-modify-write isn't atomic. The fix is mutual exclusion around the critical section.
-
Q13. Which of the following is NOT a requirement of a correct critical-section solution?
- a. Mutual exclusion
- b. Progress
- c. Bounded waiting
- d. Maximum CPU throughput
Show answer & explanation
Answer: D. Maximum CPU throughput
The three classical requirements are mutual exclusion, progress and bounded waiting. Throughput is a performance goal, not a correctness condition — a solution can be slow and still correct.
-
Q14. Paging eliminates which kind of fragmentation?
- a. Internal fragmentation
- b. External fragmentation
- c. Both internal and external
- d. Neither
Show answer & explanation
Answer: B. External fragmentation
Paging removes external fragmentation because any free frame can hold any page — no contiguous allocation needed. It still suffers internal fragmentation: on average half the last page of each process is wasted.
-
Q15. A system uses 4 KB pages with 32-bit logical addresses. How many bits are used for the page offset?
Show answer & explanation
Answer: 12
The offset must address every byte inside a page: 4 KB = 2¹² bytes → 12 offset bits, leaving 20 bits for the page number (2²⁰ pages). Page-table sizing questions all start from this split.
-
Q16. The main benefit of virtual memory is that it:
- a. Makes RAM physically larger
- b. Lets processes run without loading all of their pages into RAM
- c. Eliminates the need for disk storage
- d. Removes the need for CPU caches
Show answer & explanation
Answer: B. Lets processes run without loading all of their pages into RAM
Virtual memory lets each process see a large private address space while only its actively-used pages occupy RAM — the rest stay on disk until demanded. Programs larger than physical memory can run, and more processes fit in memory at once.
-
Q17. Belady's anomaly — more page frames causing MORE page faults — can occur with which replacement algorithm?
- a. LRU
- b. Optimal
- c. FIFO
- d. LFU
Show answer & explanation
Answer: C. FIFO
FIFO can fault more with extra frames because it evicts by arrival time, not by usefulness. LRU and Optimal are "stack algorithms" — the pages held with k frames are always a subset of those held with k+1 — so they can never exhibit the anomaly.
-
Q18. The LRU page-replacement algorithm evicts the page that:
- a. Was loaded into memory first
- b. Has not been used for the longest time
- c. Will not be used for the longest time in future
- d. Has the smallest page number
Show answer & explanation
Answer: B. Has not been used for the longest time
LRU evicts the least recently USED page, betting that the recent past predicts the near future (locality of reference). Option c describes the Optimal algorithm — unimplementable in practice since it needs future knowledge, but the benchmark LRU approximates.
-
Q19. Thrashing is the situation where:
- a. The CPU overheats under load
- b. The system spends more time paging than executing useful work
- c. Two processes deadlock on I/O
- d. The disk becomes completely full
Show answer & explanation
Answer: B. The system spends more time paging than executing useful work
Thrashing happens when processes don't have enough frames for their working sets, so every few instructions trigger a page fault — CPU utilisation collapses while the disk churns. The cure is reducing multiprogramming, not adding more processes.
-
Q20. In demand paging, a page fault occurs when:
- a. A process accesses a page that is not currently in physical memory
- b. A page contains a division-by-zero error
- c. Two processes access the same page
- d. The page table becomes full
Show answer & explanation
Answer: A. A process accesses a page that is not currently in physical memory
A page fault is a hardware trap raised when the referenced page's valid bit is off — the page isn't in RAM. The OS then finds the page on disk, loads it into a free frame (evicting one if needed) and restarts the instruction. It's a normal mechanism, not an error.
-
Q21. Fixed-size memory partitioning primarily suffers from:
- a. External fragmentation
- b. Internal fragmentation
- c. Thrashing
- d. Starvation
Show answer & explanation
Answer: B. Internal fragmentation
With fixed partitions, a process rarely fills its partition exactly — the unused space inside the allocated block is internal fragmentation. Variable partitioning flips the problem: allocations fit exactly, but free memory splinters into unusable external holes.
-
Q22. In a Unix-style file system, which piece of information is NOT stored in a file's inode?
- a. File size
- b. Owner and permissions
- c. The file's name
- d. Pointers to data blocks
Show answer & explanation
Answer: C. The file's name
The inode holds metadata — size, owner, permissions, timestamps, block pointers — but NOT the name. Names live in directory entries that map name → inode number, which is exactly why one file can have several hard links (names).
-
Q23. What does fork() return in the child process?
- a. 0
- b. The child's PID
- c. The parent's PID
- d. -1
Show answer & explanation
Answer: A. 0
fork() returns 0 in the child and the child's PID in the parent (or −1 on failure) — one call, two returns, and the return value is how the code tells which process it's in. The child can fetch its parent's PID with getppid().
-
Q24. Which of the following scheduling algorithms are preemptive? (Select all that apply.)
- a. Round Robin
- b. Shortest Remaining Time First
- c. First Come First Served
- d. Non-preemptive Shortest Job First
Show answer & explanation
Answer: A. Round Robin · B. Shortest Remaining Time First
Round Robin preempts on every quantum expiry, and SRTF preempts whenever a shorter-remaining job arrives. FCFS and non-preemptive SJF let the running process finish — the CPU is only released voluntarily.
-
Q25. In which CPU mode does the kernel execute system-call code?
- a. User mode
- b. Kernel (supervisor) mode
- c. Safe mode
- d. Virtual mode
Show answer & explanation
Answer: B. Kernel (supervisor) mode
A system call traps from user mode into kernel mode, where privileged instructions and hardware access are allowed, then returns to user mode. This dual-mode design is the hardware foundation of OS protection — user code can never touch devices directly.