Operating Systems interview questions & answers
An operating system is the software layer that manages a computer's hardware and provides services to applications, including process scheduling, memory management, file systems, and device control. It abstracts hardware so programs run safely and share resources fairly. Interviews probe how the OS handles concurrency, memory, and the boundary between user and kernel space.
Updated 2026-06-18 · 16 real, commonly-asked questions with answers.
Key takeaways
- An operating system is the software layer that manages a computer's hardware and provides services to applications, including process scheduling, memory management, file systems, and device control.
- Core areas to revise for Operating Systems: Processes & threads, CPU scheduling, Synchronization & deadlocks, Memory management & paging, Virtual memory.
- This guide answers 16 of the most-asked Operating Systems interview questions — rehearse them in OnJob's free AI mock interview.
Top 16 Operating Systems interview questions
Q1.What is the difference between a process and a thread?
A process is an independent program in execution with its own memory address space, while a thread is a lightweight unit of execution within a process that shares that memory. Threads in the same process share code and data but have their own stack and registers. Threads are cheaper to create and switch between, but a crash in one thread can take down the whole process.
Q2.What is a context switch?
A context switch is when the CPU saves the state of the currently running process or thread and loads the state of another, allowing multitasking. The saved state includes registers, the program counter, and memory mappings. Context switches add overhead, so excessive switching reduces overall throughput.
Q3.Explain the difference between preemptive and non-preemptive scheduling.
In preemptive scheduling the OS can forcibly take the CPU from a running process, for example when a higher-priority task arrives or a time slice expires. In non-preemptive scheduling a process keeps the CPU until it finishes or voluntarily yields. Preemptive scheduling improves responsiveness but adds context-switch overhead and complexity.
Q4.What is a deadlock and what conditions cause it?
A deadlock is a state where processes are each waiting for resources held by the others, so none can proceed. It requires four simultaneous conditions: mutual exclusion, hold and wait, no preemption, and circular wait. Breaking any one condition prevents deadlock.
Q5.What is virtual memory?
Virtual memory is an abstraction that gives each process its own large, contiguous address space independent of physical RAM. The OS maps virtual pages to physical frames and can move pages to disk when memory is scarce. This isolates processes, simplifies programming, and lets programs use more memory than is physically available.
Q6.Explain paging and what causes a page fault.
Paging divides memory into fixed-size pages mapped to physical frames through a page table, eliminating external fragmentation. A page fault occurs when a program accesses a page that is not currently in physical memory, prompting the OS to load it from disk. Excessive page faults, called thrashing, severely degrade performance.
Q7.What is the difference between a mutex and a semaphore?
A mutex is a locking mechanism that allows only one thread into a critical section at a time and is owned by the thread that locked it. A semaphore is a counter that controls access for a fixed number of threads and is not owned by any one thread. A binary semaphore resembles a mutex, but mutexes add ownership semantics that prevent another thread from unlocking them.
Q8.What is a race condition?
A race condition occurs when the correctness of a program depends on the unpredictable timing of multiple threads accessing shared data. For example, two threads incrementing the same counter without synchronization may lose an update. Race conditions are avoided by protecting shared state with locks, atomic operations, or other synchronization.
Q9.What is a semaphore used for in synchronization?
A semaphore is a synchronization primitive that maintains a count and supports wait (decrement) and signal (increment) operations to coordinate access to shared resources. A counting semaphore limits how many threads use a resource pool, while a binary semaphore acts as a simple lock. It is also used to signal between threads, such as in the producer-consumer problem.
Q10.Explain the producer-consumer problem.
The producer-consumer problem describes coordinating threads that produce data and threads that consume it through a shared, bounded buffer. Producers must wait when the buffer is full and consumers must wait when it is empty, requiring synchronization to avoid data corruption. It is typically solved with semaphores or condition variables that track empty and full slots.
Q11.What is the difference between internal and external fragmentation?
Internal fragmentation is wasted space inside an allocated block when the request is smaller than the block, common with fixed-size paging. External fragmentation is wasted space scattered between allocated blocks, leaving free memory that is too fragmented to satisfy a large request, common with variable-size partitions. Paging removes external fragmentation but can cause internal fragmentation.
Q12.What is the role of the OS scheduler?
The scheduler decides which ready process or thread runs next on the CPU to optimize goals like throughput, response time, fairness, or turnaround time. Common algorithms include first-come first-served, round-robin, shortest job first, and priority scheduling. The right choice depends on whether the system is interactive, batch, or real-time.
Q13.What is the difference between user mode and kernel mode?
Kernel mode is a privileged CPU mode where code can execute any instruction and access all hardware, used by the OS core. User mode is restricted, so applications cannot directly access hardware or critical instructions and must request services through system calls. This separation protects the system from buggy or malicious programs.
Q14.What is a system call?
A system call is the controlled interface through which a user-mode program requests a service from the kernel, such as reading a file, allocating memory, or creating a process. It triggers a switch from user mode to kernel mode so the OS can perform the privileged operation safely. Examples include read, write, fork, and exec.
Q15.What is thrashing?
Thrashing occurs when a system spends more time swapping pages between memory and disk than executing useful work, because too many processes compete for too little RAM. Page faults skyrocket and CPU utilization collapses. It is mitigated by reducing the degree of multiprogramming, adding memory, or using working-set models to control allocation.
Q16.What is the difference between concurrency and parallelism?
Concurrency is structuring a program to handle multiple tasks that make progress over overlapping time periods, even on a single core through interleaving. Parallelism is actually executing multiple tasks at the same instant, which requires multiple cores or processors. A program can be concurrent without being parallel, and good concurrency design enables parallelism when hardware allows.
More interview topics
Practise & prepare
Practise Operating Systems out loud
Reading answers is step one. Rehearse them in OnJob's free AI mock interview, get instant feedback, then apply to AI-matched jobs in one click.