

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer

I have been writing an application in C++ that transmits radio messages by writing to a modem connected to the serial port. To do this I need to get a file descriptor using code of the form

fd1=open(“/dev/ttyS0″, O_RDWR | O_NOCTTY | O_NDELAY);

This made me curious about the nature of the items in /dev. To try to get an idea of the contents of these items I tried a

sudo cat /dev/ttyS0

only to get the message

cat: /dev/ttyS0: Input/output error

which didn't help my understanding at all. Are these items actually a file at all or just a kind of link that allows access to the driver functionality?

share|improve this question
up vote 5 down vote accepted

Well... everything in Linux is a file or a directory. Things in /dev are special files.

The majority of devices are either block or character devices; however other types of devices exist and can be created. In general, 'block devices' are devices that store or hold data, 'character devices' can be thought of as devices that transmit or transfer data. For example, diskette drives, hard drives and CD-ROM drives are all block devices while serial ports, mice and parallel printer ports are all character devices. There is a naming scheme of sorts but in the vast majority of cases these are completely illogical.

Devices are defined by type, such as 'block' or 'character', and 'major' and 'minor' number. The major number is used to categorize a device and the minor number is used to identify a specific device type. For example, all IDE device connected to the primary controller have a major number of 3. Master and slave devices, as well as individual partitions are further defined by the use of minor numbers.

Taken from Linux-Filesystem-Hierarchy

2 options:

  1. Try

     cat < /dev/ttyS0

    and see if that works.

  2. You might solve this error by adding your user to the same group (ie. dialout).

share|improve this answer
Thanks this is very informative. – mathematician1975 Jul 18 '12 at 18:44
'character devices' can be thought of as devices that transmit or transfer data. And hence why you get this: crw-rw---- 1 root dialout 4, 64 Feb 2 15:34 ttyS0 I assume that "c" refers to character. – JohnMerlino Feb 2 '14 at 23:19

From The Linux Documentation Project:



share|improve this answer

Your Answer


