100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C

Common OS Interview Questions

The most frequently asked operating systems interview questions with clear, technically accurate answers.

Interview PrepIntermediate14 min readJul 8, 2026
Analogies

Overview

Operating systems questions show up in almost every systems-level technical interview because they test whether you understand what happens beneath the code you write every day. Interviewers use them to probe your grasp of processes, memory, scheduling, and synchronization — and to see whether you can reason precisely instead of reciting buzzwords. This lesson collects the questions that come up most often, with concise, correct answers you can adapt in your own words during an interview.

🏏

Cricket analogy: Just as a fast bowler's spell is judged not by raw pace alone but by understanding swing, seam, and field placements, OS interview questions test whether you understand the mechanics beneath the code, not just memorized buzzwords like 'deadlock' or 'thread'.

Frequently Asked Questions

Q: What is the difference between a process and a thread?

A process is an independent unit of execution with its own address space (code, data, heap, stack) and its own set of OS resources such as open file descriptors. A thread is a unit of execution that lives inside a process and shares that process's address space and resources with other threads in the same process, but has its own stack, program counter, and register set. Because threads share memory, communication between them is cheap (just read/write shared variables) but requires synchronization; communication between processes requires explicit IPC mechanisms but gives strong isolation.

🏏

Cricket analogy: A process is like an entire cricket team with its own kit, budget, and dressing room (address space and resources), while a thread is like an individual player who shares the team's dressing room and equipment but has their own personal locker (stack) and batting position (program counter).

Q: What are the four necessary conditions for deadlock?

Mutual exclusion (at least one resource is held in a non-shareable mode), hold and wait (a process holds one resource while waiting for another), no preemption (a resource can only be released voluntarily by the process holding it), and circular wait (a cycle of processes exists where each waits for a resource held by the next). All four must hold simultaneously for a deadlock to occur; breaking any single one prevents deadlock.

🏏

Cricket analogy: Deadlock is like two batsmen who both call for a risky single, each holding their crease (mutual exclusion) while waiting for the other to move, refusing to go back (no preemption), in a run-out standoff that neither can break — all four conditions of a run-out deadlock.

Q: What is the difference between paging and segmentation?

Paging divides physical memory and logical address space into fixed-size blocks called pages and frames, so allocation is easy and there is no external fragmentation, though internal fragmentation can occur within the last page. Segmentation divides a program into variable-size logical units (code, stack, heap) that mirror how the programmer thinks about the program, which makes protection and sharing more natural but reintroduces external fragmentation since segments have varying sizes.

🏏

