Operating Systems (OS) is one of the four CS fundamentals tested in Indian technical interviews: alongside DBMS, Networking, and OOP. Service IT companies (TCS, Infosys, Wipro) test OS in fresher rounds. Product companies test OS concepts at SDE-2+ level in the context of distributed systems and performance. This guide covers every major OS topic with interview-ready answers.
Process and thread questions
Q: What is the difference between a process and a thread? A process is an independent program in execution with its own memory space (heap, stack, code, data segments). Threads are lightweight execution units within a process that share the process's memory space (heap and code) but have their own stack and registers. Creating a thread is faster and cheaper than creating a process. Inter-process communication (IPC) is more complex than thread communication because processes do not share memory by default.
Q: What is a context switch? When the CPU switches from executing one process/thread to another. The OS saves the state (registers, program counter, stack pointer) of the current process and loads the saved state of the next. Context switches have overhead: this is why too many threads can hurt performance.
Q: What is the difference between multiprogramming, multitasking, and multithreading? Multiprogramming: multiple programs in memory, CPU switches when one does I/O. Multitasking: multiple processes running seemingly simultaneously via time-sharing. Multithreading: multiple threads within a single process running concurrently.
Q: What is a race condition? When two threads access shared data simultaneously and the outcome depends on the order of access. Solution: mutual exclusion via locks, semaphores, or atomic operations.
Scheduling and synchronisation
Q: What CPU scheduling algorithms should I know? FCFS (First Come First Serve): simple, convoy effect. SJF (Shortest Job First): minimum average waiting time, requires future knowledge. Round Robin: equal time slices, good for interactive systems. Priority Scheduling: priority-based, starvation possible. MLFQ (Multi-Level Feedback Queue): modern OS default, adapts based on behaviour.
Q: What is a semaphore? A synchronisation primitive with two operations: wait() (P: decrement) and signal() (V: increment). Binary semaphore (mutex): allows only one thread in the critical section. Counting semaphore: allows N threads simultaneously. Used to solve producer-consumer, reader-writer, and dining philosophers problems.
Q: What is a mutex vs a semaphore? A mutex has ownership: only the thread that locked it can unlock it. A semaphore has no ownership: any thread can signal. Mutex is used for mutual exclusion. Semaphore is used for signalling between threads.
Q: What are the four necessary conditions for deadlock? (Coffman conditions): Mutual Exclusion (only one process can use a resource at a time), Hold and Wait (a process holds a resource while waiting for another), No Preemption (resources cannot be forcibly taken), Circular Wait (a chain of processes each waiting for the next). Breaking any one condition prevents deadlock.
Memory management questions
Q: What is virtual memory? Virtual memory allows processes to use more memory than physically available by using disk as an extension. The OS maintains a page table mapping virtual addresses to physical addresses. When a referenced page is not in physical memory, a page fault occurs and the OS loads the page from disk.
Q: What is the difference between paging and segmentation? Paging: divides memory into fixed-size frames (physical) and pages (logical). Simple and avoids external fragmentation but causes internal fragmentation. Segmentation: divides memory into variable-size segments based on logical units (code, stack, heap). More natural to the programmer but causes external fragmentation.
Q: What is thrashing? When the OS spends more time handling page faults than executing processes: the system is memory-constrained and swapping pages in and out constantly. Prevention: working set model (keep only the active working set of pages in memory), increase physical RAM.
Q: What is the difference between stack memory and heap memory? Stack: automatic allocation, stores local variables and function call frames. Managed automatically (LIFO). Limited size. Heap: dynamic allocation (malloc/new), stores objects created at runtime. Must be manually freed or garbage collected. Unlimited (bounded by available memory). Stack overflow = stack exhausted. Memory leak = heap memory not freed.
OS fundamentals come up in every technical interview in India. Practise explaining concepts clearly with HireStepX's AI mock interviewer: talk through deadlock, virtual memory, and scheduling until it feels natural.
Practice freeOS interview questions in a distributed systems context
Product companies sometimes bridge OS concepts to distributed systems:
'How does an OS handle concurrent database writes?': File locking (fcntl), WAL (write-ahead logging in databases), and OS-level memory-mapped files with atomic operations.
'What happens when you run out of file descriptors on a Linux server?': The process gets EMFILE (too many open files) errors. Each socket/TCP connection consumes a file descriptor. High-concurrency servers must manage fd limits (ulimit -n) and ensure connections are properly closed. This is relevant to Node.js and Java application servers.
'Why does a multi-threaded application not always run faster on a multi-core machine?': Lock contention (threads waiting for the same lock), false sharing (cache lines bouncing between cores), context switch overhead, and non-parallelisable code (Amdahl's Law).
Frequently asked questions
Practice these questions on HireStepX