OS Questions for Interview: Top 10 with Answers

Share
OS Questions for Interview: Top 10 with Answers

Why do engineers who ship multithreaded code every day still freeze when an interviewer asks what happens during a page fault?

Because they've read the definition and never said it out loud. Operating systems questions follow a predictable pattern. A handful of core topics, process versus thread, deadlock, scheduling, virtual memory, synchronization, show up in nearly every technical screen and onsite loop, and interviewers ask them to hear how you reason rather than to check whether you memorized a diagram.

The setting matters too. In the CoderPad and CodinGame State of Tech Hiring report, 90% of developers said a technical interview is the best setting to showcase their skills. That tells you something about the OS round. It's a conversation, and the candidates who do well are the ones who can build an answer out loud, in layers, without losing the thread halfway through.

What follows are the ten highest-frequency OS questions for interview loops, ordered from fundamentals to advanced. Each one gets an answer structure, a concrete example you can adapt, and the follow-up interviewers usually fire next. Read it once, then close the page and say each answer aloud with a timer running, because OS questions for interview preparation reward crisp verbal explanation more than any other topic in the loop. If you want the underlying theory first, MasteryMind's computer science revision hub covers it in more depth.

1. What Is the Difference Between a Process and a Thread?

A software developer working at a desk with three computer monitors displaying code and flowcharts.

A process is an independent program in execution, with its own address space, file handles, credentials and scheduling state. A thread is the smallest unit the CPU schedules, and it lives inside a process, sharing the code, heap, global variables and open descriptors while keeping a private stack, program counter and register set. Interviewers open with this because everything later in the round builds on it, from multitasking to why concurrency bugs exist at all.

The Four Axes That Make a Good Answer

  • Memory: threads share the heap and global data, never the stack. Say that phrase out loud, because it's the exact sentence interviewers listen for.
  • Cost: creating and switching a thread is cheaper than forking a process, since a process switch also swaps the address space and flushes address-translation caches.
  • Communication: two processes need pipes, shared memory or sockets, while two threads pass a pointer.
  • Fault isolation: a crashing thread can take the whole process down, while a process usually fails alone.

Then attach a concrete case. A browser runs each tab in its own process so a memory bug in one page can't corrupt your bank tab, and a web server keeps a thread pool and hands each request to a worker because shared connection state is the whole point.

What interviewers listen for: "shared heap, private stack" plus one sentence on when you would pay the price of processes instead.

Portability keeps this question platform-neutral. In Stack Overflow's 2025 Developer Survey, Windows was the primary professional operating system for 49.5% of respondents, macOS for 32.9% and Ubuntu for 27.7%, so a good answer has to survive being asked on any of those.

The follow-up is nearly always about race conditions, so rehearse that transition. Explain your answer to a person, not a mirror, and practice the answer in a mock interview to find the sentence you can't finish under pressure.

2. What Is a Deadlock, and What Are the Four Necessary Conditions for It?

A deadlock is a set of processes each waiting for a resource that another member of the set holds, so nobody can proceed. The four conditions are mutual exclusion, hold and wait, no preemption and circular wait. Break any single one and deadlock becomes impossible, which gives your answer a spine instead of a list.

Prevention, Avoidance, Detection

Work the four conditions into fixes rather than reciting them.

  • Mutual exclusion: the resource can't be shared. Make it shareable where you can, for example handing out read-only copies.
  • Hold and wait: a process holds one resource while requesting another. Require all resources to be acquired up front.
  • No preemption: nobody can take a resource away. Let the OS preempt and roll back the holder.
  • Circular wait: holders form a cycle. Impose a global lock ordering so a cycle can't form.

The worked example that lands is two threads, where one locks mutex A then mutex B and the other locks B then A. Each holds what the other wants and the cycle closes.

Avoidance means negotiating before granting. The Banker's algorithm keeps the system in a safe state by only approving a request if some completion order still exists. Detection means letting cycles form and cleaning up, which is what database engines do when they pick a victim transaction and abort it. The trade-off is real: detection allows more concurrency but needs a wait-for graph and a victim-selection policy, while prevention is cheaper but restricts how resources get requested.

