🎓 BookMCQ
← Back to 13. I/O Systems

📝 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.
2
Easy
5
Medium
4
Hard

📝 All Block and character devices in I/O Systems MCQs

Q1. Which of the following best defines a character device in an operating system?

A.Provides buffered I/O with fixed‑size blocks
B.Allows unbuffered, byte‑oriented access to hardware ✅
C.Represents a network socket only
D.Handles file system metadata
💡 Difficulty: easy | ✅ Correct: B

📖 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?

A.They allow the CPU to ignore low‑priority devices completely
B.They enable the OS to stop all interrupts during any critical section
C.They let the system respond faster to urgent events while still handling less urgent ones later ✅
D.They simplify hardware design by removing the need for an interrupt controller
💡 Difficulty: easy | ✅ Correct: C

📖 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?

A.The CPU polls the keyboard repeatedly until the key code appears
B.The keyboard controller asserts the interrupt line, the CPU saves state, runs the handler, stores the byte, then returns ✅
C.The driver writes the key code directly to a memory‑mapped register without an interrupt
D.The OS ignores the interrupt and the program must retry later
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.It groups devices so the CPU can poll one group at a time
B.It assigns a unique memory address to each device for direct access
C.It receives interrupt signals, prioritizes them, and forwards only the highest‑priority request to the CPU ✅
D.It disables all devices until the CPU explicitly enables them
💡 Difficulty: medium | ✅ Correct: C

📖 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?

A.DMA eliminates the need for any interrupt because the transfer is invisible to the CPU
B.The interrupt occurs before the DMA finishes, allowing the CPU to start processing early
C.The interrupt tells the OS that the DMA has finished, so the driver can mark the buffer as ready ✅
D.DMA and interrupts cannot be combined; they are mutually exclusive mechanisms
💡 Difficulty: medium | ✅ Correct: C

📖 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?

A.To prevent the device from sending any more data
B.To avoid corrupting shared data structures that the critical section is updating ✅
C.To increase the overall interrupt rate of the system
D.To force the device driver to use polling instead of interrupts
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.Because the line can only carry a binary high/low signal
B.Because multiple devices share the same line, requiring additional identification logic ✅
C.Because the line is only used for power management, not for interrupts
D.Because the CPU ignores the line during normal operation
💡 Difficulty: medium | ✅ Correct: B

📖 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?

A.The CPU services the disk interrupt first, then the timer interrupt
B.The CPU services the timer interrupt first, then the disk interrupt ✅
C.Both interrupts are ignored until the current process finishes its time slice
D.The system merges both interrupts into a single handler call
💡 Difficulty: hard | ✅ Correct: B

📖 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?

A.Polling each device in a tight loop
B.Using a single‑threaded interrupt handler for all devices
C.Employing an interrupt controller with priority queuing and distributing work to multiple handler threads ✅
D.Disabling interrupts entirely during user‑mode execution
💡 Difficulty: hard | ✅ Correct: C

📖 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?

A.Block devices provide unbuffered, byte‑wise access while character devices use fixed‑size buffers
B.Both device types always use the same buffering strategy, differing only in naming
C.Block devices employ block‑oriented buffering and allow random‑access reads/writes; character devices deliver a continuous byte stream without inherent buffering ✅
D.Character devices store data in fixed‑size blocks, whereas block devices stream data byte by byte
💡 Difficulty: hard | ✅ Correct: C

📖 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?

A.Immediately write the data back to disk to verify integrity
B.Update the file‑system metadata before checking the buffer contents
C.Mark the destination buffer as containing valid data and wake any waiting process ✅
D.Disable all further interrupts until the current handler returns
💡 Difficulty: hard | ✅ Correct: C

📖 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.

🔗 Related Topics (MCQs)