Chapter 1. General Unix and Advanced C

Table of Contents
Everything is a file!
Abstraction and function pointers
Standard File Descriptors

Everything is a file!

If you learn nothing else, you should remember that in UNIX everything is a file.

Imagine a file in the context something familiar like a word processor. There are two fundamental operations we can use on this imaginary word processing file

  1. Read it (existing saved data from the word processor).

  2. Write to it (new data from the user).

Now consider some of the common things attached to a computer and how they relate to our fundamental file operations.

  1. The screen

  2. The keyboard

  3. A printer

  4. A CDROM

The screen and printer are both like a write-only file, but instead of being stored as bits on a disk the information is displayer as dots on a screen or lines on a page. The keyboard is like a read only file with the data coming from keystrokes and the CDROM is similar but rather than randomly coming from the user the data is stored directly on the disk.

Thus a file is a good abstraction of all the devices attached to the computer. Some files may be read-only, or write-only, or indeed both.