Operating systems interview questionswith answers and explanations
23 original operating systems questions of the kind asked in technical MCQ rounds and interviews, each with the answer and a short explanation. To answer them yourself first, open the CS fundamentals practice.
- questions
- 23
- easy
- 12
- medium
- 8
- hard
- 3
Question 1
EasyWhich CPU scheduling algorithm can starve long processes when short jobs keep arriving?
- AFirst come, first served
- BRound robin
- CShortest job firstAnswer
- DMultilevel queue with ageing
Explanation
Shortest job first always picks the shortest waiting job, so a long job can wait forever if short jobs keep arriving. Ageing exists to prevent exactly this.
Question 2
EasyWhich of these is NOT one of the four necessary conditions for deadlock?
- AMutual exclusion
- BHold and wait
- CPreemptionAnswer
- DCircular wait
Explanation
The four conditions are mutual exclusion, hold and wait, no preemption and circular wait. Preemption itself breaks deadlock.
Question 3
EasyThrashing happens when:
- Athe CPU is fully busy with computation
- Bthe system spends most of its time moving pages in and out of memoryAnswer
- Ctwo processes share the same memory segment
- Dcache hits are too frequent
Explanation
With too little memory for the working sets, processes page-fault constantly and the system does almost no useful work.
Question 4
EasyWhich of these is NOT shared by the threads of one process?
- AThe stackAnswer
- BHeap memory
- CGlobal variables
- DOpen files
Explanation
Each thread has its own stack, registers and program counter. The heap, global data and open file descriptors belong to the process and are shared by all its threads.
Question 5
EasyWhat is a context switch?
- ASaving the state of the running process and loading the saved state of anotherAnswer
- BMoving a page from disk into memory
- CSwitching from user mode to kernel mode for a system call
- DCompiling a program into machine code
Explanation
On a context switch the OS saves the CPU state (registers, program counter and so on) of the current process in its PCB and restores another's. A system call alone changes the mode, not the process.
Question 6
EasyWhich page replacement algorithm can suffer from Belady's anomaly, where adding frames increases page faults?
- AFIFOAnswer
- BLRU
- COptimal
- DNone of these
Explanation
FIFO can fault more with more frames. LRU and Optimal are stack algorithms: the pages held with n frames are always a subset of those held with n + 1, so they cannot show the anomaly.
Question 7
MediumProcesses P1, P2 and P3 arrive at time 0, in that order, with CPU bursts of 5, 3 and 1 ms. Under round robin with a time quantum of 2 ms, when does P1 finish?
- A8 ms
- B7 ms
- C5 ms
- D9 msAnswer
Explanation
P1 runs 0 to 2, P2 2 to 4, P3 4 to 5 (done), P1 5 to 7, P2 7 to 8 (done), and P1 8 to 9. P1 finishes at 9 ms.
Question 8
MediumA counting semaphore S starts at 3. These operations run in order: P, P, V, P, P, V, P (P is wait, V is signal). What is the value of S at the end?
- A0Answer
- B1
- C2
- D−1
Explanation
Each P subtracts 1 and each V adds 1: 3 → 2 → 1 → 2 → 1 → 0 → 1 → 0. The value never needed to go below 0, so no process blocked, and S ends at 0.
Question 9
MediumHow does the Banker's algorithm deal with deadlock?
- AIt lets deadlocks happen and then kills processes to break them
- BIt grants a request only if the system stays in a safe state afterwardsAnswer
- CIt forbids a process from holding one resource while waiting for another
- DIt runs the process with the shortest burst first
Explanation
The Banker's algorithm is deadlock avoidance: before granting a request it checks that some order still exists in which every process can finish (a safe state). Detection and recovery, and breaking hold and wait, are different strategies.
Question 10
MediumA system uses 32-bit logical addresses and 4 KB pages. How many entries does a single-level page table for one process have?
- A2²⁰Answer
- B2¹²
- C2³²
- D2²²
Explanation
A 4 KB page needs 12 offset bits (2¹² = 4096). The remaining 32 − 12 = 20 bits give the page number, so there are 2²⁰ pages and 2²⁰ entries.
Question 11
EasyWhat does the TLB (translation lookaside buffer) store?
- ARecently used disk blocks
- BInstructions fetched from memory
- CProcess control blocks
- DRecently used page-to-frame translationsAnswer
Explanation
The TLB is a small, fast cache of page table entries. On a TLB hit the CPU gets the frame number without walking the page table in memory.
Question 12
EasyA child process has finished, but its parent has not yet called wait() to collect its exit status. What is the child called?
- AA zombie processAnswer
- BAn orphan process
- CA daemon
- DAn idle process
Explanation
A finished child whose entry stays in the process table until the parent reads its exit status is a zombie. An orphan is a running child whose parent has already exited.
Question 13
EasyWhich of these CPU scheduling algorithms is non-preemptive?
- ARound robin
- BFirst come, first servedAnswer
- CShortest remaining time first
- DPreemptive priority scheduling
Explanation
Under FCFS a process keeps the CPU until it finishes or blocks. Round robin preempts on a timer, and SRTF and preemptive priority preempt when a better process arrives.
Question 14
EasyWhen does internal fragmentation happen?
- AWhen free memory is split into many small holes that are not next to each other
- BWhen two processes map the same page
- CWhen a fixed-size block given to a process is bigger than it needs, wasting the space left inside the blockAnswer
- DWhen the page table is larger than one page
Explanation
Internal fragmentation is wasted space inside an allocated block, as with the unused end of a process's last page. Scattered free holes between allocations are external fragmentation.
Question 15
MediumWhich of these is NOT a requirement for a correct solution to the critical-section problem?
- AMutual exclusion
- BProgress
- CBounded waiting
- DAll processes must have the same priorityAnswer
Explanation
A correct solution needs mutual exclusion (one process inside at a time), progress (a free section is not held up) and bounded waiting (no process waits forever). Priorities are not part of it.
Question 16
MediumP1, P2 and P3 all arrive at time 0 with CPU bursts of 8, 4 and 2 ms. What is the average waiting time under non-preemptive shortest job first?
- A6.67 ms
- B2.67 msAnswer
- C4.67 ms
- D3.33 ms
Explanation
SJF runs P3 (0 to 2), then P2 (2 to 6), then P1 (6 to 14). The waits are 0, 2 and 6 ms, so the average is 8/3 ≈ 2.67 ms. FCFS in arrival order would average 6.67 ms.
Question 17
EasyWhich Unix system call creates a new process?
- Aexec()
- Bwait()
- Cfork()Answer
- Dexit()
Explanation
fork() creates a child that is a copy of the caller. exec() replaces the current process's program with a new one, without creating a process.
Question 18
HardAssuming every fork() succeeds, how many processes exist in total, including the original, after this C code runs?
if (fork() == 0) { fork(); }- A4
- B3Answer
- C2
- D8
Explanation
The first fork() makes one child. In the parent it returns the child's id, so the parent skips the block. In the child it returns 0, so the child forks once more. Original, child and grandchild: 3 processes.
Question 19
EasyWhat does virtual memory allow?
- ARAM to run faster than its rated speed
- BA process to use an address space larger than physical RAM, with parts kept on diskAnswer
- CPrograms to run without any page table
- DThe CPU cache to replace main memory
Explanation
Virtual memory gives each process its own address space and keeps only the pages in use in RAM, bringing others in from disk on a page fault.
Question 20
HardWith 3 page frames, initially empty, and LRU page replacement, how many page faults does this reference string cause? 5, 2, 7, 5, 3, 5, 6, 2, 5, 7
- A8
- B6
- C7Answer
- D5
Explanation
Faults on 5, 2, 7 (frames fill). 5 hits. 3 replaces 2 (least recently used). 5 hits. 6 replaces 7. 2 replaces 3. 5 hits. 7 replaces 6. That is 7 faults. (FIFO would give 8 and the optimal policy 6.)
Question 21
MediumUnder round robin scheduling, a running process moves to the ready state when:
- Ait requests disk I/O
- Bit finishes executing
- Cit waits for a child process
- Dits time quantum runs outAnswer
Explanation
A timer interrupt at the end of the quantum preempts the process and puts it back in the ready queue. Requesting I/O or waiting for a child moves it to the waiting (blocked) state instead.
Question 22
MediumWhich statement about mutexes and semaphores is true?
- AA semaphore can only take the values 0 and 1
- BA mutex lets any number of threads into the critical section
- CA mutex is released by the thread that locked it, while a counting semaphore can let several threads in at onceAnswer
- DSemaphores work only between threads of the same process
Explanation
A mutex has an owner and admits one thread at a time. A counting semaphore holds a count and admits up to that many, which suits a pool of identical resources. Only a binary semaphore is limited to 0 and 1.
Question 23
HardA disk head is at cylinder 100. The queue holds requests for cylinders 45, 130, 10, 160, 90 and 115. Using shortest seek time first (SSTF), what is the total head movement?
- A505 cylinders
- B240 cylinders
- C230 cylindersAnswer
- D210 cylinders
Explanation
SSTF always goes to the nearest pending request: 100 → 90 (10) → 115 (25) → 130 (15) → 160 (30) → 45 (115) → 10 (35). Total = 230 cylinders. Serving in queue order (FCFS) would take 505.