Operating system interviews test processes and threads, CPU scheduling, synchronization with mutexes and semaphores, deadlock, memory management with paging and virtual memory, and page replacement. These 32 answers run two to four sentences each. Two Python scripts check the lock, deadlock, scheduling and page-fault numbers quoted.
On this page
Basics, processes and threads (Q1 to Q10)CPU scheduling (Q11 to Q15)Synchronization and deadlock (Q16 to Q23)Memory management (Q24 to Q32)Revision planFrequently asked questionsFor B.Tech, BCA and MCA students preparing for campus and fresher interviews, where operating systems is a standard theory round next to DBMS and networks. Answers are short and in the order interviewers tend to ask. The Python scripts were run on Python 3.9.6 and the numbers quoted are what they printed. The Linux memory-management concepts were checked against the kernel documentation on 1 December 2026.
Trends India shows interview-question searches for Java, Python, SQL, React and Node peaking from January to March, and those pages rank among the hub's recurring winners. The Search Console export of 26 November 2026 has no direct row for this page, so the "most asked" picks below are our reading, not data. For the two topics that get follow-ups, read process vs thread explained and deadlock in operating system explained.
Basics, processes and threads (Q1 to Q10)
- Q1. What is an operating system, and what does it do? It is the software between applications and hardware. It manages the CPU (scheduling), memory, files and devices, and gives programs a safe interface through system calls.
- Q2. What is the kernel? What is the difference between user mode and kernel mode? The kernel is the core that runs with full hardware access. User programs run in user mode and cannot touch hardware directly. They switch into kernel mode through a system call or an interrupt, then switch back.
- Q3. What is a system call? The controlled entry point into the kernel, such as opening a file or creating a process. A library function such as
printffinally calls a system call such aswrite. - Q4. What is a process, and what does its memory contain? A process is a program in execution with its own address space: code, data, heap (dynamic memory) and stack (function calls and locals), plus open files and a process control block (PCB) that the kernel keeps for it.
- Q5. What are the process states? New, ready (waiting for the CPU), running, waiting (blocked on I/O) and terminated. The scheduler moves a process between ready and running, and I/O completion moves it from waiting to ready.
- Q6. What is the difference between a process and a thread? A thread is a unit of execution inside a process. Threads of one process share code, heap and open files but each has its own stack and registers, so they are cheaper to create and switch. Processes are isolated from each other. See process vs thread explained.
- Q7. What is a context switch, and why is it costly? Saving one process's CPU state in its PCB and loading another's. It does no useful work itself, and it can also cool the CPU caches. Thread switches inside one process are cheaper because the address space stays.
- Q8. What is inter-process communication (IPC)? Ways for processes to exchange data: pipes, message queues, shared memory, sockets and signals. Shared memory is fastest but needs synchronization, while message passing is simpler and safer.
- Q9. What are zombie and orphan processes? A zombie has finished but still has a process-table entry because its parent has not read its exit status. An orphan is a running process whose parent has exited, so another process (on Linux,
init) adopts it. - Q10. What do
fork()andexec()do?fork()creates a child that is a copy of the parent and returns twice, 0 in the child and the child's id in the parent.exec()replaces the calling process's program with a new one. A shell runs a command by forking, then exec'ing in the child.
CPU scheduling (Q11 to Q15)
| Algorithm | Idea | Weakness |
|---|---|---|
| FCFS | First come, first served | Convoy effect: short jobs wait behind a long one |
| SJF | Shortest burst first, lowest average wait | Needs burst time in advance, can starve long jobs |
| Round robin | Fixed time quantum in a circle | Too small a quantum wastes time on switches |
| Priority | Highest priority first | Starvation, fixed by aging |
- Q11. What is the job of the scheduler? It picks which ready process gets the CPU next. Goals are high CPU use and throughput, with low waiting time, turnaround time and response time.
- Q12. Preemptive or non-preemptive scheduling? Preemptive lets the OS take the CPU from a running process (timer interrupt, higher-priority arrival). Non-preemptive lets a process run until it blocks or finishes. Modern general-purpose systems are preemptive.
- Q13. How do FCFS and SJF compare? For bursts 24, 3 and 3 run in that order, FCFS gave an average wait of 17.0. Running the shortest first gave 3.0. The script at the end of this section reproduces both.
- Q14. What is starvation, and what is aging? Starvation is a process waiting forever because others keep winning, as with priority scheduling. Aging raises a waiting process's priority over time so it eventually runs.
- Q15. What is the convoy effect? Many short processes stuck behind one long CPU-bound process under FCFS, which leaves other resources idle and raises average wait.
Synchronization and deadlock (Q16 to Q23)
- Q16. What is a race condition and a critical section? A race condition is when the result depends on the timing of threads touching shared data. The critical section is the code that touches it, and it must run one thread at a time. The script below counts to 40,000 safely with a lock.
- Q17. What are the requirements for a critical-section solution? Mutual exclusion (one at a time), progress (a free section is not blocked without reason) and bounded waiting (no thread waits forever).
- Q18. Mutex versus semaphore? A mutex is a lock that one thread holds and the same thread releases. A semaphore is a counter that allows up to N holders at once, and any thread can signal it. In the script, a semaphore of 2 kept peak concurrency at 2 across 6 threads.
- Q19. What is a monitor? A language-level construct that bundles shared data, the procedures that use it and a lock, so only one thread is inside at a time. Java's
synchronizedmethods work this way. - Q20. What is the producer-consumer problem? A producer adds items to a bounded buffer and a consumer removes them. You need a mutex for the buffer plus two semaphores for empty and full slots. A blocking queue gives this in practice, and the script runs one.
- Q21. What is a deadlock, and what are the four necessary conditions? Processes wait on each other in a cycle forever. All four must hold: mutual exclusion, hold and wait, no preemption and circular wait. Break any one and deadlock cannot happen. See deadlock in operating system explained.
- Q22. How are deadlocks prevented, avoided and handled? Prevention breaks a condition, for example by acquiring locks in a fixed order. Avoidance, such as the banker's algorithm, grants a request only if the state stays safe. Detection and recovery lets deadlock happen, then kills or rolls back a process. Many systems simply ignore it, the ostrich approach.
- Q23. What is the dining philosophers problem? Five philosophers share five forks and each needs two to eat. If all grab the left fork they deadlock. Fixes: number the forks and always take the lower first, allow only four at the table, or use an arbiter.
import threading, multiprocessing as mp
counter = 0
def work(lock, n):
global counter
for _ in range(n):
with lock:
counter += 1
def main():
lock = threading.Lock()
ts = [threading.Thread(target=work, args=(lock, 10000)) for _ in range(4)]
[t.start() for t in ts]; [t.join() for t in ts]
print("with lock:", counter)
# two threads take two locks in opposite order; timeouts expose the deadlock
a, b = threading.Lock(), threading.Lock(); gate = threading.Barrier(2); res = {}
def grab(name, first, second, wait):
with first:
gate.wait()
got = second.acquire(timeout=wait)
res[name] = got
if got: second.release()
t1 = threading.Thread(target=grab, args=("T1", a, b, 0.1)); t2 = threading.Thread(target=grab, args=("T2", b, a, 1.0))
t1.start(); t2.start(); t1.join(); t2.join()
print("opposite lock order, T1 gives up, T2 then finishes:", res)
# semaphore: at most 2 at once
sem = threading.Semaphore(2); peak = [0, 0]; m = threading.Lock()
def job():
with sem:
with m:
peak[0] += 1; peak[1] = max(peak[1], peak[0])
threading.Event().wait(0.05)
with m: peak[0] -= 1
js = [threading.Thread(target=job) for _ in range(6)]
[j.start() for j in js]; [j.join() for j in js]
print("peak concurrent:", peak[1])
# producer-consumer
import queue
q = queue.Queue(maxsize=2); out = []
def cons():
while (x := q.get()) is not None: out.append(x)
t = threading.Thread(target=cons); t.start()
for i in range(5): q.put(i)
q.put(None); t.join(); print("consumed:", out)
if __name__ == "__main__":
main()
Output (the second line shows two threads taking two locks in opposite order, which is a circular wait. One gives up on its timeout and the other then finishes):
with lock: 40000
opposite lock order, T1 gives up, T2 then finishes: {'T1': False, 'T2': True}
peak concurrent: 2
consumed: [0, 1, 2, 3, 4]
Memory management (Q24 to Q32)
- Q24. What is virtual memory? A technique that gives each process its own large address space, backed by RAM and disk. Only the pages in use sit in RAM, so programs can exceed physical memory and are isolated from each other.
- Q25. What is paging, and what is a page table? Memory is split into fixed-size pages (virtual) and frames (physical). The page table maps each page to a frame, and the hardware memory-management unit (MMU) walks it on every access. The TLB caches recent translations.
- Q26. Paging versus segmentation? Paging uses fixed-size blocks that the programmer never sees and removes external fragmentation. Segmentation uses variable-size logical units such as code and stack and can suffer external fragmentation.
- Q27. Internal versus external fragmentation? Internal is wasted space inside an allocated block, such as the unused end of the last page. External is free memory split into pieces too small to use. Paging avoids the second, and compaction fixes it.
- Q28. What is a page fault? An access to a page that is not in RAM. The OS traps, loads the page from disk (evicting another if needed) and restarts the instruction. It is far slower than a normal access, so a high fault rate hurts.
- Q29. Which page-replacement algorithms should I know? FIFO evicts the oldest page, LRU evicts the least recently used and optimal evicts the page used farthest in the future (a benchmark, not implementable). LRU is a good approximation of optimal. Real systems use cheaper approximations such as the clock algorithm.
- Q30. What is Belady's anomaly? Giving FIFO more frames can cause more faults. On the reference string 1,2,3,4,1,2,5,1,2,3,4,5, FIFO gave 9 faults with 3 frames and 10 with 4. LRU gave 10 and 8, because it is a stack algorithm and cannot show the anomaly.
- Q31. What is thrashing? The system spends most of its time swapping pages rather than running because too many processes compete for too little RAM. Fixes include fewer running processes, more memory or a working-set policy.
- Q32. Stack versus heap? The stack holds function frames and local variables, and is freed automatically on return. The heap holds dynamically allocated memory that the program or a garbage collector frees. Stack is fast but small, heap is flexible but can leak or fragment.
from collections import deque
def fifo_faults(refs, frames):
mem, q, faults = set(), deque(), 0
for p in refs:
if p not in mem:
faults += 1
if len(mem) == frames:
mem.remove(q.popleft())
mem.add(p); q.append(p)
return faults
def lru_faults(refs, frames):
mem, faults = [], 0
for p in refs:
if p in mem:
mem.remove(p)
else:
faults += 1
if len(mem) == frames:
mem.pop(0)
mem.append(p)
return faults
refs = [1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5]
print("FIFO 3 frames:", fifo_faults(refs, 3), "4 frames:", fifo_faults(refs, 4))
print("LRU 3 frames:", lru_faults(refs, 3), "4 frames:", lru_faults(refs, 4))
def avg_wait(bursts):
t = total = 0
for b in bursts:
total += t
t += b
return total / len(bursts)
bursts = [24, 3, 3]
print("FCFS order 24,3,3 average wait:", avg_wait(bursts))
print("SJF order 3,3,24 average wait:", avg_wait(sorted(bursts)))
Output:
FIFO 3 frames: 9 4 frames: 10
LRU 3 frames: 10 4 frames: 8
FCFS order 24,3,3 average wait: 17.0
SJF order 3,3,24 average wait: 3.0
Revision plan
- Day 1 to 2: Q1 to Q10 and one drawing of process states and the address-space layout.
- Day 3: scheduling. Practise FCFS, SJF and round robin by hand on three jobs and compute average waiting time.
- Day 4 to 5: synchronization and deadlock. Be ready to write a mutex-protected counter and name the four deadlock conditions.
- Day 6: memory. Do a FIFO and LRU page-fault count by hand on one reference string.
- Day 7: read the two explainers, then do the networking set in computer networks interview questions and the DBMS interview questions.
Interviewers also ask language-level follow-ups such as threads in Java or the Python GIL. Prepare those from Java interview questions and Python interview questions.
Frequently asked questions
What are the most asked operating system interview questions?
No company publishes its question bank, so this is our reading. Expect process versus thread, the process states, deadlock with its four conditions, mutex versus semaphore, paging with page faults and a scheduling calculation. Questions 6, 18, 21, 25, 29 and 30 above are the ones to master first.
How do I prepare operating systems for a fresher interview?
Read the process, scheduling, synchronization, deadlock and memory topics in that order, then practise by hand: one scheduling table and one page-replacement trace. Write a small thread program yourself so mutex and race condition are not just words.
What is the difference between a process and a thread in an interview answer?
A process has its own address space and is isolated. Threads inside a process share code, heap and files but have their own stack and registers. Threads are cheaper to create and switch, but a bug in one can corrupt shared data.
Do I need to know Linux commands for an OS interview?
For theory rounds, mostly concepts. For developer and DevOps roles, know basics such as ps, top, kill, chmod and grep, and how to read a process list. They are asked as practical follow-ups rather than as a separate round.
Is Belady's anomaly really asked?
It appears in college viva and some written tests, usually as 'which algorithm suffers from it and show an example'. FIFO does, LRU and optimal do not. Memorise the reference string used in the answer above and you can reproduce it.
Which OS topics are most important for software developer roles?
Our reading: processes and threads, synchronization, deadlock and virtual memory, because they show up in concurrency and performance questions. Scheduling algorithms and disk scheduling matter more for written tests than for coding interviews.
Learn this with mentors
Programmes for builders and engineers with admissions open: live classes, mentors and project work.


