CS Fundamentals · Fresher-relevant
Operating Systems interview questions on processes, threads, scheduling, memory management, deadlocks, and virtual memory.
What is the difference between a process and a thread?
Tip: A process is an independent program with its own address space; a thread is a lightweight unit of execution within a process that shares its memory and resources. Threads communicate cheaply via shared memory but require synchronisation; processes are isolated and safer but costlier to switch.
What is a deadlock and what are the four necessary conditions?
Tip: Deadlock is a state where processes wait on each other forever. The Coffman conditions — mutual exclusion, hold and wait, no preemption, and circular wait — must ALL hold. Breaking any one prevents deadlock (e.g. impose a global lock-ordering to remove circular wait).
Explain virtual memory and paging.
Tip: Virtual memory gives each process a private, contiguous address space larger than RAM. The MMU maps virtual pages to physical frames via page tables; the TLB caches translations. Pages not in RAM live on disk and cause a page fault when accessed — excessive faulting is thrashing.
What is the difference between a mutex and a semaphore?
Tip: A mutex is a binary lock with ownership — only the locking thread can unlock it, used for mutual exclusion. A semaphore is a counter allowing N concurrent accesses (a binary semaphore is signalling, not ownership). Use a mutex for critical sections, a counting semaphore for limited resource pools.
Describe common CPU scheduling algorithms.
Tip: FCFS (simple, convoy effect), SJF (optimal average wait, needs burst prediction), Round Robin (time-sliced, fair for interactive systems), and Priority scheduling (risk of starvation, fixed by aging). Real OSes use multilevel feedback queues to balance throughput and responsiveness.
What is a race condition and how do you prevent it?
Tip: A race condition is when the outcome depends on the unpredictable timing of concurrent access to shared state. Prevent it by protecting critical sections with locks/mutexes, using atomic operations, or avoiding shared mutable state altogether (immutability, message passing).
What is the difference between paging and segmentation?
Tip: Paging divides memory into fixed-size pages/frames — simple, no external fragmentation, but internal fragmentation. Segmentation divides memory into variable-size logical units (code, stack, heap) matching program structure — external fragmentation but logical sharing/protection. Many systems combine both.
What happens during a context switch?
Tip: The OS saves the current process/thread's CPU registers, program counter, and stack pointer into its PCB, then loads the next one's state. It is pure overhead (no useful work), flushes some caches/TLB, so excessive switching hurts throughput.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.