Expect the production follow-up: "a service hangs and no thread is burning CPU, what now?" The answer is a thread dump, build the wait-for graph from the stack traces, and look for two locks acquired in opposite orders. Then fix it at the code level with a documented lock hierarchy.

3. Explain CPU Scheduling Algorithms Such as FCFS, SJF, Round Robin and Priority Scheduling

Three processes arrive together with CPU bursts of 8, 4 and 2 units. Compare how each scheduling policy orders them, then explain the trade-off: interviewers usually probe waiting time, turnaround time, response time and throughput.

First-Come, First-Served (FCFS) runs jobs in arrival order. The waiting times are 0, 8 and 12 units, for an average of 6.67. It is simple to implement, but a long job at the front creates the convoy effect, delaying shorter jobs behind it.

Shortest Job First (SJF) runs the shortest burst first. The waiting times are 0, 2 and 6 units, averaging 2.67. This minimizes average waiting time when burst lengths are known, but operating systems generally have to estimate them from past behaviour.

Round Robin assigns each ready process a fixed time quantum, then moves unfinished work to the back of the queue. With a quantum of 2, the waiting times are 6, 6 and 4 units, averaging 5.33. Shorter quanta improve responsiveness, while longer ones reduce switching and make the policy behave more like FCFS.

Priority scheduling runs the highest-priority process first. It can favour urgent work, but low-priority processes may wait indefinitely; aging gradually raises their priority to prevent starvation.

An infographic summarizing CPU scheduling algorithms including FCFS, SJF, Round Robin, Priority Scheduling, and performance metrics.

A common follow-up asks what happens when Round Robin's quantum changes. If it is too small, frequent context switches consume more CPU time. If it is too large, interactive tasks wait longer for a turn. Multilevel feedback queues address this tension by adjusting priorities and time slices for different kinds of work.

4. What Is Virtual Memory, and How Does Paging Work?

What happens when a process uses an address that is not currently in RAM? The operating system handles it through virtual memory: each process gets a private address space, while hardware maps virtual addresses to physical memory and, when needed, disk.

Paging divides virtual memory into fixed-size pages and RAM into same-size frames. A page table maps each page to a frame. To translate an address, the memory management unit separates its page number from its offset, looks up the page number, then combines the frame number with the unchanged offset. A translation lookaside buffer (TLB) caches recent mappings so the processor can avoid a page-table lookup for many accesses.

When a page is absent from RAM, accessing it triggers a page fault. The operating system finds a free frame or selects a page to evict, loads the required page, updates the mapping and resumes the instruction. A minor fault can be handled without reading the page from disk; a major fault requires disk I/O and can add substantial latency.

Worked example: diagnose rising memory use

Suppose a service's reported memory climbs while throughput falls. First compare virtual size with resident set size (RSS), the portion currently in physical memory. A large virtual address space with stable RSS may reflect reserved address space rather than growing physical use. Rising RSS, frequent page faults or swap activity, and worsening latency point to a different problem and deserve closer investigation.

Practical rule: compare allocation profiles with RSS, fault rates, swap activity and latency percentiles before calling the increase a memory leak.

Copy-on-write can explain a temporary change around process creation. After a fork, parent and child can share pages until one writes to a page, at which point the operating system creates a private copy. That sharing can make memory readings harder to interpret.

Windows held 76.65% of worldwide desktop operating-system usage in StatCounter's desktop market share snapshot. That is market context, not evidence about interview questions. Answer in terms of page tables, faults, frames and disk I/O, then name one Windows tool and one Linux tool you could use to inspect memory behavior.

5. What Is a Race Condition, and How Do Mutexes and Semaphores Prevent It?

Two threads read a shared counter holding 5, both add one, both write 6. One increment disappears. That's a race condition: the result depends on the interleaving of accesses to shared state rather than on the code alone.

Two people working together on a computer keyboard to solve coding problems and prevent race conditions.

A mutex is a lock with ownership. One thread enters the critical section, and the same thread must release it. A semaphore is a counter that signals: it limits how many holders can proceed at once and any thread or process can post to it. That ownership difference is what the interviewer is fishing for, and it's the distinction most candidates blur.

