ctx->lectures->lecture0

Introduction to computation, hardware and UNIX

Turing Machines

A theoretical machine that performs actions on an infinite tape. These actions

  1. Can be determined by the value of the symbols on the tape.
  2. Include at least: reading/writing of the tape symbols, printing symbols.

In the above context the first introduces the "configuration" parameters, and the second introduces the "behaviour" at a given "configuration". The group of all the configurations and their transitions is called the state transition table, and if drawn as a diagram, it is called the state transition diagram.

Universal Turing Machine

Some examples follow. In the format STATE, READ, DO, GO (P means Print, * means anything).

A machine that writes 0s:

s1, *, P0, s1

A machine that writes 0s and 1s:

s1, *, P0, s2
s2, *, P1, s1

A tape negator (means it does 100100110001 -> 011011001110):

s1, 1, P0, s3
s2, 0, P1, s3
s3, *, R, s1||s2

(means s1 OR s2, since it depends on the next symbol)

Universal Turing Machines

We said that since these state transition tables, can be written on the tape, we could create a machine that has 2 tapes; from one we read the instruction (program code) and on the other one we execute it. therefore we have a Turing machine that can 'run' other machines. The Turing machine, that can run all possible other machines, is called a Universal Turing Machine.

Understanding the relation to modern computers

To have a "computer" we need at least a CPU and some kind of memory. Then the relation is straightforward. Code running on the CPU is the state transition table, which accounts for the "behaviour" of the system. Memory takes the place of the infinite tape, which determines (by what it contains) the "configuration" of the system.

Operating Systems

In this context what can an operating system be? Well, it is EVERYTHING between this previous image of a "computer" and what you experience in everyday life. This means, it is up to the operating system to introduce and implement the way that you control the machine. It is what connects your idea of a FILE object named myfile that you can myfile.open(), myfile.read(), myfile.delete(), myfile.write(). But as you can imagine, for this to be implemented we need to connect two pretty different things:

And this mess is just for simple files ;)

UNIX

Well the UNIX engineers (most notably Ken Thompson, Dennis Ritchie, Bill Joy) understood, that in order to bring such a diverse pair close, they needed Abstraction by Interfaces. This is actually a DESIGN PATTERN found not only in computer programs, but in nature also (Societies, Simple Machinery, onions?). So they designed UNIX to be a Multi-User, Multi-Tasking, Structured Operating System.

OS layers

The Unix Filesystem

The UNIX filesystem controls the way that information in files and directories is stored on disk and other forms of secondary storage. It controls which users can access what items and how. The filesystem is therefore one of the most basic tools for enforcing security on your system.

Information stored in the UNIX filesystem is arranged as a tree structure of directories and files. The tree is constructed from directories and subdirectories within a single directory, which is called the root. Each directory, in turn, can contain other directories or entries such as files, pointers (symbolic links) to other parts of the filesystem, logical names that represent devices (such as /dev/tty), and many other types. Remember! Everything in UNIX is a file, so you can do pretty cool things... (like reading thermal data from a sensor device (an external thermometer) by using the cat command (which just prints a file) on the device file that represents the thermometer (let's say it is /dev/sensor2). Then we would do cat /dev/sensor2 and the command would print the temperature as reported by the thermometer, in a human readable format).

Some programs to get you started (with examples)

ls: List contents of directory

% ls -al
% ls -alh
% ls -al /bsd

man: Prints manual of other commands

% man ls
% man ssh
% man man

cd: Change directory

% cd /etc
% cd /home/user # which is also cd ~, or just cd

pwd: Print working directory

% cd /var
% pwd
/var

cp: Copy a file

% cp myfile newfilecopy
% cp -r mydir/ mynewdir/

rm: Remove a file

% rm oldstupidfile
% rm -rf oldstupiddirectory/

ps: View system processes

% ps -ax # view all processes
% ps -xU luser # only luser's procs

more: Read a file

% more mytext # view mytext, press space for next page

grep: Search for something somewhere

% grep Password secretfile # find if secretfile contains the word Password

su: Become super-user (or another user)

% su # need to enter root password
% su - userA # become userA

Have a gift! A poster filled with history! Taken from Éric Lévénez.

Happy Hacking...

dsp@