Fifteen common OS interview questions
- What is the difference between a process and a thread?
- What is a context switch, and why is it costly?
- Explain the main CPU scheduling algorithms.
- What is a deadlock, and what are its four necessary conditions?
- How can deadlocks be prevented, avoided or detected?
- Mutex versus semaphore?
- What is a race condition, and how do you prevent it?
- What is the critical section problem?
- What is paging? What is a page fault?
- What is virtual memory, and why use it?
- What is thrashing?
- Internal versus external fragmentation?
- What are system calls?
- User mode versus kernel mode?
- What happens when you run a program?
Processes, threads and scheduling
- Process vs thread: a process has its own address space and resources; threads share their process's memory but have their own stack and registers. Threads are cheaper to create and switch, but shared memory needs synchronisation.
- Context switch: saving one task's CPU state and loading another's; costly because of the save/restore work and cache and TLB disruption.
- Scheduling: first-come-first-served (simple, convoy effect), shortest job first (optimal average wait, needs job lengths, can starve long jobs), round robin (time slices, fair, good for interactive work), priority scheduling (with ageing to prevent starvation), and multilevel feedback queues used by real systems.
Deadlocks and synchronisation
A deadlock needs all four Coffman conditions: mutual exclusion, hold and wait, no preemption, and circular wait. Prevent it by breaking one — most practically, acquire locks in a fixed global order to remove circular wait. Avoidance algorithms such as the Banker's algorithm grant resources only when the system stays in a safe state. Detection builds a wait-for graph and breaks cycles by aborting or preempting.
| Primitive | Use |
|---|---|
| Mutex | One thread at a time in a critical section; owned by the locking thread |
| Counting semaphore | Up to N concurrent users of a resource, such as a connection pool |
| Binary semaphore | Signalling between threads; not owned |
| Condition variable | Wait until a condition becomes true, used with a mutex |
| Spinlock | Very short waits on multi-core systems; wastes CPU otherwise |
Memory management
Paging splits virtual memory into fixed-size pages mapped to physical frames by a page table, removing external fragmentation (at the cost of some internal fragmentation in the last page). A page fault occurs when a page isn't in RAM and must be loaded from disk. Virtual memory gives each process its own large, isolated address space and lets the system use disk as overflow. When processes need far more memory than is available, the system spends most of its time swapping pages — thrashing — and throughput collapses. The TLB caches recent address translations to keep paging fast.
Kernel and user mode
User programs run in a restricted mode; privileged operations such as I/O and memory mapping require a system call that switches into kernel mode, where the OS performs the operation safely. This separation protects the system from buggy or malicious programs. “What happens when you run a program?” ties it together: the shell forks a process, exec loads the program, the loader maps it into memory, and the scheduler gives it CPU time.
Practising
Reading answers is not the same as saying them. Pick ten of the questions above and answer them aloud against a timer; a free AI interview assistant like CoPilot Interview can ask operating systems questions in a mock interview and flag answers that ran long or lacked an example. Pair this with Linux interview questions for the practical side, and computer networks questions for the rest of the core subjects.
Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly. Everything else on this page applies whichever tool you use, or none.
Frequently asked questions
What is the difference between a process and a thread?
A process has its own memory and resources; threads run within a process and share its memory while keeping their own stacks and registers, making them lighter but requiring synchronisation.
What are the four conditions for deadlock?
Mutual exclusion, hold and wait, no preemption and circular wait. Removing any one prevents deadlock; ordering lock acquisition removes circular wait.
What is virtual memory?
An abstraction giving each process its own large, isolated address space, mapped to physical memory by page tables, with disk used to hold pages that don't fit in RAM.
What is thrashing?
When the system spends most of its time moving pages between memory and disk because active processes need more memory than is available, so useful work collapses.
Practise on real interview questions
Run 145 real interview questions across 10 tracks, answer out loud and see a structured answer to compare with yours. Free, no signup.
Try a practice question