Operating Systems Essentials

Beginner · 22 min read · High-Level Design, Foundations

Processes and threads, scheduling, synchronisation, deadlock, virtual memory, I/O models and fsync, with the classic numerical questions.

Operating-system questions are a standard part of many interview loops in India, including Amazon, Microsoft, Goldman Sachs, Adobe and campus hiring at most product companies, and they come up indirectly everywhere else.

This lesson is a focused refresher: the concepts interviewers actually ask about, explained through what they mean for real systems, and the classic numerical questions worked through.

Processes and threads

A process is a running program with its own address space (code, data, heap, stack), open files and resources. A thread is a unit of execution inside a process: threads share the process's memory and files, and each has its own stack, registers and program counter.

CPU scheduling

The scheduler picks which ready thread runs next on each core.

Synchronisation

When threads share data, a race condition occurs if the result depends on the timing of their operations. The code that touches shared data is the critical section, and a correct solution needs mutual exclusion (one thread inside at a time), progress (if nobody's inside, someone waiting can enter) and bounded waiting…

Deadlock

A set of threads is deadlocked when each waits for a resource held by another. All four Coffman conditions must hold at once:

Memory management

Each process sees its own virtual address space, as if it had all memory to itself. The hardware (MMU) translates virtual addresses to physical ones using page tables, in fixed-size pages (commonly 4 KB) mapped to physical frames.

I/O models: why event loops scale

epoll is why one Redis or Nginx thread can serve tens of thousands of connections: work is done only for sockets that are ready, and idle connections cost almost nothing. That's the answer to the classic C10K problem, and the reason real-time systems can hold many open connections per server.

Files, the page cache and durability

Interview questions

  • What's the difference between a process and a thread, and when would you choose processes?
  • How can one Redis or Nginx thread handle thousands of connections?
  • A write() call returned successfully. Is the data safe if the machine loses power?
  • What is thrashing, and how do you fix it?

Practice

Write your answer before opening the suggested one. Anything you mark "Partly" or "Missed it" comes back in your review deck.

Further reading

Key takeaways

  • Processes isolate; threads share memory. Context switches between processes cost more (address space, TLB).
  • Know the scheduling algorithms and their trade-offs; be able to compute waiting and turnaround times.
  • Mutex: ownership and mutual exclusion. Semaphore: a counter for limits and signalling.
  • Deadlock needs all four Coffman conditions; global lock ordering prevents it in practice.
  • Virtual memory gives isolation and lets memory exceed RAM; the TLB caches translations; thrashing means the working set doesn't fit.
  • FIFO, LRU and Optimal page replacement, and Belady's anomaly for FIFO.
  • epoll-style multiplexing lets one thread serve thousands of connections; write() isn't durable until fsync().

Previous: Networking Essentials · Next: Scalability: Vertical vs Horizontal