Input / Output Systems MCQs for the NSCT
Input/output (I/O) systems are the part of the operating system that moves data between the CPU, memory and devices such as disks, keyboards and network cards. The core question is how the CPU learns that a device is ready and who moves the data. The three answers are polling, interrupts and DMA, and buffering smooths out the speed differences. This is topic 11 of the 12 in the Operating Systems area, which carries 5% of the NSCT according to HEC's Areas of Competencies.
Operating Systems was the weakest area in 2026: candidates averaged 33.8%, the lowest of all ten areas, per the HEC NSCT report. I/O questions mix definitions with short overhead calculations, so learn the formulas below. This page follows Silberschatz's chapter on I/O systems, with Stallings's buffering model where noted.
Polling
In polling (programmed I/O with busy-waiting), the CPU repeatedly reads the device controller's status register until the busy bit clears, then writes the command and data itself.
Polling costs CPU time = polls per second × cycles per poll ÷ clock rate. Polling 1,000 times a second at 500 cycles a poll on a 1 GHz CPU uses 0.05% of the CPU.
Exam angle: polling is not always bad. If the device is ready within a few microseconds, a short busy-wait costs less than handling an interrupt.
Interrupts
With interrupts, the device raises a signal on the interrupt-request line when it is ready. After the current instruction, the CPU saves its state, looks up the handler in the interrupt vector and runs it. Some key terms:
- Maskable interrupts can be disabled during critical code. Nonmaskable interrupts cannot, and are reserved for events such as unrecoverable memory errors.
- Interrupt chaining: each vector entry points to a list of handlers when there are more devices than vector entries.
- Priority levels: a high-priority interrupt can pre-empt a low-priority handler.
Each interrupt costs a fixed overhead, so fast devices with one interrupt per byte or word can swamp the CPU. For example, a device sending 200,000 bytes/s with one 4-microsecond interrupt per byte uses 200,000 × 4 µs = 0.8 s of every second: 80% of the CPU.
Exam angle: the fraction of CPU time is interrupts per second × handler time. If it comes out above 100%, interrupt-driven I/O cannot keep up.
DMA
Direct memory access (DMA) hands block transfers to a DMA controller. The CPU writes a command block (source, destination, byte count), the controller moves the data over the bus, and the CPU gets one interrupt per block.
| Method | Who moves the data | Interrupts | Best for |
|---|---|---|---|
| Polling | CPU, busy-waiting | None | Very fast, short operations |
| Interrupt-driven | CPU, per byte or word | One per byte or word | Slow devices, such as keyboards |
| DMA | DMA controller | One per block | Disks, network cards, bulk data |
Take the same 200,000 bytes/s device with DMA and 4,096-byte blocks, at 20 µs of CPU time per block. That is about 48.8 blocks a second × 20 µs, roughly 0.1% of the CPU instead of 80%. While the controller uses the bus, the CPU may briefly lose memory cycles. This is called cycle stealing. Scatter-gather DMA moves data to or from several non-contiguous memory areas with one command.
Exam angle: DMA does not remove the CPU entirely. The CPU still sets up the transfer and handles the completion interrupt.
Buffering
A buffer is memory that holds data in transit. Silberschatz gives three reasons for buffering: a speed mismatch between producer and consumer, different transfer sizes between devices, and copy semantics (the data written is the data as it was at the time of the write() call).
Stallings models the time per block with T for input, C for processing and M for copying from the system buffer to the user area:
| Scheme | Time per block |
|---|---|
| No buffering | T + C |
| Single buffer | max(C, T) + M |
| Double buffer | max(C, T) |
Related kernel services:
- Caching keeps a copy of data that also lives elsewhere. A buffer may hold the only copy.
- Spooling queues whole jobs for devices, such as printers, that cannot interleave streams.
Exam angle: with double buffering, the slower of T and C sets the pace. Speeding up the faster one gains nothing.
Common traps
- Saying DMA uses no CPU at all. The CPU still handles setup, the completion interrupt and cycle stealing.
- Mixing up nonblocking and asynchronous calls. Nonblocking returns whatever is ready now; asynchronous finishes the whole transfer later and notifies the process.
- Counting 8 bits per character on a serial line that adds start and stop bits (10 bits per character).
- Treating a cache and a buffer as the same thing.
- Thinking memory-mapped I/O needs IN/OUT instructions. That describes port-mapped I/O.
Worked examples
1. Understanding. Is a keyboard a block device or a character-stream device, and why? Answer: a character-stream device. It delivers one byte at a time through get and put operations, with no seeking. Disks are block devices with random access.
2. Application. A network card raises 40,000 interrupts per second, each costing 15 µs. What share of CPU time do they use? Answer: 40,000 × 15 µs = 0.6 s per second, which is 60%. The card is a candidate for interrupt coalescing or polling under load.
3. Analysis. Using Stallings's model with T = 50 µs, C = 80 µs and M = 5 µs, what is the time per block with single buffering, and does double buffering help? Answer: single buffering takes max(80, 50) + 5 = 85 µs. Double buffering takes max(80, 50) = 80 µs. The job is CPU-bound, so only a faster CPU would help much.
Practise
The quiz below has 100 input/output systems questions, filterable by tier and difficulty.
Practise: 100 questions
FAQs
When is polling better than interrupts?
Polling is better when the device responds very quickly, so the busy-wait is shorter than the cost of an interrupt (saving state, running the handler, rescheduling). It also helps under very heavy load, as with network cards, where per-packet interrupts would swamp the CPU. Interrupts are better for slow or unpredictable devices.
What is the difference between memory-mapped and port-mapped I/O?
In memory-mapped I/O, device registers sit in the ordinary address space and are read and written with normal load and store instructions. In port-mapped (isolated) I/O, devices have a separate address space reached through special instructions, such as x86 IN and OUT. Memory-mapped registers must not be cached.
What are blocking, nonblocking and asynchronous I/O?
A blocking call suspends the process until the I/O completes. A nonblocking call returns at once with whatever data is ready, possibly none. An asynchronous call also returns at once, but the full transfer finishes later and the process is notified, for example by a signal or a callback.
Why does the OS spool printer output?
A printer can print only one job at a time. Spooling writes each process's output to its own file on disk and queues the files, so the printer handles complete jobs one after another instead of interleaving lines from several programs.
Next step
Continue to Protection & Security MCQs, the last OS topic. The previous topic is Secondary Storage Management. Revisit the Operating Systems MCQs hub or test yourself in an NSCT mock test.