Mutual Exclusion Versus Signaling

Use a mutex when the problem is "only one at a time touches this". Use a semaphore when the problem is "at most N at a time" or "wake a waiter when an item arrives". The classic producer-consumer bounded buffer uses both: semaphores count empty and full slots while a mutex guards the buffer itself.

Spinlocks belong in the same answer for kernel code, where holding a lock briefly and busy-waiting beats paying for a sleep and wake. Condition variables and atomic operations round out the toolkit, and it's worth saying that unsynchronized reads are only safe for immutable data.

The follow-up is usually a design question: "how would you build a thread-safe queue?" Answer with a mutex plus two condition variables, then mention a lock-free ring buffer with atomics if the interviewer asks about scale. If you want to see how concurrency questions are framed by different companies, browse the Question Bank of real interview questions grouped by company and compare the wording.

6. What Is a Context Switch, and Why Does It Matter?

A context switch saves the state of the running task and loads the state of the next one. The saved state includes the program counter, registers, stack pointer and memory mapping information, and the scheduler updates its own bookkeeping in between.

The interesting part is the cost, which candidates tend to underestimate.

  • Register and stack save/restore is the visible part, and it's small.
  • Address-space changes on a process switch invalidate cached translations, so the next task starts with a cold TLB.
  • Cache pollution follows, because the new task's working set evicts the old one's from L1 and L2.
  • Scheduler overhead grows with run-queue length as the kernel searches for the next task.

A server running 2,000 threads on 8 cores spends real capacity on switching and cache misses that never appear in a profiler's happy path. Dropping to a pool sized near the core count, or moving blocking I/O to async, usually beats adding threads.

A context switch you can't measure is a context switch you can't justify. Watch voluntary and involuntary switch counts before and after any thread-pool change.

The mechanics land better with a platform example. Windows was the primary professional operating system for 47.6% of surveyed developers in 2024, according to Stack Overflow's 2024 Developer Survey, so a Windows-flavoured example (a thread pool, a thread dump, the scheduler view in a profiler) will usually be understood.

The follow-up: "does adding threads ever reduce throughput?" Yes, past the point where switching and contention outweigh parallelism, and the same reasoning explains why thread-per-connection servers collapse under load.

7. What Is the Difference Between Internal and External Fragmentation?

Fragmentation is memory you paid for and can't use. Internal fragmentation lives inside an allocated block: a 4 KB page holding 1 KB of data wastes 3 KB that no other allocation can touch. External fragmentation lives between blocks: total free memory is plentiful but chopped into pieces too small for the next request.

Paging trades one for the other. Fixed-size frames leave internal waste in the last page of every allocation but eliminate external fragmentation entirely. Variable-size contiguous allocation does the opposite, which is why heap managers for variable objects fight external fragmentation with free lists, coalescing and size-class buckets.

The Numeric Example That Settles It

Lexicographic-style arithmetic makes it concrete. With free blocks of 100, 200 and 300 bytes and a request for 250, first fit takes the 300 block and leaves a 50-byte stub. Best fit takes the same 300 here but scans everything first. Worst fit leaves a 50-byte block that is useless, which is exactly the trade-off to mention when asked why best fit is common and worst fit rarely is.

Kernel allocators solve the same problem differently. Slab allocation keeps caches of fixed-size objects, so a request for a common structure never fragments. The Linux kernel's memory-management subsystem covers virtual memory, demand paging, kernel and user-space allocation, and exposes tuning through /proc and sysctl rather than hiding it, as the Linux kernel memory-management documentation describes. That observability is worth citing in an answer about diagnosing memory waste.

The follow-up asks why paging doesn't end fragmentation for good. The answer is page tables, small-object allocators and per-process overhead, all of which reintroduce waste at a different layer.

8. What Is the Difference Between Kernel Mode and User Mode, and How Do System Calls Work?

CPUs provide at least two privilege levels. Kernel mode can execute privileged instructions and touch hardware directly. User mode cannot, which is what keeps a buggy application from corrupting the machine or reading another process's memory. The boundary is enforced in hardware, not by convention.

