💻Technical12 min

Operating System Interview Questions

Operating Systems is where interviewers test whether you understand what happens beneath your code — how programs run concurrently, share memory, and avoid corrupting each other's data. For freshers the questions cluster tightly: process versus thread, deadlock and its conditions, CPU scheduling, and memory management. Learn these clusters well and you will handle most OS rounds.

Process vs Thread — The Opening Question

Almost every OS round starts here. Nail the memory-sharing distinction.

  • A process is an independent program in execution with its own memory (code, data, heap, stack).
  • A thread is the smallest unit of execution within a process; threads of a process share memory and files.
  • Context switching between processes is heavier than between threads.
  • Threads communicate easily via shared memory; processes need IPC (pipes, sockets, shared memory).

Deadlock — Know the Four Conditions

Deadlock is the most tested concurrency topic. Memorise the four Coffman conditions.

  • Mutual exclusion — a resource is held in non-shareable mode.
  • Hold and wait — a process holds one resource while waiting for another.
  • No preemption — resources cannot be forcibly taken away.
  • Circular wait — a closed chain of processes each waiting on the next.
  • Break any one condition to prevent deadlock; Banker's algorithm is used for avoidance.

CPU Scheduling — Compare the Algorithms

Be able to define each algorithm and state its trade-off, and compute average waiting time on a small example.

  • FCFS — simple, but suffers the convoy effect (long jobs delay short ones).
  • SJF — optimal average waiting time, but can starve long processes and needs burst prediction.
  • Round Robin — fair, responsive; performance depends on the time quantum.
  • Priority scheduling — can starve low-priority jobs; aging fixes it.

Memory Management — Paging vs Segmentation

This pair is a frequent question. Contrast fixed-size vs logical-size division.

  • Paging — divides memory into fixed-size pages/frames; removes external fragmentation but has internal fragmentation.
  • Segmentation — divides memory by logical units (function, array) of varying size; can cause external fragmentation.
  • Virtual memory uses paging plus disk to run programs larger than physical RAM.
  • A page fault occurs when a referenced page is not in memory and must be loaded from disk.

Synchronization — Race Conditions & Semaphores

Expect a question on how concurrent threads are kept safe.

  • A race condition is when the result depends on the timing of threads accessing shared data.
  • The critical section is code that must not run concurrently; protect it with a lock.
  • A mutex allows one thread at a time; a semaphore allows a counted number.
  • A binary semaphore behaves like a mutex; counting semaphores manage a pool of resources.

Common Interview Questions & Answers

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

A process is an independent program in execution with its own separate memory space — code, data, heap and stack. A thread is a lightweight unit of execution inside a process, and all threads of the same process share that process's memory and open files, keeping only their own stack and registers. Because of the shared memory, thread context switches and communication are much cheaper than between processes, which need inter-process communication.

Lead with the memory distinction — it is the crux of the answer.

Q2. What is a deadlock and how can it be prevented?

A deadlock is when a set of processes are each waiting for a resource held by another, so none can proceed. It requires four simultaneous conditions — mutual exclusion, hold and wait, no preemption, and circular wait. You prevent it by ensuring at least one condition cannot hold, for example by acquiring all resources at once (breaking hold-and-wait) or imposing a global ordering on resource requests (breaking circular wait). Avoidance uses the Banker's algorithm to only grant requests that keep the system in a safe state.

Listing all four Coffman conditions is what the interviewer is scoring.

Q3. Explain Round Robin scheduling and its main parameter.

Round Robin gives each ready process a fixed time slice called the quantum and cycles through them in order, preempting any process that exceeds its slice. It is fair and responsive, which is why it suits time-sharing systems. The critical parameter is the quantum: too large and it degrades to FCFS; too small and excessive context switching wastes CPU time.

Naming the quantum trade-off in both directions signals real understanding.

Q4. What is the difference between paging and segmentation?

Paging divides both logical and physical memory into fixed-size blocks called pages and frames; it eliminates external fragmentation but can waste space inside a page as internal fragmentation. Segmentation divides memory into variable-size logical units such as a function or array, which matches how programmers think but can cause external fragmentation. Modern systems often combine both.

Tie each scheme to its fragmentation type — that is the discriminating detail.

Q5. What is a race condition and how do you prevent it?

A race condition occurs when two or more threads access shared data concurrently and the final result depends on the unpredictable order of execution. You prevent it by protecting the critical section — the code touching shared state — with synchronization primitives such as a mutex, which permits one thread at a time, or a semaphore, which permits a fixed count. The goal is mutual exclusion over the shared resource.

Use the terms 'critical section' and 'mutual exclusion' explicitly.

Common Mistakes to Avoid

Saying threads have fully separate memory — they share the process's memory

Listing only two or three of the four deadlock conditions

Confusing which scheduling algorithm causes starvation vs the convoy effect

Mixing up internal (paging) and external (segmentation) fragmentation

Describing a mutex and semaphore as identical

Expert Tips

Practise computing average waiting time for FCFS, SJF and Round Robin on a 4-process example

Memorise the four deadlock conditions as a set you can rattle off

For every algorithm, prepare its one-line weakness (starvation, convoy effect, quantum sensitivity)

Relate synchronization to a real bug if you have hit one — it makes the answer memorable

Pre-Interview Checklist

6 items

Frequently Asked Questions

How much OS depth do freshers need?

Focus on the five clusters here — process/thread, deadlock, scheduling, memory management, synchronization. These cover the large majority of fresher OS questions.

Are numerical scheduling problems asked?

Yes, frequently. Be ready to compute average waiting and turnaround time for FCFS, SJF and Round Robin on a small set of processes.

Is OS asked in non-systems roles?

Core OS concepts appear even in web and data roles because concurrency and memory come up everywhere. The depth is lighter, but process vs thread and deadlock are fair game anywhere.

🎯

Ready to ace your next interview?

Practice with SpeakWell AI. Upload your resume → get resume-based questions → practice with AI interviewers → improve communication → track progress → get instant AI feedback.

Back to all guides