📝 Block and character devices in I/O Systems (11 MCQs)
Two Fundamental Device Access Models
Block and character devices are two common categories used by operating systems to represent I/O resources. Block devices transfer data in addressable fixed-size units and commonly support random access, as with disks and solid-state drives. Character devices expose streams of bytes or characters, often through sequential operations, as with terminals and serial interfaces.
Why Different Device Semantics Need Distinct Interfaces
Storage devices must support operations on identifiable data blocks, often at arbitrary logical addresses. Terminals and serial ports behave more like streams, where data arrives or leaves sequentially. Treating both categories identically would obscure important semantics, such as seeking, buffering, request scheduling, and the ordering of incoming data.
Block Transfers and Character Stream Operations
A block device request identifies a logical block address, transfer length, and direction. The block layer may merge or reorder requests before dispatching them. Character device operations commonly read or write byte sequences through a stream-oriented interface. Drivers handle device-specific details, including readiness, buffering, and event notification.
Example of Disk and Terminal Access
A program requests block 120 from a storage device, and the block layer schedules the corresponding read. Another program reads 20 bytes from a terminal. The first operation targets an addressable storage unit, while the second obtains available stream data. A terminal read may return fewer bytes or wait for further input.
Random Access, Streaming and Performance
Block interfaces suit file systems, databases, and other workloads requiring addressable storage. Character interfaces suit terminals, serial ports, and devices producing continuous streams. The distinction describes common operating system abstractions rather than every physical device's internal design. Some devices expose specialised interfaces, and network hardware is often managed through dedicated networking structures.
Misconceptions About Block and Character Devices
'A block device transfers only one block per request' is false because requests can cover multiple blocks. 'A character device must transfer exactly one character' is incorrect because stream operations can transfer buffers of many bytes. 'All storage devices are character devices because data is binary' confuses data representation with the operating system's access model.
Exam Focus: Device Classification and Operations
Classify disks and SSDs as typical block devices, and terminals and serial ports as typical character devices. Compare random block addressing with stream-oriented access. Questions may ask whether seeking, request merging, or sequential reads apply to a given device abstraction and how the relevant driver handles data transfer.
Key Terms of Block and Character Devices
- Block device - Supports addressable fixed-size data units.
- Character device - Provides stream-oriented byte access.
- Logical block - Addressable storage unit.
- Random access - Access to selected data locations.
- Stream - Ordered sequence of bytes.
📝 All Block and character devices in I/O Systems MCQs
Q1. Which of the following best defines a character device in an operating system?
📖 Explanation: A character device delivers data as a stream of bytes without imposing a block structure, so reads and writes occur one byte at a time and are often unbuffered. Option B captures this definition. Option A describes block devices, which use buffers and fixed‑size blocks. Option C is unrelated to device classification, and Option D refers to metadata handling, not character I/O. Understanding this distinction helps developers choose the correct driver type for a given peripheral.
Q2. Why are multilevel interrupt priorities crucial for a modern operating system?
📖 Explanation: Multilevel priorities let the OS assign higher urgency to time‑critical devices (e.g., timers) and lower urgency to less critical ones (e.g., printers). The system can pre‑empt processing of low‑priority interrupts when a high‑priority interrupt arrives, improving responsiveness. Option C correctly describes this benefit. Option A is false because low‑priority devices are still serviced. Option B misstates the purpose—critical sections may defer interrupts but not all the time. Option D is inaccurate; the interrupt controller is essential for priority handling.
Q3. A program reads keyboard input via a character‑device driver that uses interrupt‑driven I/O. Which sequence correctly describes what happens after the user presses a key?
📖 Explanation: When the key is pressed, the keyboard controller raises an interrupt. The CPU detects the request, saves its current context, jumps to the interrupt handler, which reads the scancode from the device, places it into the driver’s buffer, and then executes a return‑from‑interrupt instruction. This flow matches option B. Option A describes polling, not interrupt‑driven I/O. Option C omits the interrupt step. Option D incorrectly claims the OS ignores the interrupt, which would lose the keystroke.
Q4. How does an interrupt controller eliminate the need for the CPU to poll every I/O device?
📖 Explanation: The interrupt controller monitors all device interrupt lines, determines which device raised a request, applies priority rules, and signals the CPU only for the most urgent interrupt. This prevents the CPU from constantly checking each device (polling). Option C correctly describes this mechanism. Option A still requires polling within groups. Option B confuses address mapping with interrupt handling. Option D misrepresents the controller’s role, as devices are not disabled globally by the controller.
Q5. A block‑device driver uses DMA to transfer a 4 KB sector and then relies on an interrupt to signal completion. Which statement about this design is most accurate?
📖 Explanation: In DMA‑based block I/O, the device moves the entire sector directly to memory while the CPU is free. Upon completion, the device raises an interrupt, informing the OS that the buffer now contains valid data. This is precisely what option C states. Option A is wrong because the CPU still needs notification of transfer completion. Option B reverses the order of events. Option D is false; DMA and interrupts are commonly used together to achieve efficient I/O.
Q6. During a critical section, the OS defers handling of a character‑device interrupt. What is the primary reason for this behavior?
📖 Explanation: Deferring interrupts while a critical section runs protects shared kernel data structures from concurrent modification, ensuring consistency. Option B captures this safety rationale. Option A is inaccurate; the device can still generate data, but the interrupt is masked. Option C misinterprets deferral as increasing interrupt frequency. Option D incorrectly suggests a switch to polling, which is not the purpose of deferring interrupts.
Q7. Why does the interrupt‑request line alone not tell the CPU which device needs service?
📖 Explanation: The interrupt‑request line indicates that *some* device needs attention but does not identify which one. The interrupt controller resolves this ambiguity by examining individual device lines and applying priority logic. Therefore, option B is correct. Option A is partially true about the binary nature but does not explain the identification issue. Options C and D are unrelated to the function of the interrupt‑request line.
Q8. A system receives both a high‑priority timer interrupt and a low‑priority disk‑completion interrupt simultaneously. Which outcome best reflects proper multilevel interrupt handling?
📖 Explanation: Multilevel interrupt handling ensures that higher‑priority events, such as timer ticks, pre‑empt lower‑priority ones like disk completions. Consequently, the CPU should execute the timer handler before attending to the disk interrupt, as described in option B. Option A reverses the priority order. Option C would violate real‑time requirements, and option D is not how distinct interrupt sources are typically managed.
Q9. An operating system must handle 100 000 interrupts per second on a server. Which design choice most helps maintain performance at this scale?
📖 Explanation: At very high interrupt rates, a hardware interrupt controller that prioritizes and queues requests, combined with multiple kernel threads that process different device classes, spreads the workload and prevents bottlenecks. Option C captures this scalable approach. Option A would waste CPU cycles. Option B creates a single point of contention. Option D would cause missed events and system instability.
Q10. Which statement correctly contrasts block and character devices regarding buffering and access patterns?
📖 Explanation: Block devices operate on fixed‑size blocks, support random access, and typically use kernel buffers to cache blocks. Character devices present a sequential byte stream and often forego buffering, delivering data as it arrives. Option C accurately reflects these differences. Option A swaps the definitions. Option B incorrectly claims identical buffering. Option D reverses the roles of the two device classes.
Q11. After a DMA engine finishes transferring a 4 KB block from a disk, the device controller raises an interrupt. Which action should the operating system’s interrupt handler perform first?
📖 Explanation: The first responsibility of the interrupt handler is to inform the OS that the DMA transfer is complete, which is done by marking the buffer as valid and waking any process that was blocked waiting for the I/O. This corresponds to option C. Option A adds unnecessary work and could cause recursion. Option B should occur after the buffer is known to be ready. Option D would unnecessarily stall other devices. This ordering ensures efficient use of DMA and timely notification to applications.