Interview Q&A / Operating Systems
Operating Systems interview questions
Processes, threads, scheduling, memory and deadlocks, in plain words.
Prefer rapid revision? Practise Operating Systems short interview answers →
- What does a page table entry contain besides the frame number?
Besides the frame number, an entry holds control bits: valid/present, read/write/execute permissions, a user/supervisor bit, a dirty (modified) bit and an accessed (reference) bit.
IntermediateQuick answer2 min read - What is a condition variable and why does wait() release the lock?
A condition variable lets a thread sleep until some condition becomes true. wait() atomically releases the lock and sleeps so other threads can change the state; on wakeup the thread reacquires the lock and rechecks.
IntermediateQuick answer1 min read - What is a monitor in operating systems, and how is it different from a semaphore?
A monitor bundles shared data with the procedures that access it, and the language guarantees only one thread is inside at a time. A semaphore is a bare counter that the programmer must use correctly everywhere.
IntermediateQuick answer1 min read - What is a spinlock, and when is it better than a lock that puts the thread to sleep?
A spinlock makes a waiting thread loop on the CPU until the lock is free. It is better when the lock is held for a very short time, because sleeping and waking cost more than a brief spin.
IntermediateQuick answer1 min read - What is livelock, and how is it different from deadlock?
In deadlock, processes are blocked and make no progress. In livelock they keep running and changing state in response to each other, but still make no progress, like two people repeatedly stepping aside in a corridor.
IntermediateQuick answer1 min read - What is the convoy effect in FCFS scheduling?
The convoy effect is when many short processes queue behind one long CPU-bound process, so the CPU and I/O devices sit idle in turns and average waiting time rises sharply.
IntermediateQuick answer1 min read - What is the difference between fork() and exec()?
fork() creates a new process that is a copy of the caller. exec() replaces the current process's program with a new one, keeping the same PID. Shells combine them: fork a child, then exec the command in it.
IntermediateQuick answer1 min read - What is the difference between user-level threads and kernel-level threads?
User-level threads are managed by a library in user space, and the kernel sees only one process. Kernel-level threads are managed by the OS itself, so they can run on several cores and block independently.
IntermediateQuick answer1 min read - What is the dining philosophers problem and how can it be solved?
Five philosophers sit round a table with five forks, and each needs two adjacent forks to eat. If all pick up their left fork together, everyone waits forever. Solutions include a fork ordering, a limit of four seated, or an asymmetric pickup.
IntermediateQuick answer1 min read - Why do operating systems use multi-level page tables?
A single flat page table needs an entry for every possible page, even unused ones. A multi-level table splits it into pieces and only allocates the pieces for regions actually in use, saving a large amount of memory.
IntermediateQuick answer1 min read - How does the Banker's algorithm decide whether a resource request is safe?
It pretends to grant the request, then checks whether some order exists in which every process can still finish with the resources left. If such a safe sequence exists, the request is granted; otherwise it waits.
AdvancedQuick answer2 min read - What is the Test-and-Set instruction and how does it provide mutual exclusion?
Test-and-Set is a hardware instruction that atomically reads a memory flag and sets it to 1. If it returned 0, the caller got the lock; if 1, someone else holds it. Because it is one indivisible step, two threads cannot both see 0.
AdvancedQuick answer1 min read