Operating Systems

Cover processes and threads, CPU scheduling, synchronisation, deadlocks, memory management and virtual memory at interview depth.

Intermediate · about 10 hours · difficulty 3/5

Learn first: How Campus and Off-Campus Hiring Works

OS is a favourite theory topic in both service and product-company interviews. Focus on clear explanations with small examples.

Core concepts

  • Process vs thread, process states, PCB, context switching, user vs kernel mode, system calls.
  • CPU scheduling: FCFS, SJF, SRTF, Round Robin and priority scheduling. Be ready to compute average waiting and turnaround time for a small example. Starvation and aging.
  • Synchronisation: race conditions, critical section, mutex vs semaphore (binary and counting), producer-consumer, readers-writers and dining philosophers.
  • Deadlocks: four necessary conditions (mutual exclusion, hold and wait, no preemption, circular wait), prevention, avoidance with the Banker's algorithm, detection.
  • Memory management: paging, segmentation, fragmentation (internal vs external), TLB.
  • Virtual memory: demand paging, page faults, page replacement (FIFO, LRU, Optimal), Belady's anomaly, thrashing.
  • Basics of file systems and disk scheduling (often asked at service companies).

Pitfalls

  • Saying mutex and binary semaphore are the same; ownership is the key difference.
  • Memorising scheduling definitions without being able to draw a Gantt chart.

You are ready to move on when you can draw a Round Robin Gantt chart, list the four deadlock conditions with one way to break each, and run LRU on a page reference string.

Key concepts

  • Processes, threads, context switch
  • CPU scheduling algorithms
  • Mutex, semaphores, critical section
  • Classic synchronisation problems
  • Deadlock conditions and Banker's algorithm
  • Paging, segmentation, fragmentation
  • Virtual memory and page replacement
  • Disk scheduling

Mini project

Write a small simulator that takes a list of processes and prints Gantt charts and average waiting time for FCFS, SJF and Round Robin, plus a page replacement simulator for FIFO and LRU that counts page faults. Use it to answer 10 textbook numericals.

Check yourself

What are the four necessary conditions for deadlock, and how does the Banker's algorithm avoid it?

Free resources