Pigmaei gigantum humeris impositi plusquam ipsi gigantes vident (Dwarfs standing on the shoulders of a giant may see farther than a giant himself) Bernard of Chartres, 12th Century

INTRODUCTION TO

Patricia J Riddle [email protected] Tutorials

• Monday 10-11 • Wednesday 11-12 • Thursday 10-11 and 12-1

• Alastair Abbott • [email protected] Overall Aim Informal Objective

• To understand the nitty-gritty stuff about how a computer does its thing. Big Picture

• Appreciate how a complex systems can be built using mostly independent layers. Overview of Part 1

• Understand what an is.

• Learn how an OS abstracts and interacts with hardware.

• Appreciate how we can hide complexity by building in layers UNIX

• We will use UNIX as a concrete example of an OS to illustrate (and play with) ideas. Part I: UNIX

• Basic understanding of UNIX and its filesystem • Familiarity with a common UNIX shell • Overview of simple commands: – Logging in/out (,,logout); looking around (,,), managing files (,,,,,) – Finding, viewing, printing, and editing files (,,,,… ) – Finding additional information using commands like man and – Regular expressions, wild cards – Building pipes (,,,… ) – Viewing and controlling processes (,bg,fg,,… ) • Shell scripting

Lecture 2 COMPSCI 215 6 Part I: UNIX (continued)

• Understand notions of files, directories and permissions

• Be able to and debug shell scripts for simple tasks – Shell variables, shell control statements and arithmetic

Lecture 2 COMPSCI 215 7 What’s in It for you?

• To pass COMPSCI 215 and

• do OS-related 3rd year courses – Operating systems – Computer Architercture More in it for you

• First, its fun!

• Write better programs because you understand the limitations and features of the underlying machine

• Troubleshoot problems quicker because you are familiar with more than one level of abstraction http://research.microsoft.com/~gbell/digital/timeline/quiz8r.htm

UNIX is Born • Initiated in 1969 by and • Motivation: a need for a “convenient interactive computing service” – The story goes that ... Ken wanted something to run a “Space Travel” game, and there was this unused PDP-7 sitting in the corner… – With the help of Dennis and a few more people, Ken wrote a small general- purpose -sharing OS turned to be very convenient to such extent that a more powerful PDP-11/20 has been bought!

Lecture 2 COMPSCI 215 10 UNIX is Named

• UNIX ⇔ UNiplexed Information and Computing System – It was originally spelled "Unics" – Coined in 1969 to describe a specific computer OS, the term "UNIX" now covers a whole of variations, e.g. Linux, Mac OS X, FreeBSD (Berkeley Standard Distribution), Solaris, … • The name followed an earlier system called "Multics" (Multiplexed Information and Computing Service) – Multics was a large multi-user OS that was being developed at Bell Labs shortly before UNIX was created in the early 70s – Brian Kernighan is credited with the name UNIX

Lecture 2 COMPSCI 215 11 UNIX Spread

• Whole system was re-written in “C” in 1973, and Bell Labs started to give it away – They were restricted by monopoly laws from selling software – Universities took it up, and graduates took it into industry • The UNIX OS is portable - this is why UNIX systems are available on practically every hardware platform – Apart from basic OS functions, UNIX provides users, system administrators, and programmers with a host of applications – It encourages users to combine multiple programs to solve a complex problem and offers a rich set of programming tools

Lecture 2 COMPSCI 215 12 http://content.answers.com/main/content/img/CDE/_IBMMFRM.GIF

UNIX is Adopted

The standard computer interface at that time looked like this for the IBM OS/360 JCL: //BATCHJOB JOB(‘12345‘),MSGCLASS=H,MSGLEVEL=(1,1), NOTIFY=ME, // USER=ME,REGION=400K //STEP1 EXEC PGM=HELLO //STEPLIB DISP=SHR,DSN=MY.LOAD.LIBRARY //SYSPRINT DD SYSOUT=* In this environment UNIX was a revelation: [pat]$ HELLO HELLO [pat]$

http://ftp.arl.mil/ftp/historic-computers/jpeg/pdp11,70.jpg Lecture 2 COMPSCI 215 13 Why Study UNIX?

UNIX MS Windows • Open design - • Closed Design - • Modular • Monolithic • Programmer-centric • User-centric • Popular on servers • Popular They may appear different, but … – All OS must ultimately provide the user the same utility – Abstract away hardware so that users do not have to worry about it

Lecture 2 COMPSCI 215 14 Two Types of User Interfaces