Tracing a System Call End to End

Follow a single read() and the answer writes itself.

  1. Application code calls the C library wrapper, which places the system call number and arguments in registers.
  2. The wrapper executes a trap instruction, and the CPU switches to kernel mode at a fixed entry point.
  3. The kernel dispatches through the system call table to the handler, which validates arguments and permissions.
  4. The handler reaches the file through the virtual file system, an abstraction that presents one interface to user space while several filesystem implementations coexist beneath it, as the Linux VFS documentation explains.
  5. The kernel copies results back, restores user state and returns, and the wrapper translates the return value.

That layering is why read() on ext4, XFS or a network filesystem looks identical from your code. It's also why open, read, write and fork are worth naming as examples: each one crosses the boundary and each one has a measurable cost.

Batching reduces that cost. A high-throughput server that writes 10,000 tiny records one syscall at a time pays for 10,000 crossings; buffering into a few large writes pays for a few. Caching the mode switch itself, as the vDSO does for some clock reads, is the other classic answer.

Interview edge: say that user mode is a security boundary rather than a performance feature, then explain what a kernel bug or a missing permission check costs.

Mobile platforms make the follow-up concrete. StatCounter's worldwide mobile operating-system figures put Android at 72.36% and iOS at 27.61% of mobile usage (StatCounter OS market share), so expect questions about sandboxing and declared permissions, which are the same user-mode boundary with an app-level policy on top.

9. Compare Page Replacement Algorithms FIFO, LRU and Optimal, and Explain Belady's Anomaly

When memory is full and a page must be loaded, something gets evicted. FIFO evicts the oldest resident page and ignores usage. LRU evicts the page that hasn't been touched for the longest time, which fits the principle of locality. Optimal evicts the page whose next use is furthest away, which can't be built but gives you a lower bound to measure against.

Working a Reference String

Take the string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5. Run FIFO with three frames and you count 9 page faults. Run the same string with four frames and FIFO gives you 10. That is Belady's anomaly: more memory, more faults.

The reason is structural. LRU is a stack algorithm, so the set of pages resident with N frames is always a subset of the set resident with N+1, and adding frames can only help. FIFO has no such property, so its eviction order can shift into a worse pattern when the frame count changes.

Production systems rarely implement true LRU because it needs per-access bookkeeping. They approximate it with a clock or second-chance sweep, where a reference bit buys a page another pass through the hand. That's the detail that distinguishes a textbook answer from an engineer's.

The follow-up asks what happens when the working set outgrows memory. Framing the answer around thrashing, where the system spends its time paging and almost none executing, usually satisfies them, and an answer that names working-set or page-fault-frequency control shows you know the OS does something about it.

10. What Are the Main Inter-Process Communication Mechanisms?

Processes have isolated address spaces, so the OS has to provide every channel between them. Group the mechanisms by scope and the answer organizes itself.

  • Same machine, streaming: anonymous pipes for parent-child flows, named pipes or FIFOs when the processes aren't related.
  • Same machine, structured: message queues for discrete messages with boundaries preserved, and local sockets for request-response.
  • Same machine, high throughput: shared memory, which is the fastest option because nothing is copied after setup, and the hardest because you build the synchronization yourself with semaphores or a mutex in shared memory.
  • Across a network: sockets over TCP or UDP, with HTTP or gRPC layered on top for microservices.
  • Notification only: signals, when you need to interrupt rather than deliver data.

A worked choice sharpens it. Moving a 2 GB file between two local services, shared memory wins on throughput but costs you synchronization and cleanup if a writer dies mid-update. Handing the same data to a service on another host, sockets are the only option and chunking matters more than mechanism.

Memory-mapped files sit between categories, and they're observable. /proc/PID/maps lists the virtual address ranges mapped into a process with their permissions, so you can see shared libraries, mapped files and shared segments directly, as the Linux /proc filesystem documentation describes. That makes a strong closing line for an answer about verification.

The follow-up asks why pipes are so common when shared memory is faster. Because the shell example ls | grep txt needs no synchronization, no cleanup and no shared schema, and that simplicity beats raw speed for nearly every command-line tool.

