Operating Systems practice questions with answers
Practise operating system questions at your own pace: processes, threads, scheduling, deadlocks, memory, paging and synchronisation. Pick an answer to see whether you are right and why. Nothing is timed or ranked here; for that, play the Daily Quiz at 4 PM IST.
What is the main difference between a process and a thread?
easy
- Threads cannot run in parallel
- Threads of the same process share its memory; processes have separate address spaces
- Processes are always faster
- There is no difference
Answer: B. Threads of the same process share its memory; processes have separate address spaces
Explanation: Sharing memory makes threads cheap to create and communicate, but they need synchronisation to avoid races.
What is a context switch?
easy
- Changing the user interface theme
- Saving the state of the running process or thread and loading another's so the CPU can run it
- Switching between programming languages
- Restarting the OS
Answer: B. Saving the state of the running process or thread and loading another's so the CPU can run it
Explanation: Context switches allow multitasking but cost time (saving registers, switching memory maps, cold caches).
Which scheduling algorithm can cause starvation of long jobs?
easy
- First come, first served
- Shortest job first
- Round robin
- None
Answer: B. Shortest job first
Explanation: If short jobs keep arriving, a long job may never run. Ageing (raising priority over time) prevents this.
What is virtual memory?
easy
- Memory in the cloud
- An abstraction giving each process its own address space, mapped to RAM or disk by the OS and hardware
- Cache memory
- A RAM disk
Answer: B. An abstraction giving each process its own address space, mapped to RAM or disk by the OS and hardware
Explanation: It isolates processes and lets programs use more memory than physical RAM, with pages moved to and from disk as needed.
Which four conditions must all hold for a deadlock?
medium
- Mutual exclusion, hold and wait, no preemption, circular wait
- Starvation, ageing, paging, swapping
- Mutual exclusion, preemption, priority, polling
- Race, lock, signal, wait
Answer: A. Mutual exclusion, hold and wait, no preemption, circular wait
Explanation: These are the Coffman conditions. Breaking any one prevents deadlock, for example by acquiring locks in a fixed order to stop circular wait.
What is thrashing?
medium
- Overheating of the CPU
- The system spends most of its time swapping pages in and out instead of doing work
- A disk failure
- A type of malware
Answer: B. The system spends most of its time swapping pages in and out instead of doing work
Explanation: It happens when the working sets of running processes do not fit in RAM. Reduce the number of processes or add memory.
What is the difference between a mutex and a semaphore?
medium
- They are identical
- A mutex lets one owner hold the lock; a counting semaphore allows up to N concurrent holders
- A semaphore only works between processes
- A mutex is slower
Answer: B. A mutex lets one owner hold the lock; a counting semaphore allows up to N concurrent holders
Explanation: A binary semaphore looks like a mutex, but a mutex has an owner who must release it; a semaphore can be signalled by any thread.
With 3 page frames and FIFO replacement, how many page faults does the reference string 1, 2, 3, 4, 1, 2 cause?
medium
- 4
- 5
- 6
- 3
Answer: C. 6
Explanation: 1, 2, 3 fault (cold). 4 faults and evicts 1; 1 faults and evicts 2; 2 faults and evicts 3: 6 faults in total.
What is a race condition?
hard
- Two programs competing for the fastest CPU
- The result depends on the unpredictable timing of threads accessing shared data without proper synchronisation
- A scheduling algorithm
- A network timeout
Answer: B. The result depends on the unpredictable timing of threads accessing shared data without proper synchronisation
Explanation: counter++ is read, add, write: two threads can read the same value and one update is lost. Use locks or atomic operations.
What is Belady's anomaly?
hard
- More RAM always means fewer faults
- With FIFO page replacement, adding page frames can increase the number of page faults
- LRU can be slower than FIFO
- Caches are useless for random access
Answer: B. With FIFO page replacement, adding page frames can increase the number of page faults
Explanation: Stack algorithms such as LRU and the optimal policy never show this anomaly; FIFO can.
What does the TLB (translation lookaside buffer) do?
hard
- Stores files
- Caches recent virtual-to-physical page translations so most memory accesses skip a page-table walk
- Balances network load
- Schedules threads
Answer: B. Caches recent virtual-to-physical page translations so most memory accesses skip a page-table walk
Explanation: A TLB miss means walking the page table in memory. Huge pages reduce misses for programs with large memory footprints.
Which of these happen in user mode vs kernel mode? (Select the ones that need kernel mode)
hard
- Reading a file from disk
- Adding two numbers in a loop
- Allocating a new memory page from the OS
- Sending data over a network socket
Answer: A. Reading a file from disk; C. Allocating a new memory page from the OS; D. Sending data over a network socket
Explanation: Hardware access and memory management go through system calls into the kernel. Plain arithmetic runs entirely in user mode.