GUI - Graphical User Interface CLI - Command Line Interface • Easier to learn • Expressive • Aesthetics • Modular and flexible: • Obvious multi-tasking – multiple commands in one line or one command into multiple lines • Quicker • Remote access

www.mark13.org/toad/ horstmann.com/bigj/help/windows/tutorial.html Lecture 2 COMPSCI 215 15 The Maxtrix “Hack” What is an Operating System?

Definition • An OS manages the hardware and software resources of the computer system • It provides a stable, consistent way for applications to deal with the hardware without having to know all the details of the hardware Properties: • safe, efficient, abstract

Lecture 2 COMPSCI 215 17 The Shell

Unix provides user-level access to its features through a “command interpreter” called the “shell”: 1. Write a prompt (e.g. prid013@wintermute02:~$ or [pat]$ ) 2. Read a line of input 3. The first word is the command; the rest are to pass to that command 4. Find an executable matching the command “in the usual places” and run it 5. for the command to finish; when it does, go back to step 1.

Lecture 2 COMPSCI 215 18 Using University UNIX Account

• Connect from MS Windows using Putty • File → New Connection login.cs.auckland.ac.nz • Under-grad server is login.cs.auckland.ac.nz • Login using your UPI and NetAccount password • Put the mouse away!

Lecture 2 COMPSCI 215 19 Using University UNIX Account

Login as: ggim001 Password:

Linux wintermute02.cs.auckland.ac.nz 2.6.20-16-powerpc64-smp #3 SMP Thu Jun 7 19:39:25 UTC 2007 ppc64

The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

ggim001 wintermute02 501$

Lecture 2 COMPSCI 215 20 SSH to login.cs… from MacOSX 10.4.9

Lecture 2 COMPSCI 215 21 Fun UNIX Commands

ggim001 wintermute02 500$ echo HELLO HELLO echo - print a string ggim001 wintermute02 501$ ls ls - list files / directories Desktop Music Sites Documents Pictures Teaching cd - change directory Examples Public Temp ggim001 wintermute02 502$ cat - display contents of a file bmca012 pts/1 Jun 7 15:42 (125-237-234-216.jetstream.xtra.co.nz) who - display who’s logged in rjes009 pts/18 Jun 7 15:51 (fclj06.sfac.auckland.ac.nz) write - write to other people ggim001 pts/99 Jun 7 16:11 (georgy.tcs.auckland.ac.nz) mesg - do or do not disturb ggim001 wintermute02 503$ cd Temp man - your useful helper ggim001 wintermute02 504$ cat h215.txt HELLO, CLASS COMPSCI 215! ggim001 wintermute02 505$ mesg n ggim001 wintermute02 506$ write ggim001 [pts/99] write: write: you have write permission turned off

Lecture 2 COMPSCI 215 22 man mesg

MESG(1) BSD General Commands Manual MESG(1) NAME mesg -- display (do not display) messages from other users SYNOPSIS mesg [n | y] DESCRIPTION The mesg utility is invoked by a user to control write access others have to a terminal device. Write access is allowed by default, and programs such as (1) and write(1) may display messages on the terminal. The first terminal device in the sequence of devices associated with standard input, standard output and standard error is affected. Options available: n Disallows messages. y Permits messages to be displayed. If no arguments are given, mesg displays the present message status to the standard output. EXAMPLES Disallow messages from other users to the current terminal: mesg n

Lecture 2 COMPSCI 215 23 man mesg Allow messages from other users to ttyp1 (assuming you are also logged in on that terminal): mesg y 1 An error has occurred. COMPATIBILITY Previous versions of the mesg utility wrote the message status to the standard error output and affected the terminal attached to standard error without first trying the standard input or output devices. SEE ALSO biff(1), talk(1), (1), write(1) STANDARDS The mesg utility conforms to IEEE Std 1003.1-2001 (``POSIX.1''). A mesg command appeared in Version 1 AT&T UNIX.

BSD May 5, 2002 BSD (END) (to quit, ‘q’) Lecture 2 COMPSCI 215 24 man and

• man - on-line manual • apropos - search manual – Apropos means ‘suitable’, i.e. search for something suitable – Instead of apropos you can also use man -k • To read sections of manual: type • To quit reading: type ‘q’

