Operating systems fundamentals are a staple of technical interviews at Indian product companies and FAANG India. Google, Amazon, Microsoft, Flipkart, and Razorpay all test OS concepts in backend, systems engineering, and SDE roles. Topics cover processes, threads, CPU scheduling, memory management, deadlocks, and synchronisation. This guide covers OS interview questions for Indian companies in 2026.
Processes, threads, and process management
Process and thread fundamentals:
1. Process vs thread: Process: an instance of a running program. Has its own address space (code, data, heap, stack), file descriptors, and OS resources. Context switching between processes is expensive (full address space switch). Thread: a unit of execution within a process. Shares the process's address space, code, data, and heap but has its own stack and registers. Lighter than a process: creating/context-switching threads is cheaper than processes. Multiple threads in a process can communicate via shared memory but must synchronise to avoid race conditions.
2. Process states: New: process is being created. Ready: in memory, waiting for CPU. Running: executing on CPU. Waiting/Blocked: waiting for I/O, a lock, or a signal. Terminated: process has finished. Transitions: Ready → Running (scheduled by OS), Running → Waiting (I/O), Running → Ready (time slice expired, preemption), Waiting → Ready (I/O complete).
3. Inter-process communication (IPC): Pipes: unidirectional byte stream; parent-child communication. Named pipes (FIFOs): like pipes but persisted in the filesystem; unrelated processes can use them. Message queues: send discrete messages; supports multiple senders/receivers. Shared memory: fastest IPC (direct memory access between processes); requires synchronisation (semaphores, mutexes). Sockets: communicate between processes on the same or different machines (Unix domain sockets for local; TCP/UDP sockets for network).
4. Context switching: The OS saves the current process's state (registers, program counter, stack pointer) in its PCB (Process Control Block), loads the next process's state from its PCB, and resumes execution. Cost: time to save/restore state + cache misses (the new process has a cold cache; old process data is evicted). Minimising context switches is a key performance concern in high-throughput server applications.
CPU scheduling algorithms
Scheduling concepts and algorithms:
1. Scheduling goals: Maximise CPU utilisation, maximise throughput, minimise turnaround time (total time from submission to completion), minimise waiting time (time in the ready queue), minimise response time (time from submission to first response). Trade-offs: optimising throughput (batch jobs) conflicts with minimising response time (interactive apps).
2. Key scheduling algorithms: FCFS (First-Come, First-Served): non-preemptive; processes run in arrival order. Simple but poor average waiting time; convoy effect (short jobs wait behind long ones). SJF (Shortest Job First): schedule the shortest burst time job next. Optimal for minimising average waiting time but requires knowing burst time in advance (impractical). Can be preemptive (SRTF: Shortest Remaining Time First). Round Robin (RR): preemptive; each process gets a time quantum (10-100ms); after quantum expires, the process is put back in the ready queue. Best for time-sharing systems; response time proportional to quantum size. Priority scheduling: each process has a priority; highest priority runs first. Problem: starvation (low-priority processes never run). Fix: aging (increase priority of waiting processes over time). Multilevel queue: separate queues for different process types (foreground/background); each queue has its own scheduling algorithm.
3. Metrics: Turnaround time = completion time - arrival time. Waiting time = turnaround time - burst time. Response time = first response time - arrival time. CPU utilisation = (CPU busy time) / (total time). Throughput = number of processes completed per time unit.
4. Linux scheduling: Linux uses the CFS (Completely Fair Scheduler). Each process gets a fair share of CPU time proportional to its weight (determined by nice value). CFS tracks vruntime (virtual runtime) for each process and always schedules the process with the lowest vruntime. Real-time scheduling: SCHEDFIFO and SCHEDRR for hard real-time processes that need deterministic latency.
Memory management, virtual memory, and deadlocks
Advanced OS topics:
1. Memory management: Memory hierarchy: registers (fastest, smallest), L1/L2/L3 cache, RAM, disk. OS memory management goals: isolation (processes cannot access each other's memory), efficiency (use RAM fully), sharing (shared libraries mapped into multiple process address spaces). Segmentation: divides memory into logical segments (code, stack, heap). Paging: divides physical memory into fixed-size frames and virtual memory into pages of the same size. Page table maps virtual page numbers to physical frame numbers.
2. Virtual memory: Allows a process to use more memory than physically available by using disk (swap) as overflow. Demand paging: load pages only when needed. Page fault: accessing a page not currently in RAM triggers an OS interrupt; OS loads the page from disk and resumes execution. Thrashing: excessive paging when the working set of active pages does not fit in RAM; CPU spends more time handling page faults than executing instructions. Fix: increase RAM, reduce the number of concurrent processes, or use the working set model.
3. Page replacement algorithms: When RAM is full and a new page must be loaded, which page to evict? FIFO: evict the oldest page. Belady's anomaly: adding more frames can increase page faults. Optimal: evict the page that will not be used for the longest time. Not practical (requires future knowledge). LRU (Least Recently Used): evict the page not used for the longest time. Approximates optimal; commonly implemented in OS. Clock algorithm: approximates LRU with a use bit and a circular buffer.
4. Deadlock: Occurs when a set of processes are blocked, each waiting for a resource held by another process in the set. Four necessary conditions (Coffman conditions): (1) Mutual exclusion (resource cannot be shared), (2) Hold and wait (process holds a resource while waiting for another), (3) No preemption (resources cannot be forcibly taken), (4) Circular wait (circular chain of waiting processes). Prevention: eliminate one of the four conditions. Avoidance: Banker's algorithm: only allocate resources if the system remains in a safe state. Detection and recovery: allow deadlocks to occur; detect them via a resource allocation graph; recover by killing a process or preempting resources. Ignore (Ostrich algorithm): used by most OSes for rare deadlocks that are fixed by a reboot.
5. Semaphores and mutexes: Mutex (mutual exclusion lock): binary; only one thread can hold it at a time. Used to protect a critical section. Semaphore: integer counter; wait (P) decrements (blocks if 0), signal (V) increments. Binary semaphore: same as mutex. Counting semaphore: controls access to a resource with N instances. Deadlock in synchronisation: can occur if threads acquire multiple locks in different orders. Fix: always acquire locks in the same canonical order.
Frequently asked questions
Explore more