Introduction

An operating system interacts with a huge variety of hardware devices. These devices differ in speed, functionality, communication style, and reliability. A keyboard behaves very differently from a printer, a hard disk, or a network card. Managing this diversity is one of the most important responsibilities of the I/O subsystem.

The operating system cannot treat all devices identically because each device has unique operational characteristics. Some devices transfer data one byte at a time, while others transfer gigabytes per second. Some devices are mechanical and slow, while others are electronic and extremely fast. Some generate continuous streams of data, while others respond only occasionally.

Understanding I/O devices is important because device behavior directly affects:

  • System performance

  • CPU utilization

  • Interrupt frequency

  • Scheduling efficiency

  • Data transfer strategies

What is an I/O Device?

An I/O device is any hardware component used to transfer data into or out of a computer system.

The term “I/O” stands for:

  • Input

  • Output

Some devices perform only input, some only output, and many perform both.

Examples include:

  • Keyboard

  • Mouse

  • Monitor

  • Printer

  • Hard disk

  • SSD

  • USB drive

  • Network card

  • Scanner

  • Camera

  • Microphone

The operating system communicates with these devices through controllers and drivers.

Fundamental Problem with I/O Devices

The major challenge is that devices are highly heterogeneous.

For example:

DeviceSpeed
CPU CacheNanoseconds
RAMVery Fast
SSDFast
HDDSlower
KeyboardExtremely Slow

This creates a huge performance mismatch.

Key Insight

I/O devices are usually much slower than the CPU

Because of this:

  • CPU cannot wait continuously

  • OS must coordinate communication efficiently

Classification of I/O Devices

Devices are classified based on behavior and functionality.

1. Human-Readable Devices

These devices interact directly with users.

Examples:

  • Keyboard

  • Mouse

  • Monitor

  • Printer

  • Touchscreen

Characteristics:

  • Relatively slow

  • User-dependent

  • Interactive

2. Machine-Readable Devices

These devices communicate with electronic systems.

Examples:

  • Sensors

  • Disk drives

  • Controllers

Characteristics:

  • Faster than human devices

  • Hardware-oriented

3. Communication Devices

Used for data transfer between systems.

Examples:

  • Network cards

  • Modems

  • Wi-Fi adapters

Characteristics:

  • Asynchronous communication

  • Packet-based transfer

Device Behavior Classification

This classification is extremely important in operating systems.

1. Block Devices

A block device transfers data in fixed-size blocks.

Examples:

  • HDD

  • SSD

  • USB drives

Characteristics:

  • Random access possible

  • Data organized into blocks

  • Supports buffering and caching

Example operation:

Read block 105

Key Insight

Block devices support direct/random access

2. Character Devices

Character devices transfer data one character or byte at a time.

Examples:

  • Keyboard

  • Mouse

  • Serial ports

Characteristics:

  • Sequential communication

  • No random access

  • Stream-oriented

Example:

Read next character

Key Insight

Character devices operate as data streams

3. Network Devices

Network devices behave differently from both block and character devices.

Characteristics:

  • Packet-oriented

  • Asynchronous

  • Variable-size data transfer

Examples:

  • Ethernet cards

  • Wi-Fi adapters

Device Speed Differences

One of the biggest operating system challenges is handling devices with drastically different speeds.

For example:

DeviceApproximate Speed
KeyboardVery Slow
HDDMedium
SSDFast
RAMVery Fast
CPUExtremely Fast

Why This Matters

If CPU waits directly for slow devices:

CPU utilization becomes very poor

This leads to mechanisms like:

  • Interrupts

  • DMA

  • Buffering

  • Spooling

Device Communication Modes

Devices communicate using different methods.

1. Synchronous Devices

CPU waits until operation completes.

Example:

  • Simple polling systems

Problem:

  • Wastes CPU time

2. Asynchronous Devices

CPU continues execution while device works independently.

Example:

  • Modern disks

  • Network cards

Key Insight

Modern systems heavily rely on asynchronous I/O

Blocking vs Non-Blocking Devices

Blocking I/O

Process waits until operation completes.

Example:

read(fd, buffer, size);

The process pauses until data arrives.

Non-Blocking I/O

Process continues even if data unavailable.

Used in:

  • Servers

  • Event-driven systems

Important Insight

Blocking affects process scheduling and responsiveness

Device Buffers

Since devices and CPU operate at different speeds, buffers are used.

A buffer is temporary storage between:

  • Device

  • CPU

  • Memory

Example

Keyboard typing:

  • Characters stored temporarily

  • OS reads them later

Why Buffers Are Needed

Without buffers:

  • Fast producer may overwhelm slow consumer

  • Data loss may occur

Spooling

Some devices cannot handle multiple requests simultaneously.

Example:

  • Printer

Instead of making processes wait:

  • OS stores jobs in queue

This is called:

Spooling (Simultaneous Peripheral Operations Online)

Example

Print jobs:

  • Stored on disk

  • Printed sequentially

Key Insight

Spooling allows sharing slow devices efficiently

Dedicated vs Shared Devices

Dedicated Devices

Used by only one process at a time.

Example:

  • Tape drives

Shared Devices

Multiple processes can use simultaneously.

Example:

  • Disk drives

Error Handling in Devices

Devices may fail due to:

  • Hardware faults

  • Communication errors

  • Power failures

The OS must:

  • Detect errors

  • Retry operations

  • Report failures

Example

Disk controllers use:

  • ECC (Error Correcting Codes)

Device Queues

Multiple processes may request same device.

OS maintains:

  • Device request queues

Scheduling determines:

  • Which request served next

This directly connects to:

  • Disk scheduling algorithms

Real-World Example

Suppose you save a file.

Sequence:

  1. Application issues write request

  2. OS invokes file system

  3. Disk driver sends commands

  4. Controller accesses disk

  5. Data transferred

  6. Completion interrupt generated

Even a simple file save involves multiple device layers.

Why Device Abstraction Matters

Imagine if every application needed to understand:

  • Disk geometry

  • USB protocols

  • Network signaling

Impossible.

The OS provides:

Device abstraction

Applications interact using simple operations like:

  • read()

  • write()

while OS handles hardware complexity.