Cricket analogy: Paging is like a stadium dividing seating into identical fixed-size blocks that any ticket can fill regardless of section, while segmentation is like organizing seating by meaningful zones (VIP box, players' family enclosure, general stand) that vary in size and map to how fans actually think about the ground.

Q: What is a semaphore, and how does it differ from a mutex?

A semaphore is an integer synchronization variable accessed only through atomic wait (P/decrement) and signal (V/increment) operations, used to control access to a resource pool; a counting semaphore can allow more than one holder. A mutex is specifically a binary lock with ownership semantics — only the thread that acquired it may release it, and it is designed purely for mutual exclusion of a critical section, not general signaling between threads.

🏏

Cricket analogy: A semaphore is like a stadium's counting system for how many spectators may use a set of practice nets at once (allowing several), while a mutex is like a single locked equipment room key that only the groundskeeper who took it may return, used purely to prevent two people entering at once.

Q: What is a page fault, and what happens when one occurs?

A page fault is a trap raised by the MMU when a process accesses a page that is marked not-present in its page table, meaning the page is not currently in physical memory. The OS's fault handler locates the required page (in swap or the file system), selects a free frame or evicts a victim frame using a page-replacement algorithm, loads the page into memory, updates the page table, and then resumes the faulting instruction.

🏏

Cricket analogy: A page fault is like a substitute fielder being called onto the field because the specialist fielder isn't currently on the ground — the twelfth-man manager (OS fault handler) locates them in the dressing room (swap/disk), sends them out (loads into memory), updates the team sheet (page table), and play resumes exactly where it paused.

Q: What happens during a context switch?

The CPU saves the current process's or thread's execution state — program counter, registers, stack pointer, and other CPU state — into its process control block (PCB), then loads the saved state of the next process to run from its PCB, and updates memory-management registers such as the page table base register if switching address spaces. Context switches are pure overhead from the application's point of view; the CPU does no useful work during them, which is why minimizing their frequency and cost matters for scheduler design.

🏏

Cricket analogy: A context switch is like a bowler being taken off mid-over — the umpire notes exactly which ball was bowled, the field placements, and the score (PCB), then brings on a new bowler with their own run-up and field setup restored, and no actual overs are bowled during the changeover itself.

Q: What is the difference between multiprogramming, multitasking, and multiprocessing?

Multiprogramming keeps several jobs in memory so the CPU can switch to another job whenever one blocks on I/O, maximizing CPU utilization on a single processor. Multitasking extends this idea to interactive use, rapidly time-slicing the CPU among multiple tasks so users perceive them as running simultaneously. Multiprocessing means the system has more than one physical CPU (or core), so processes can execute truly in parallel rather than merely being interleaved.

🏏

Cricket analogy: Multiprogramming is like a ground keeping several practice sessions ready so when one team breaks for lunch, another team's nets are ready to use; multitasking is like a coach rapidly rotating attention between multiple net sessions so all look attended simultaneously; multiprocessing is like having two separate grounds running sessions truly in parallel.

Q: What is thrashing, and what causes it?

Thrashing occurs when a system spends more time paging pages in and out of memory than executing actual process instructions, because the combined working sets of the running processes exceed available physical memory. It is typically caused by over-committing the degree of multiprogramming; the fix is to reduce the number of concurrently running processes (via a working-set model or load control) rather than adding more processes, which would make it worse.

🏏

Cricket analogy: Thrashing is like a team making so many substitutions that more time is spent walking players on and off the field than actually playing overs, because too many players are rotating through too few field positions — the fix is fielding fewer active substitutions, not more.

Q: What is the difference between preemptive and non-preemptive scheduling?

In preemptive scheduling, the OS can forcibly take the CPU away from a running process — for example when a higher-priority process arrives or a time quantum expires — enabling better responsiveness but requiring careful synchronization to avoid race conditions during the switch. In non-preemptive scheduling, once a process is given the CPU it keeps it until it voluntarily yields, blocks for I/O, or terminates, which is simpler to reason about but can let a long process starve others of CPU time.

🏏

Cricket analogy: Preemptive scheduling is like an umpire forcing a bowler off mid-over when the over-rate falls too far behind, requiring careful handling of the field reset; non-preemptive scheduling is like letting a bowler finish their full spell before any change, simpler but risking a tired bowler dragging on too long.

Q: What is a race condition, and how is it prevented?

A race condition occurs when the correctness of a program depends on the relative timing or interleaving of multiple threads or processes accessing shared data, typically because a critical section is not properly protected. It is prevented by ensuring mutual exclusion around the shared data using mechanisms such as locks, mutexes, semaphores, or monitors, so that only one thread executes the critical section at a time.

🏏

Cricket analogy: A race condition is like two fielders both running for the same catch without calling it clearly, where the outcome (who actually takes the catch) depends purely on timing — the fix is a clear 'mine' call (mutual exclusion) so only one fielder commits to the catch at a time.

Quick Reference

  • Process = isolated address space; thread = shares address space within a process.
  • Deadlock requires mutual exclusion, hold-and-wait, no preemption, and circular wait — all four at once.
  • Paging avoids external fragmentation; segmentation avoids internal fragmentation but not external.
  • Mutex has ownership (only the locker unlocks); semaphore does not and can count beyond 1.
  • Page fault = MMU trap for a missing page, resolved by the OS fault handler.
  • Context switch overhead includes saving/restoring PCB state and possibly flushing the TLB.
  • Multiprogramming = CPU utilization via job switching; multitasking = perceived simultaneity; multiprocessing = real parallel hardware.
  • Thrashing = high paging activity, low useful CPU work, caused by memory over-commitment.
  • Preemptive scheduling can interrupt a running process; non-preemptive cannot.
  • Race conditions are fixed by enforcing mutual exclusion over shared/critical data.

Key Takeaways

  • Interviewers reward precise definitions over vague buzzwords — always tie your answer back to what the hardware or OS actually does.
  • Most OS questions are really asking you to trace a mechanism end-to-end, such as what happens on a page fault or context switch.
  • Comparative questions (process vs thread, mutex vs semaphore, paging vs segmentation) are common — practice stating both similarities and the key differentiator.
  • Deadlock and scheduling questions often expect you to name the underlying conditions or trade-offs, not just a definition.
  • Use small concrete examples in your answers; they demonstrate deeper understanding than abstract descriptions alone.

Practice what you learned

Was this page helpful?

Topics covered

#OperatingSystemsStudyNotes#OperatingSystems#CommonOSInterviewQuestions#Common#Interview#Questions#Frequently#StudyNotes#SkillVeris#ExamPrep