All interview questions CS Fundamentals · 2026

Operating System Interview Questions

Operating Systems is a core CS-fundamentals topic in software and SDE interviews. These are the questions interviewers actually ask, with concise answers you can speak confidently.

16 questions with concise, interview-ready answers.

1. What is an operating system?

An operating system is the software layer that manages a computer's hardware and resources and provides services to application programs. It handles processes, memory, file systems, and I/O devices, and acts as an intermediary between the user and the hardware. Common examples are Windows, Linux, macOS, and Android.

2. What is the difference between a process and a thread?

A process is an independent program in execution with its own memory space (code, data, heap, stack), while a thread is a lightweight unit of execution that runs inside a process. Threads of the same process share its code, data, and heap but each has its own stack and registers. Because they share memory, threads communicate more easily and context-switch faster than separate processes.

3. What are the different states of a process?

A process typically moves through five states: new (being created), ready (waiting to be assigned to the CPU), running (instructions are executing), waiting/blocked (waiting for I/O or an event), and terminated (finished execution). The OS scheduler moves processes between the ready, running, and waiting states.

4. What is a context switch?

A context switch is the act of saving the state (registers, program counter, etc.) of the currently running process or thread and loading the saved state of another so the CPU can switch execution between them. It is what enables multitasking, but it is pure overhead — no useful work is done during the switch. Excessive context switching can hurt performance.

5. What are the common CPU scheduling algorithms?

Key algorithms include First-Come-First-Served (FCFS), which runs processes in arrival order; Shortest Job First (SJF), which picks the process with the smallest burst time; Round Robin (RR), which gives each process a fixed time quantum in turn; and Priority scheduling, which runs the highest-priority process first. FCFS can cause the convoy effect, SJF can starve long jobs, and Round Robin is preemptive and good for time-sharing systems.

6. What is a deadlock and what are its four necessary conditions?

A deadlock is a situation where two or more processes are each waiting for a resource held by another, so none can proceed. It can only occur when all four Coffman conditions hold simultaneously: mutual exclusion, hold and wait, no preemption, and circular wait. Breaking any one of these conditions prevents deadlock.

7. How can deadlocks be handled — prevention, avoidance, and the banker's algorithm?

Deadlocks can be handled by prevention (designing the system so one of the four conditions can never hold), avoidance (granting resources only if the system stays in a safe state), or detection and recovery. The banker's algorithm is an avoidance technique: before granting a request it simulates the allocation and grants it only if a safe sequence still exists in which every process can finish.

8. What is the difference between a semaphore and a mutex?

A mutex is a locking mechanism that allows only one thread into a critical section at a time, and it has ownership — only the thread that locked it can unlock it. A semaphore is a signaling mechanism with an integer counter; a counting semaphore can allow multiple threads up to a set limit, and a binary semaphore (value 0/1) behaves like a lock but without ownership. In short, a mutex is for mutual exclusion while a semaphore is for signaling and managing access to a pool of resources.

9. What is the critical section problem?

The critical section is the part of a program that accesses shared resources and must not be executed by more than one process at a time. The critical section problem is designing a protocol that lets processes cooperate while satisfying three requirements: mutual exclusion, progress (a process not in its critical section cannot block others), and bounded waiting (no process waits indefinitely). Solutions use locks, semaphores, or algorithms like Peterson's.

10. What is the difference between paging and segmentation?

Paging divides memory into fixed-size blocks called pages (and physical frames), so it suffers from internal fragmentation but no external fragmentation, and it is invisible to the programmer. Segmentation divides memory into variable-size logical units such as code, stack, and data, which can cause external fragmentation but maps naturally to the program's logical structure. Paging is the simpler hardware view; segmentation is the more programmer-friendly logical view, and some systems combine both.

11. What is virtual memory?

Virtual memory is a technique that gives each process the illusion of a large, contiguous address space that may be larger than the physical RAM. The OS keeps only the actively used pages in RAM and stores the rest on disk (in a swap area or page file), bringing pages in on demand. This allows more and larger programs to run than would fit in physical memory.

12. What is a page fault?

A page fault occurs when a program accesses a page that is mapped in its virtual address space but is not currently loaded in physical memory. The OS traps the fault, fetches the required page from disk into a free frame (evicting another page if needed via a replacement algorithm), updates the page table, and resumes the instruction. Too many page faults can severely slow a program because disk access is far slower than RAM.

13. What is thrashing?

Thrashing is a state where the system spends most of its time swapping pages in and out of memory rather than executing useful work, causing CPU utilization to collapse. It happens when there is too little physical memory for the active set of processes, so page faults occur constantly. It can be reduced by lowering the degree of multiprogramming, adding more RAM, or using the working-set model to manage page allocation.

14. What is the difference between internal and external fragmentation?

Internal fragmentation is wasted space inside an allocated block, when a fixed-size allocation is larger than the memory the process actually needs — common with paging. External fragmentation is wasted space outside allocated blocks, when free memory is split into small non-contiguous holes that together are large enough but cannot satisfy a request — common with variable-size allocation and segmentation. Compaction and paging are common ways to reduce external fragmentation.

15. What is the difference between multiprogramming and multitasking?

Multiprogramming keeps multiple programs in memory and switches the CPU to another whenever the running one waits for I/O, maximizing CPU utilization. Multitasking is an extension that rapidly time-shares the CPU among processes using small time slices so they appear to run simultaneously, giving better interactivity and response time. Multitasking is essentially multiprogramming with preemptive time-sharing.

16. What is the difference between kernel mode and user mode?

The CPU runs in two privilege levels: kernel (supervisor) mode, where code has full access to hardware and privileged instructions, and user mode, where application code runs with restricted access. User programs cannot directly touch hardware or critical resources; they request such services through system calls, which switch the CPU into kernel mode. This separation protects the OS and other processes from buggy or malicious user code.

Get these answered live in your real interview

NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.

Try NostrobeAI free