1. Introduction

Once upon a time in a galaxy far, far away

1.1. Introduction

Let’s start identifying what we’re dealing with. Let’s name some of them. Have you ever opened a computer? If not, maybe you should. There’s a lot of cables and some of the components listed below in there.

  • Monitor, probably on your desk. If you don’t see this one, you’re probably blind.
  • Keyboard, the main input device you’re going to use.
  • Mouse, have you seen the original design? It should be called the cube.
  • Speakers, probably on your desk next to the monitor or built-in the same one.
  • Computer case, contains the essential components.
  • Power supply, as all the components require electricity.
  • The motherboard, holding together the other core components. It’s the main circuit board you see, where all the cables go.
  • The CPU, usually hidden beneth a fan.
  • Main memory, shouldn’t be too far from the CPU, a row of nice chips.
  • Hard disk, where the big data goes, like all the files.
  • Graphics card, if you’re into games, otherwise probably included in the motherboard.
  • Network card, nowadays often included in the motherboard.
  • USB hub, because you need more peripherals.
  • Floppy disk drive, on ancient systems used for storage and startup.
  • Optical disk drive (CD, DVD), successor of the floppy disk but nowadays mostly there to fill some space.

So that’s a lot of devices, but we’re going to discard most of them. For now, only the essential components are relevant. And that’s the CPU, Main memory, the Hard disk and of course the Keyboard. Other parts may appear (probably you’re looking at the display right now) but we’re not going to pay much attention to them.

This tutorial aims at teaching you operating system concepts. But what is an operating system (OS), anyhow? Well, there’s no clear definition so we can only specify vaguely. The OS is the most fundamental program running on your computer. It sets up a platform for other programs to run on. This has mainly two effects. First, you need to manage access to the various devices (generally, resource management [1]). E.g. you can’t have to programs writing to the same location on the hard disk. Second, it offers hardware abstraction. This means that it offers a way to access a class of devices (e.g. monitors), independent on what specific device (i.e. which brand or size) you have attached to your computer. Otherwise, every program would have to implement this itself (for every monitor!).

On most systems, the core functionality is provided by a single program, the kernel. It’s discussed a lot - and computer scientists can bash their heads in over details [2] - what should be included in the kernel. The Linux kernel does about the following:

  • CPU management
  • Memory management
  • Device drivers
  • Hard disk management (file systems)
  • Networking
  • Program execution and seperation
  • User separation

So it deals with the hardware abstraction and resource management mentioned above. With this it creates a solid basis for programs to run upon. But a kernel makes not yet a platform. A lot more is needed for this, a whole environment of programs. Only the combination of a kernel with some basic and complex programs provides all the functionality which is expected from an operating system.

The programs complete what the kernel does not offer: User access to the devices and possibilities offered by the kernel. You need a program which does the drawing on your screen (the windows), to show your desktop (the icons, the menus, ...), to browse your files, to play music, to display images, to browse the internet, to find newly attached devices, and many, many more.

One of the many benefits of free and open source software (FOSS) is that there’s not only one program which can do a certain task but very often, there’s several. You can build an operating system, by combining the kernel with your favourite tools [3]. That’s exactly what a Linux distribution is. Because building such a combination of tools isn’t as easy as it sounds, you usually don’t do it yourself but start off with an existing one. For example, this tutorial is based upon Debian and works equally well with its derivatives Ubuntu and variants thereof (xubuntu, kubuntu, ...). But there’s many others, like SuSE, RedHat or Gentoo and many more.

When we talk about Linux, we often mean a Linux distribution, without saying which one exactly. All of these distributions use the same kernel, and in fact Linux refers the kernel only. The kernel is written and maintained by the Linux foundation. Other software is developed independently and may also work with other kernels. In fact, many programs do. That’s because Linux is one kind of Unix (just as Debian is a kind of Linux) and many programs only require to be run on a unix system. For example, BSD, Solaris or Apple’s OSX are unix-like OS as well. For example, the GNU foundation provides many of the fundamental tools and you’ll find them on any of these platforms.

1.1.1. Exercises

  • In your own words, why do we need an OS?
  • What parts belong to the OS?
  • What are the responsibilities of the kernel?
  • Name 4 Linux distributions.
  • Name 3 operating systems.

1.2. Fressen und gefressen werden

A little bit of theory never harmed anyone. So before we start, there’s an important concept you have to understand.

Everything about the computer can be viewed as an input/output system. The computer itself, with input coming from keyboard and mouse and the output being the display or speakers. But also a program follows the same principle. There the input is the user input (e.g. whatever you type) and the output the program’s result. Output is meant very generally. It’s just any reaction. It can be text printed to the screen but also showing you a window, changing a window’s contents, playing sound, making noise, display an image, play a movie, learn to play tic-tac-toe or even an error.

_images/input_output.png

The output is usually what you want to achieve. The problem which we face as humans is usually what input we have to provide such that the program produces the output we desire. Or from a programmer’s perspective, we know the input and output and have to create a program which produces the latter from the former.

The beauty of this input/output model is its simplicity. But its implications are immense. And make the whole computing thing much, much easier.

  1. We don’t care how the machine is built internally. Two machines with the same input/output behaviour are equivalent, even if they are realized completely different. It doesn’t matter whether you build up your computer from relays or transistors and it’s no difference what language was used to code a program.
  2. Given the machine and input, the output is always the same. This is what we call determinism. The machine always does the same, independent on time or where you put it (unless that’s part of the input, of course). If this wasn’t true your computer would become pretty moody.
  3. The machine doesn’t care about how it gets the input or what happens to the output. As long as you state the same input, of course. But to the machine it doesn’t matter if its input was generated by a human or another computer or a thousand monkeys. It doesn’t even have a notion of it. The same is true for the output. The machine does its job, and that’s it. What you do with the result is no concern of the program. You can read it, listen to it, observe it, ignore it, give it to someone else, type it into another program. The job of a program is to produce the output, not to watch over it.
  4. There might be several input leading to the same output. That one’s just food for thought. A program might be trivial, for example producing text output “Hello” for any input it gets. It’s a valid machine, though not very useful.

So in the end, we use this model to isolate the parts of a computer. Each part, we is dedicated to some very specific task. And each part can run and be changed independently. Computers are extremely complex. No one understands everything about them in full detail. But with this isolation we achieve a breakdown of complexity. Then you only need to understand a small part. Which you can do.

Further, we need the notion of a second abstract model, the Von Neumann architecture. It states that there’s a processor and memory. Everything you do with a computer can be reduced to those two components. The memory holds all data and the CPU does all the computations. A program then is a set of instructions to the CPU. It can let the CPU get or store some data from memory and do some arithmetic operation (e.g. add up two values). Now, the major implication of this architecture is that there’s no difference between data and a program. The set of instruction - which is the program - can also be stored in memory, alongside the data (stored-program computer). You just point the CPU to the first instruction, then let it rattle down the whole set, executing one by one. Like this you can have a general purpose CPU and still run every program imaginable. In the end, that’s the power of computers - you use the same universal machine and one single set of hardware for everything.

_images/von_neumann_architecture.png

(Image from Wikipedia, Licensed under CC BY-SA 3.0 via Wikimedia Commons).

[1]A resource is any part of the computer which needs to be somehow controlled. That would for example be memory and hard disk access but also access to the CPU or network.
[2]For example the infamous flame war between Torvalds and Tanenbaum. The discussion was about what should be included in a kernel and how. Also see the Tanenbaum-Torvalds Debate.
[3]That would be Linux from scratch. At the end of this this tutorial, you will come very close to this.