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 is a race condition, and what is the critical section problem?
A race condition happens when two or more threads access shared data at the same time and the result depends on the exact timing of their steps. The critical section is the part of code that touches that shared data, and the critical section problem is designing a way so only one thread runs it at a time, with progress and bounded waiting.
BeginnerIn-depth3 min read - What is context switching in an operating system?
Context switching is when the OS pauses the process or thread running on a CPU, saves its state (registers, program counter, stack pointer) in its control block, and loads the saved state of another one so it can continue. It lets many programs share one CPU, but each switch is pure overhead.
BeginnerIn-depth3 min read - What is the difference between a mutex and a semaphore?
A mutex is a lock that lets only one thread into a critical section at a time, and only the thread that locked it should unlock it. A semaphore is a counter that allows up to N threads to use a resource at once, and any thread can signal it, which also makes it useful for one thread to notify another.
BeginnerIn-depth3 min read - What is the difference between a process and a thread?
A process is a running program with its own memory. A thread is a unit of work inside a process; threads of the same process share that memory, so they are lighter to create but need care to avoid clashing.
BeginnerIn-depth2 min read - What are the FCFS, SJF, Round Robin and Priority CPU scheduling algorithms, and how do you calculate waiting time?
FCFS runs processes in arrival order, SJF picks the shortest job next and gives the lowest average waiting time, Round Robin gives each process a fixed time slice in turn for fair response, and Priority runs the most important process first but can starve low-priority ones unless aging is used.
IntermediateIn-depth4 min read - What is a deadlock and how can you prevent it?
A deadlock is when two or more processes wait for each other forever, each holding something the other needs. It needs four conditions together; breaking any one of them, for example always taking locks in the same order, prevents it.
IntermediateIn-depth2 min read - What is virtual memory, and how does paging work?
Virtual memory gives every process its own private address space that looks large and continuous, while the OS maps it onto real RAM in fixed-size blocks called pages (often 4 KB). A page table translates each virtual page to a physical frame, and pages not in RAM can be kept on disk and loaded on demand through a page fault.
IntermediateIn-depth4 min read - What is thrashing in an operating system, and how can it be prevented?
Thrashing is when a system spends most of its time moving pages between RAM and disk instead of running programs, because the running processes together need more memory than is available. It is prevented by giving each process enough frames for its working set, controlling page-fault rate, and reducing the number of running processes.
AdvancedIn-depth4 min read