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