Computer Science from the Bottom Up

Categories:

Recommended

Chapter 1 – General Unix and Advanced C

1 Everything is a file!

An often-quoted tenet of UNIX-like systems such as Linux or BSD is everything is a file. Imagine a file in the context of something familiar like a word processor. There are two fundamental operations we could 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).

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 CD-ROM

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

Thus the concept of a file is a good abstraction of either a sink for, or source of, data. As such it is an excellent abstraction of all the devices one might attach to the computer. This realisation is the great power of UNIX and is evident across the design of the entire platform. It is one of the fundamental roles of the operating system to provide this abstraction of the hardware to the programmer.

It is probably not too much of a stretch to say abstraction is the primary concept that underpins all modern computing. No one person can understand everything from designing a modern user-interface to the internal workings of a modern CPU, much less build it all themselves. To programmers, abstractions are the common language that allows us to collaborate and invent.

Learning to navigate across abstractions gives one greater insight into how to use the abstractions in the best and most innovative ways. In this book, we are concerned with abstractions at the lowest layers; between applications and the operating system and the operating system and hardware. Many more layers lie above this, each worthy of their own books. As these chapters progress, you will hopefully gain some insight into the abstractions presented by a modern operating system.

2 Implementing abstraction

In general, abstraction is implemented by what is generically termed an Application Programming Interface (API). API is a somewhat nebulous term that means different things in the context of various programming endeavours. Fundamentally, a programmer designs a set of functions and documents their interface and functionality with the principle that the actual implementation providing the API is opaque.

For example, many large web applications provide an API accessible via HTTP. Accessing data via this method surely triggers many complicated series of remote procedure calls, database queries and data transfers, all of which are opaque to the end user who simply receives the contracted data.

Those familiar with object-oriented languages such as Java, Python or C++ would be familiar with the abstraction provided by classes. Methods provide the interface to the class, but abstract the implementation.

Attribution

Ian Wienand(2004-2022), Computer Science from the Bottom Up, URL: https://www.bottomupcs.com/

This work is licensed under the Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0):  (https://creativecommons.org/licenses/by-sa/3.0/).

VP Flipbook Maker

Unleash your creativity with VP Online Flipbook Maker! It is a professional tool for you to transform your PDFs and other documents into captivating flipbooks with intuitive steps.