In a multi-process system, Process P1 currently holds Printer A while waiting to acquire Scanner B. Simultaneously, Process P2 holds Scanner B while waiting to acquire Printer A. Neither process can proceed, and both remain frozen indefinitely. What phenomenon is occurring here, and what strategies can the operating system use to prevent, avoid, or recover from it?
Answer
Diagnosis: This is a classic deadlock.
Technical Reasoning: Each process is holding a resource while waiting for another resource held by the other, creating a circular wait condition where no process can release its resource or move forward.
Solutions:
- Prevent deadlocks by breaking the circular wait condition entirely.
- Use the Banker's Algorithm during runtime for dynamic deadlock avoidance.
- Implement a detection mechanism and recover by forcibly terminating or restarting one of the stuck processes.
A video editing software needs to simultaneously play back a live timeline preview, render background visual effects, and auto-save the project file without lagging. Should the developer use multiple separate processes or multiple threads within a single process for these tasks, and why?
Answer
Recommended Approach: Use multiple threads within a single parent process.
Technical Reasoning: Because these tasks live in the same process, they share memory space and can communicate or pass frame data with almost zero overhead. Creating entirely separate processes would burn up unnecessary system memory and introduce heavy, slow communication bottlenecks.
Three compute jobs arrive at the processor queue at the exact same moment: P1 requires 10 ms of CPU time, P2 requires 2 ms, and P3 requires 5 ms. Which CPU scheduling strategy (First-Come First-Served, Shortest Job First, or Round Robin) will achieve the absolute lowest average waiting time, and how do the others compare?
Answer
Winning Choice: Shortest Job First (SJF) is the winning choice for prioritizing the lowest average wait time.
Comparison:
- FCFS (First-Come, First-Served): Executes P1 -> P2 -> P3, forcing the tiny jobs to wait behind the massive one, causing a high average wait time.
- SJF (Shortest Job First): Executes P2 -> P3 -> P1, minimizing the average waiting time down to the absolute mathematical minimum.
- Round Robin: Divides CPU time fairly using fixed, cycling time slices.
An application is being compiled with distinct code instructions, runtime global variables, and a growing execution stack, all of which require completely different security access permissions (e.g., read-only vs. read-write). Which memory management scheme—paging or segmentation—is best suited for this structure, and why?
Answer
Recommended Approach: Segmentation is the ideal fit.
Technical Reasoning: Segmentation divides the virtual address space according to the natural, logical structure of the program itself, making it easy to mark a code segment as "read-only" and a stack segment as "read-write." However, if your primary system bottleneck is eliminating fragmented gaps in physical memory, Paging remains the preferred low-level choice.
A modern game requires 8 GB of active memory space to load its assets, but the computer running it only has 4 GB of physical RAM installed. How is the operating system able to successfully execute this game despite the physical hardware limitation?
Answer
Mechanism: Virtual Memory.
Technical Reasoning: The operating system utilizes virtual memory to create an illusion of expanded RAM by mapping inactive chunks of the program over to a dedicated space on the hard drive or SSD. Only the pages actively needed by the CPU are kept loaded in the physical RAM slots, allowing massive applications to execute smoothly on limited hardware.
A computer suddenly slows down to a crawl. The hard drive activity light stays completely solid, and overall CPU utilization drops down to near zero. What state is the system experiencing, what is happening under the hood, and how can it be resolved?
Answer
Diagnosis: Thrashing.
Technical Reasoning: The system has run so low on physical RAM that it is constantly hitting page faults, spending almost all of its clock cycles desperately swapping pages back and forth between disk and memory instead of executing actual software instructions.
Solutions:
- Upgrade the machine with more physical RAM.
- Kill a few non-essential running processes to drop the system load.
- Adjust the page replacement strategy to better track working memory sets.
A running application requests a lock on a system hardware resource. Before granting access, the operating system pauses to calculate whether enough total resources will remain for all other active processes to safely finish their work. What is this algorithmic mechanism called, and how does it decide whether to approve or postpone the request?
Answer
Mechanism: The Banker's Algorithm.
Technical Reasoning: It acts as a cautious credit manager, only granting a process's resource request if the resulting state leaves the entire system in a guaranteed "safe state." If the request risks putting the system into an unsafe zone where a deadlock could happen later, the request is postponed, and the process is forced to wait.
Two parallel application threads attempt to update the exact same bank account balance variable at the exact same millisecond. Without intervention, one thread reads the old balance before the other finishes updating it, causing a deposit or withdrawal to be lost. What is this phenomenon called, and how must the code be protected?
Answer
Diagnosis: Race Condition.
Technical Reasoning: Because multiple threads access and manipulate shared data concurrently without synchronization, the final outcome depends on the non-deterministic order of execution.
Solution: Protect the shared variable using a synchronization tool like a mutex, semaphore, or monitor, ensuring that only one thread can enter that critical section of code at any given moment.
A corporate network needs to manage concurrent access to a pool of 5 identical shared printers, while separately ensuring that a single system configuration file can only be edited by one administrator thread at a time. What synchronization primitives should be used for each task and why?
Answer
Recommended Primitives:
- Use a counting Semaphore to manage the printers, as it can track an available pool of multiple identical resources.
- Use a Mutex to protect the configuration file, as it enforces a strict, single-owner lock that ensures absolute mutual exclusion.
An actively running process suddenly has to wait for a slow disk read/write operation. The operating system instantly suspends it to let another ready process start utilizing the CPU. What is this transition called, what data structure is involved, and what is its primary drawback?
Answer
Mechanism: Context Switch.
Technical Reasoning: The OS safely snapshots the registers and state of the old process into its Process Control Block (PCB) and loads up the stored state of the new process.
Drawback: While vital for modern multitasking, frequent context switching introduces computational overhead that can slow down overall performance.
While a user is watching a full-screen video, they press a key on their keyboard to pause playback. How does the hardware signal the CPU to pause its current execution loop, and what specialized code handles the keypress before returning to the video?
Answer
Mechanism: Hardware Interrupt and Interrupt Service Routine (ISR).
Technical Reasoning: The keyboard hardware generates a physical electrical pulse (interrupt). This forces the CPU to temporarily pause its current execution loop, jump over to execute a specialized piece of code called an Interrupt Service Routine (ISR), process the keypress, and then seamlessly jump right back to where it left off in the video player.
System RAM is completely full, and an application triggers a page fault demanding a new virtual memory page from disk. The operating system must choose an old page to evict. What are the three primary page replacement algorithms used to make this decision?
Answer
Page Replacement Strategies:
- FIFO (First-In, First-Out): Booting out the oldest page in memory, like a basic queue.
- LRU (Least Recently Used): Looking backward to evict the page that hasn't been touched in the longest time.
- Optimal: A theoretical model that evicts the page that won't be needed for the longest time in the future.
A system has 50 MB of total free space scattered across memory in tiny 5 MB gaps, causing the OS to reject a new process demanding a single 20 MB block. Separately, a process is given a fixed 32 KB page but only uses 20 KB of it, wasting the remaining 12 KB. What are these two memory waste phenomena called?
Answer
Diagnosis:
- External Fragmentation: Enough total memory exists across scattered gaps, but it isn't continuous.
- Internal Fragmentation: Fixed-size blocks (like pages) allocate more space than a process actually needs, leaving the remainder locked up and wasted inside the block.
A modern web server splits its architecture so that one frontend process handles incoming user connections while a separate background process writes system logs to disk. Because these processes inhabit isolated memory spaces, what general category of mechanisms must they use to pass data, and what are the common options?
Answer
Mechanism: Inter-Process Communication (IPC).
Options:
- Shared Memory: Super fast, requires manual locking.
- Message Passing: Safer, uses system queues.
- Anonymous/Named Pipes: Great for simple, sequential data streams.
- Sockets: Ideal if the processes ever need to move to separate network machines.
An embedded vehicle safety system must detect a physical crash and deploy cabin airbags within a strict window of just a few milliseconds. Why can a general-purpose operating system like standard Linux not be trusted here, and what type of operating system is strictly required?
Answer
Required System: Real-Time Operating System (RTOS).
Technical Reasoning: A general-purpose OS cannot guarantee that background tasks won't delay critical operations. An RTOS guarantees deterministic scheduling, prioritizing strict execution deadlines above general throughput to ensure critical tasks run exactly when required without exception.
Premium Content
Unlock Scenario - Part 1 and all premium lessons with a subscription.
All premium lessons
Ad-free experience
Priority support
From ₹199.99/year — See plans