The 10 OS Interview Questions at a Glance

Question OS Topic Difficulty Key Concept to Nail Likely Follow-up
What is the difference between a process and a thread? Processes and threads Foundational Processes have separate address spaces; threads share process memory but have their own stacks and registers When would you choose processes over threads?
What is a deadlock, and what are the four necessary conditions for it? Deadlocks Intermediate Mutual exclusion, hold and wait, no preemption, and circular wait must all hold How can the Banker's algorithm avoid deadlock?
Explain CPU scheduling algorithms: FCFS, SJF, Round Robin and Priority Scheduling CPU scheduling Intermediate Compare scheduling policies by waiting, turnaround, and response time, including their trade-offs How does the Round Robin time quantum affect performance?
What is virtual memory, and how does paging work? Virtual memory and paging Intermediate The MMU maps virtual pages to physical frames using page tables; missing pages cause page faults What does the TLB do, and what causes thrashing?
What is a race condition, and how do mutexes and semaphores prevent it? Concurrency and synchronization Intermediate Mutexes provide ownership-based mutual exclusion; semaphores use counters for signaling or resource limits How would semaphores coordinate a producer-consumer buffer?
What is a context switch, and why does it matter? Processes, threads, and scheduling Intermediate The CPU saves one task's state and restores another's, incurring overhead Why is a process switch generally more expensive than a thread switch?
What is the difference between internal and external fragmentation? Memory allocation Foundational Internal waste is inside allocated blocks; external waste is scattered between them How does paging trade external fragmentation for internal fragmentation?
What is the difference between kernel mode and user mode, and how do system calls work? Protection and system calls Intermediate System calls use a controlled trap to transfer requests from restricted user mode to the kernel What steps occur when a program calls read?
Compare page replacement algorithms: FIFO, LRU and Optimal, and explain Belady's anomaly Virtual memory and page replacement Advanced FIFO can exhibit Belady's anomaly; LRU uses recency, while Optimal is a theoretical benchmark Why does LRU avoid Belady's anomaly?
What are the main inter-process communication (IPC) mechanisms? Inter-process communication Intermediate Choose among pipes, queues, shared memory, sockets, and signals based on scope and trade-offs When would shared memory be preferable to sockets or pipes?

Turn This List Into Interview-Ready Answers

Reading answers is not the same as delivering them, and the OS round punishes the gap more than most. The plan that works takes seven days and about twenty minutes a day.

Take two questions from this list each day. Write a one-paragraph skeleton for each with four lines: the definition, the mechanism, one worked example, and one trade-off. Close every note, set a timer for ninety seconds, and say the answer out loud. Record it. The sentences you can't finish are the ones you need to fix, and they're rarely the ones you'd guess.

Day one and two cover processes, threads and deadlock. Day three is scheduling with the arithmetic done by hand. Day four is virtual memory and page replacement, including the reference string. Day five is concurrency. Day six is modes, system calls and fragmentation. Day seven is IPC plus a full run through all ten, back to back, with no notes.

Where Practice Tools Fit

A recruiter screen will ask two or three of these and go deep on one. Onsites spread them across rounds, and a system design discussion will pull scheduling or IPC back in without warning. Practising the answer you'll speak, at the speed you'll speak it, is the highest-return hour you can spend.

ParakeetAI's Mock Interview lets you practice out loud against an AI interviewer that answers back, and you can read the transcript afterwards to see where your explanation stalled. The first mock interview is free and needs no credit card, so a full dry run of this list costs you nothing but the time.

Keep a one-page ledger of the follow-ups you fumbled. Mine the transcript after each run, add the weak spot to the next day's two questions, and stop practising anything you can already explain cleanly. The point isn't to cover ten topics. It's to be unable to get caught on any of them.


ParakeetAI is an AI interview assistant that listens to the interviewer's question during a live call and shows a suggested answer on your screen, without ever joining the call as a participant. The Question Bank gathers real interview questions grouped by company, and the Mock Interview gives you one free practice run to rehearse answers like the ten above out loud. Visit ParakeetAI to see how the preparation tools and the live assistant fit together.

Read more