Last Minute Notes

OS Interview Playbook

Operating systems interview rehearsal: a 50-question bank with strong-answer checklists, numerical problem types (scheduling, paging, page replacement, Banker's, disk scheduling) with solving recipes, production scenarios, cheat sheets, common mistakes, and a 7-day study plan.

📘 OS Interview Playbook

The other pages teach the material. This page is for rehearsal: a question bank with what a strong answer contains, recipes for the numerical problems that appear in written tests, production scenarios, cheat sheets, and a study plan.

Table of Contents

  1. What Interviewers Look For
  2. Question Bank
  3. Numerical Problem Recipes
  4. Production Scenarios
  5. Cheat Sheets
  6. Common Mistakes
  7. Study Plan

1. What Interviewers Look For

LevelExpected
New grad / campusDefinitions and differences (process vs thread, paging vs segmentation), scheduling and page replacement numericals, deadlock conditions, semaphores
MidContext switch costs, fork and exec, IPC choices, race conditions and locks in real code, virtual memory and page faults, file descriptors
SeniorMemory ordering, lock-free trade-offs, epoll and event loops, page cache and fsync durability, containers from namespaces and cgroups, performance debugging
Systems / infraScheduler internals (CFS, EEVDF), NUMA, TLB shootdowns, io_uring, eBPF, kernel bypass

Signals that raise your rating: connecting theory to something observable (ps states, free output, strace), quoting rough costs (syscall, context switch, page fault, fsync), and explaining trade-offs rather than definitions.


2. Question Bank

2.1 Basics and processes (12)

#QuestionStrong answer includesRead
1What does an OS do?Resource management and abstractions, isolationFundamentals
2Kernel mode vs user mode?CPU rings, privileged instructions, whyFundamentals
3What happens during a system call?Registers, trap instruction, mode switch, return, cost, vDSOFundamentals
4Monolithic vs microkernel?Speed vs isolation, examples, Linux modulesFundamentals
5Process vs thread?Address space, what is shared, cost, failure isolationProcesses and Threads
6Describe process states.Five states and transitions, D and Z in psProcesses and Threads
7What is a context switch?Save and restore PCB, page table switch, cache and TLB costProcesses and Threads
8How does fork work?Copy-on-write, return values, fork + exec patternProcesses and Threads
9Zombie vs orphan?Not reaped vs re-parented to init, PID 1 in containersProcesses and Threads
10User threads vs kernel threads?Models 1:1, M:1, M:N, goroutines, virtual threadsProcesses and Threads
11IPC mechanisms and when to use each?Pipes, sockets, shared memory, message queues, signalsProcesses and Threads
12SIGTERM vs SIGKILL, and graceful shutdown?Catchable vs not, drain within a deadlineProcesses and Threads

2.2 Scheduling (6)

#QuestionStrong answer includesRead
13Compare FCFS, SJF, SRTF, RR, priority.Preemption, waiting time, starvation, response timeCPU Scheduling
14How do you choose an RR time quantum?Overhead vs responsiveness, 80 percent ruleCPU Scheduling
15What is starvation and aging?Low priority never runs, raise priority over timeCPU Scheduling
16Explain MLFQ.Queues, demotion, boost, learns interactivityCPU Scheduling
17How does the Linux scheduler work?Classes, CFS vruntime and red-black tree, EEVDF since 6.6, niceCPU Scheduling
18What is priority inversion?Mars Pathfinder, priority inheritanceCPU Scheduling

2.3 Synchronization and deadlock (12)

#QuestionStrong answer includesRead
19What is a race condition? Give an example.counter++ as load, add, storeSynchronization
20Critical section requirements?Mutual exclusion, progress, bounded waitingSynchronization
21Mutex vs semaphore?Ownership, counting, signalingSynchronization
22Spinlock vs mutex?Busy wait vs sleep, when each wins, futex hybridSynchronization
23Why does condition wait use a while loop?Spurious wakeups, Mesa semanticsSynchronization
24Solve producer-consumer with semaphores.empty, full, mutex, correct orderSynchronization
25Dining philosophers solutions?Ordering, limit seats, atomic pick-upSynchronization
26What is CAS and the ABA problem?Atomic compare and swap, version tagsSynchronization
27Four conditions for deadlock?Coffman conditions with a way to break eachSynchronization
28Prevention vs avoidance vs detection?Design out vs safe state check vs find cycles and recoverSynchronization
29Explain the Banker's algorithm.Need matrix, safety check, safe sequenceSynchronization
30Deadlock vs livelock vs starvation?Blocked vs busy without progress vs unfairSynchronization

2.4 Memory (12)

#QuestionStrong answer includesRead
31What is virtual memory and why?MMU translation, isolation, overcommit, sharingMemory
32Paging vs segmentation?Fixed vs variable, fragmentation typesMemory
33Internal vs external fragmentation?Inside blocks vs between blocks, fixesMemory
34How is an address translated?Page number, offset, TLB, page walkMemory
35Why multi-level page tables?Sparse address spaces, 4-level x86-64Memory
36What is the TLB?Cache of translations, miss cost, ASIDs, huge pagesMemory
37Walk through a page fault.Valid check, frame, disk read, table update, restartMemory
38Compare page replacement algorithms.FIFO, LRU, Optimal, Clock, Belady's anomalyMemory
39What is thrashing and how do you fix it?Working set exceeds RAM, reduce load or add memoryMemory
40Stack vs heap?Per-thread automatic frames vs dynamic shared allocations, sizes, errorsProcesses and Threads
41What is copy-on-write?Shared read-only pages copied on first write, fork, snapshotsMemory
42What happens when a container hits its memory limit?cgroup OOM kill, exit code 137Memory

2.5 Files, I/O, and Linux (8)

#QuestionStrong answer includesRead
43What is an inode?Metadata without the name, links, extentsFile Systems
44Hard link vs symlink?Same inode vs path file, cross-FS, danglingFile Systems
45What does fsync do and why does it matter?Page cache vs stable storage, atomic rename patternFile Systems
46What is journaling?Write-ahead log for metadata, modesFile Systems
47select vs poll vs epoll?O(n) scans vs ready list, level vs edgeI/O and Linux
48How does an event loop serve many connections?Non-blocking sockets, epoll, callbacks, no CPU-heavy work on the loopI/O and Linux
49How are containers implemented?Namespaces, cgroups, overlayfs, capabilities, seccompI/O and Linux
50Container vs VM?Shared kernel vs hypervisor, startup, isolationFundamentals

3. Numerical Problem Recipes

Problem typeRecipe
CPU schedulingDraw a Gantt chart first. Turnaround = completion - arrival. Waiting = turnaround - burst. Response = first run - arrival. For RR, write the ready queue at every step and add new arrivals before the preempted process
Address translationOffset bits = log2(page size). Page number = address >> offset bits. Physical = frame << offset bits OR offset
Page table sizeEntries = 2^(VA bits - offset bits). Size = entries x entry size. Multi-level: bits per level = log2(page size / entry size)
Effective access time (TLB)EAT = h x (TLB + mem) + (1 - h) x (TLB + levels x mem + mem)
Effective access time (faults)EAT = (1 - p) x mem + p x fault service time
Page replacementDraw frames as columns per reference, mark faults. Optimal: evict the page used furthest ahead. LRU: evict the one used longest ago
Banker'sNeed = Max - Allocation. Repeatedly pick a process with Need <= Work, add its Allocation to Work. All finish = safe
Disk schedulingList the order, sum absolute differences. SCAN goes to the end, LOOK turns at the last request. C-SCAN counts the return if the question says so
Semaphore tracesTrack the value and the waiting queue after every operation
fork countingn sequential fork() calls produce 2^n processes; with conditions (fork() && fork()), draw the tree

Practice sets with verified answers: CPU Scheduling, Memory Management, Synchronization and Deadlocks, File Systems and Storage.


4. Production Scenarios

ScenarioStrong direction
"Load average is 40 on a 16-core box, but CPU is 30 percent busy."Tasks in D state waiting on disk or NFS; vmstat b column, iostat -x for latency, ps for D processes
"The service's latency spikes every few seconds, CPU looks fine."cgroup CPU throttling (cpu.stat nr_throttled), GC pauses, THP compaction, swap; remove CPU limits or size thread pools to the quota
"The container keeps restarting with exit code 137."OOM kill by cgroup limit; check memory.events, heap vs native memory, raise limit or fix the leak
"Disk shows 100 percent used but du finds far less."Deleted files still held open (lsof +L1), restart or truncate via /proc/<pid>/fd; also check inodes with df -i
"Too many open files errors under load."FD limit (ulimit -n, systemd LimitNOFILE), leaked sockets, connection pooling
"The app hangs; all threads seem stuck."Thread dump; look for lock cycles (deadlock) or a pool starved by blocking calls; fix lock ordering or pool design
"Writes were acknowledged but lost after a power failure."No fsync, disk write cache without power-loss protection, wrong journaling mode; fsync plus atomic rename, group commit
"One Node.js process becomes unresponsive under a specific request."CPU-heavy code blocking the event loop; profile, move work to worker threads or another service

5. Cheat Sheets

Costs to remember

OperationRough cost
Function callAbout 1 ns
Uncontended mutex lock and unlockAbout 20 ns
System call100 ns to a few microseconds
Context switch (direct)1 to 5 microseconds
Minor page faultAbout 1 microsecond
Thread creation10 to 50 microseconds
Process creation (fork + exec)Hundreds of microseconds to milliseconds
NVMe random read10 to 100 microseconds
Major page fault from NVMeAbout 100 microseconds
fsync on consumer SSDMilliseconds
HDD seek5 to 10 ms

Process vs thread

ProcessThread
Address spaceOwnShared
CreationSlowerFaster
SwitchPage table changeRegisters and stack only
CommunicationIPCShared memory
Crash impactContainedWhole process

Deadlock at a glance

ConditionPrevention
Mutual exclusionMake resources sharable
Hold and waitRequest all at once
No preemptionTimeouts, tryLock
Circular waitGlobal lock order

Page replacement

AlgorithmAnomalyPractical
FIFOBelady's anomaly possibleSimple, poor
LRUNoneToo costly exactly
OptimalNoneImpossible, benchmark
ClockPossible (approximates LRU)Real systems

6. Common Mistakes

  • Saying threads "have their own memory"; they share the heap and only own stacks and registers.
  • Confusing a mode switch (syscall) with a context switch.
  • Claiming SJF is practical without mentioning burst prediction.
  • Using if instead of while around a condition wait.
  • Treating a binary semaphore and a mutex as identical.
  • Forgetting that deadlock needs all four conditions, and that lock ordering is the practical fix.
  • Saying write() makes data durable.
  • Calling low free memory on Linux a problem.
  • Believing containers are lightweight VMs with their own kernel.
  • Forgetting that epoll does not make regular file I/O asynchronous.

7. Study Plan

DayFocusOutput
1OS FundamentalsExplain a system call end to end; strace -c ls
2Processes and ThreadsWrite a fork + exec + wait program; draw the state diagram
3CPU SchedulingSolve three scheduling problems with Gantt charts
4Synchronization and DeadlocksCode producer-consumer; run the Banker's example by hand
5Memory ManagementTranslate addresses; FIFO, LRU, Optimal on a reference string
6File Systems and I/O and LinuxBuild a crude container with unshare; write an epoll echo server
7This pageAnswer the question bank out loud; do the production scenarios

Related: Computer Fundamentals for the hardware underneath (caches, CPU pipelines, memory hierarchy) and Networking for the socket side of I/O.

On this page