Lecture 2 COMPSCI 215 25 apropos clock adjtime (2) - smoothly tune kernel clock adjtimex (2) - tune kernel clock alarm (2) - set an alarm clock for delivery of a signal clock (3) - Determine processor time clock (8) - query and set the hardware clock (RTC) clock_getres (3) - clock and time functions clock_gettime (3) - clock and time functions clock_settime (3) - clock and time functions hwclock (8) - query and set the hardware clock (RTC) oclock (1x) - round X clock xclock (1x) - analog / digital clock for X

Lecture 2 COMPSCI 215 26 man oclock OCLOCK(1) OCLOCK(1) NAME oclock - round X clock SYNOPSIS oclock [-option ... ] DESCRIPTION Oclock simply displays the current time on an analog display. OPTIONS -fg color choose a different color for the both hands and the jewel of the clock -bg color choose a different color for the background. -jewel color choose a different color for the jewel on the clock.

Lecture 2 COMPSCI 215 27 man oclock

-minute color choose a different color for the minute hand of the clock. -hour color choose a different color for the hour hand of the clock. -backing { When Mapped Always Not Useful } selects an appropriate level of backing store. -geometry geometry define the initial window geometry; see X(7x). -display display specify the display to use; see X(7x). -bd color choose a different color for the window border. -bw width choose a different width for the window border. As the Clock widget changes its border around quite a bit, this is most usefully set to zero. -shape causes the clock to use the Shape extension to create an oval window. This is the default unless the shapeWindow resource is set to false.

Lecture 2 COMPSCI 215 28 man oclock -noshape causes the clock to not reshape itself and ancestors to exactly fit the outline of the clock. -transparent causes the clock to consist only of the jewel, the hands, and the border. COLORS If you would like your clock to be viewable in color, include the following in the #ifdef COLOR section you read with xrdb: *customization: -color This will cause oclock to pick up the colors in the app- defaults color customization file: /usr/X11R6/lib/X11/app- defaults/Clock-color. Below are the default colors: Clock*Background: grey Clock*BorderColor: light blue Clock*hour: yellow Clock*jewel: yellow Clock*minute: yellow SEE ALSO X(7x), X Toolkit documentation AUTHOR Keith Packard, MIT X Consortium X Version 11 Release 6.6 OCLOCK(1) Manual page oclock(1x) line 13/79 (END)

Lecture 2 COMPSCI 215 29 For Tommorrow

• Try logging on to login – I will give away a free chocolate egg tomorrow to the 10th person who logs in to chaos.

• What is the command I will use to figure out the 10th person to log in to login? – I will give away a chocolate egg tomorrow to the person who emails me the best answer about how they figured out the command. Logging on to Unix Machine…

• Try logging on to login.cs.auckland.ac.nz – Let you be interested in all the students who logs in to login – Find out what UNIX command mentioned in this lecture could be used to figure out the 2nd or 4th person to log in? • Resources – There are literally hundreds of books in the library on UNIX • Look for ones with a phrase like “beginners” or “dummies”… – Web tutorials on UNIX: see a few links on the course web page – Also check out: http://www.cs.auckland.ac.nz/references/Unixhelp – Bruce Hutton’s notes on using UNIX: http://www.cs.auckland.ac.nz/~bruceh/lectures/210UNIX/UNIXLectures.pdf

Lecture 2 COMPSCI 215 31 Best Way To Learn: Use UNIX!

• Most of all, you will learn by trying things out while seated at a terminal – You can expect lots of sad things to happen when you start using UNIX, but it gradually gets easier – Silly little names for commands are the most annoying part – Try to look “under the surface” at the technical achievements of Unix, rather that getting into a panic trying to memorize commands • If you are feeling brave, try running Knoppix (boots off a CD - no installation required; a very friendly GUI to UNIX)

Lecture 2 COMPSCI 215 32 Best Way To Learn: Use UNIX!

• If you are feeling braver still, try installing Ubuntu Linux – Needs a good PC, a free partition, and a free weekend • If you want to use UNIX at home, install CYGWIN – Runs a UNIX emulator on MS DOS / MS Windows – No way to send mouse events to UNIX through CYGWIN: put the mouse away! • Using your university UNIX account – Ugrad UNIX server is called login.cs.auckland.ac.nz – Login using your UPI and NetAccount password - see Slide 13: ssh [email protected]

Lecture 2 COMPSCI 215 33 Using University UNIX Account

• Ugrad UNIX server is called chaos.cs.auckland.ac.nz • Login using your UPI and NetAccount passwd

[pat]$ ssh [email protected] Password: chaos> bash prid013@chaos:~$

……… prid013@chaos:~$ exit chaos> logout Connection to chaos.cs.auckland.ac.nz closed. [pat]$