The difference between character devices, block devices, and network devices in Linux

In Linux systems, there are three main types of devices: character devices, block devices, and network devices. They have some differences in data handling and access patterns.

  1. Character device:

    • Devices that perform input and output in units of bytes are called character devices. For example, keyboard, mouse, serial port, etc.
    • Character devices read and write data as streams, with no random access to data.
    • Character devices usually have buffered behavior, that is, multiple bytes can be read or written in one pass.
  2. Block device:

    • A device that performs input and output in blocks (usually a fixed size of 512 bytes or greater) is called a block device. For example, hard disk, solid state disk, etc.
    • Block devices support random access, allowing data to be read and written to specific blocks.
    • Block devices are usually managed by the file system and use caching to improve performance.
  3. Internet equipment:

    • Network devices are used for data communication through the network, such as Ethernet cards, wireless network cards, etc.
    • Network devices transmit data through the physical network, and use network protocols (such as TCP/IP) to send and receive data packets.
    • Network devices provide network communication functions to support remote data transmission.

These device types have corresponding drivers in the Linux kernel to manage and control them. Each type of device has different characteristics and modes of operation, so you need to understand the differences when programming and configuring your device. For example,

When reading and writing on character devices, you can use read()the and write()system calls,

It is still valid to use read()and on block devices , but it is more common to use file system interfaces (such as , , ) for data access.write()open()read()write()

In network device programming, the socket (Socket) API is usually used to realize network communication.

Guess you like

Origin blog.csdn.net/FLM19990626/article/details/131409197