Andy Tanenbaum Computer Architecture, Operating Systems and

Transcription

Andy Tanenbaum Computer Architecture, Operating Systems and
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
BLAISE PASCAL (1623-1662)
COMPUTER ARCHITECTURE,
OPERATING SYSTEMS AND UNIX
• Invented mechanical adding machine at 19
• Like modern computer: Broke down a lot, hard to fix
• Did much research in mathematics and hydrostatics
Andrew S. Tanenbaum
Vrije Universiteit
Amsterdam
1
2
BARON GOTTFRIED WILHELM VON LEIBNIZ (1646-1716)
•
•
•
•
CHARLES BABBAGE (1791-1871)
Taught himself advanced Latin and Greek
Entered University of Leipzig at age 14
Co-invented calculus (independent of Newton)
Invented binary numbers, 4-function calculator
•
•
•
•
Occupied Newton’s chair at Cambridge (never taught)
Built working Difference Engine (1832)
Designed Analytical Engine, but never completed it
Analytical Engine had processor, memory, I/O
Analytical
engine
3
ENIAC (1945)
•
•
•
•
•
4
EDVAC (1948)
Designed by J. Mauchley & J.P. Eckert at U. of Penn
Funded by the Army for numerical calculations
Contained 17,000 vacuum tubes
Speed: 5000 additions/sec
Programmed using jumper cables
• Designed by John von Neumann at U. of Penn.
• Program was stored in memory
• Many computers used this design for decades
5
6
1
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
IBM SYSTEM 360 (1964)
•
•
•
•
•
MINICOMPUTERS (1960s)
Family of six compatible mainframe
Used small integrated circuits (chips)
Used for scientific and commercial work
Widely used for COBOL (Y2K problem)
Made IBM dominant computer company for 20 years
•
•
•
•
PDP-1 (1961) cost $100K, occupied 2 m3
Individual departments could now buy a computer
Minis were used to control scientific experiments
President of DEC (once-dominant mini vendor) said:
– “Nobody needs a computer in his house”
PDP-11 family
had a run of
25 years
7
8
APPLE I (1976) AND APPLE II (1977)
•
•
•
•
IBM PC (1981)
•
•
•
•
•
Built by Steve Jobs & Steve Wozniak in Jobs’ garage
First mass market PC (millions sold)
Apple II: 4 KB RAM, 8 expansion slots, used color TV
Schools and individuals could now buy a computer
IBM wanted a game machine to compete with APPLE II
Instead, PC was used by corporations
Used 4.77 MHz Intel 8088 CPU, 16 KB RAM
IBM published the design, which led to clone industry
Current Pentium systems derive from this system
9
CURRENT SPECTRUM
Type
Disposable computer
Embedded computer
Game computer
Personal computer
Server
COW
Mainframe
Supercomputer
10
COMPUTER ARCHITECTURE
Price ($) Example
• What the computer looks like to the programmer
1 Greeting card
10 Watch, car, TV
• About the hardware interface, not the implementation
100 Home video game
1K Desktop or portable computer
10K Network server
• Components
100K Departmental minisupercomputer
– CPU
– Memory
– Input/Output
1M Batch data processing in a bank
10M Long-range weather prediction
11
12
2
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
VON NEUMANN VS BUS DESIGNS
BASIC CPU OPERATION
• A program is a sequence of instructions in memory
• PC (Program Counter) points to current instruction
• CPU fetches an instruction, executes it, advances PC
I/O
Von
Neumann
CPU
Memory
I/O
Program (in memory)
CPU
PC
CPU
Memory
I/O
I/O
Bus
Instruction
Instruction
Instruction
Instruction
Instruction
Instruction
Instruction
Instruction
13
CPU DATA PATH
TRENDS IN CPU ARCHITECTURE
CPU
Register
Register
Register
Register
Internal
bus
Arithmetic
Logic Unit
Operations
done here
ALU
14
• RISC engines
• Multiprocessors
• COWs
64 of the
VU DAS
machines
15
SOFTWARE
•
•
•
•
16
BATCH SYSTEMS (ca. 1960)
ENIAC used patch panels and jumpers
Early programmable machines used assembler
In 1957 FORTRAN was invented; is now obsolete
Until ca.1960 the programmer was the operator
Cards read
to tape on
small 1401
17
Computing
done on
big 7094
Printing
done on
small 1401
18
3
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
MULTIPROGRAMMING (1960s)
EARLY PC OPERATING SYSTEMS
• Running multiple programs together (time-sliced)
1
3
2
• Initially, no operating system
• Usually just a BASIC interpreter in read-only memory
• IBM PC had MS-DOS
Computer with
four programs
running at once
–
–
–
–
–
4
• If each program has an on-line user at a
remote terminal, it is called timesharing
Single user
No security
No multiprogramming
No windows or graphical interface
Based on typed commands
• IBM 360 was first commercial computer with it
19
20
GRAPHICAL USER INTERFACES
MICROSOFT WINDOWS
• History
–
–
–
–
–
–
Doug Engelbart (Stanford), 1968 WJCC
Xerox PARC
Steve Jobs visited PARC
Apple Lisa
Apple Macintosh
Windows
•
•
•
•
•
•
•
Doug Engelbart
• WIMP:
–
–
–
–
Windows
Icons
Menus
Pointing
MS-DOS
OS/2
Windows 1.0
Windows 2.0
Windows 3.0, 3.1, 3.11
Windows 95/98
Windows NT/2000
Worth $100 billion
(GDP of NL: $350 billion)
21
UNIX
•
•
•
•
•
•
•
22
MINIX/LINUX
1961 M.I.T. invented timesharing on the 7094
1965 Start of MULTICS as a computer utility
1969 Ken Thompson writes UNICS on PDP-7
1975 Bell Labs releases PDP-11 V6 to universities
1980 U. of Calif Berkeley releases 4 BSD for VAX
1983 AT&T releases System V
1988 POSIX attempts to unify BSD and System V
• 1987 AST releases MINIX (UNIX clone) w/source
(available free at: www.cs.vu.nl/~ast/minix.html)
• 1987 comp.os.minix formed with ca. 40,000 users
• 1987 AST gets 200 emails a day demanding stuff
• 1987 AST starts saying NO to everyone
• 1991 Linus Torvalds gets tired of NO, writes Linux
Ken (left)
Dennis (middle)
Bill (right)
23
24
4
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
UNIX PHILOSOPHY
UNIX IS A TIMESHARING SYSTEM
User 1
•
•
•
•
•
User 2
UNIX is a system for programmers, not grannies
Originally text-based, now GUIs available
Designed to be powerful, not easy for beginners
Small number of concepts that can be combined
Each program should do one thing and do it well
UNIX computer
User 4
User 3
UNIX is widely
used on network
servers
25
26
IMPLICATIONS OF TIMESHARING
UNIX LAYER STRUCTURE
• Because there are multiple users, security is needed
Users
To log in, you need a
login name and a password
Shell (user interface)
Utility programs
Operating system (kernel mode)
Hardware (SPARC, Pentium, RS6000, …)
• All users have a UID (User ID) used for security
• Files have owners and access to them is protected
27
28
KEY CONCEPTS IN UNIX
UNIX PROCESSES
• When a program name is typed, a process is started
• Process: a program in execution
– Program text
– Variables
– Environment
Computer after
Computer before
User types
command
Shell
process
• File
– Linear sequence of bytes
– Stored on disk; independent of programs
– Designed for maximum flexiblity
sh
sh
cc
29
30
5
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
PROPERTIES OF A PROCESS
FILES
• Each process has its own
–
–
–
–
–
–
• A file is a linear sequence of bytes
Memory
Program
Registers
Variables
Network connections
Files
• File names are 1-255 characters with no structure
• All ASCII characters are legal in file names
– Examples, .3 , a.b.c.d , :::
• Upper and lower case are distinct
– ABC and abc are different files
• Every file has an owner--the user who created it
• Each process is independent of all the others
31
32
FILE PROTECTION
DIRECTORIES
Root directory (/)
• rwx rwx rwx
bin
lib
usr
file.c
Other
Group
Owner
• rwx - - - - - • rwx r - - r - -
Only the owner can read/write/execute
Owner can rwx, others can just read
/bin
/lib
/usr
cat
cc
cp
dd
liba
libc
libm
ast
bal
jim
Working
directory
/usr/ast
/usr/bal
teaching
research
bureaucrating
students
projects
• Super-user can override all protection rules
33
LINKS
34
SPECIAL FILES
Root directory (/)
bin
lib
usr
• Block special files
/bin
/lib
/usr
cat
cc
cp
dd
liba
libc
libm
ast
bal
jim
/usr/ast
/usr/bal
teaching
research
bureaucrating
proposal
students
projects
grant
• Character special files
– No random access
– Example: printer (/dev/lp)
• Usual protection rules apply
shared file
Note: primary and link are indistinguishable
– Allow random access
– Example: disk (/dev/hd1)
/usr/ast/proposal
/usr/bal/grant
35
36
6
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
MOUNTED FILE SYSTEMS
SHELL
• You can mount one file system on another so
UNIX does not have any A:, C: like Windows
•
•
•
•
After mounting
Before mounting
Root dir
floppy
Root dir
file1
file2
file3
file4
dir
filea
fileb
filec
file1
file2
file3
file4
dir
The shell is the UNIX command interpreter
It is just a user program
If you don’t like the standard one, write your own
Many exist: Bourne shell, Korn shell, C shell
filea
fileb
filec
/dir/filec
37
38
COMMANDS
COMMON COMMANDS
• Simple commands
– date
– ls
•
•
•
•
•
•
•
•
# print the time and date
# list the current directory
• Commands can have arguments
– cat file1 file2 file3
# list three files on the screen
• Commands can have flags
– ls -l
– ls -ltr
# long listing of current directory
# long listing in reverse time order
cat
cc
cd
chmod
cp
cmp
grep
ls
•
•
•
•
•
•
•
•
make
man
mkdir
mv
prep
rm
split
troff
39
40
REDIRECTION
FILTERS
• Many little programs exist that transform their input.
They are called filters. Some examples:
• Output can be redirected
– date >x
–
–
–
–
–
–
–
• Input can be redirected
– grep pattern <file
• Both can be redirected
– prep <inf >outf
41
head
tail
sort
prep
rev
wc
uniq
42
7
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
PIPELINES
SHELL PROGRAMMING
List songs 11-20 from the top 40
• head -20 top40 | tail -10
• The shell is a programming language
• It has variables
– Example if you type
Count distinct words in combined file1 and file2
• cat file1 file2 | prep | sort | uniq | wc >output
v1=abc
echo $V1
# set the variable V1 to the string abc
# echo the contents of variable V1
it types back
abc
• Some built in variables:
– HOME, PATH, TERM, PS143
44
SHELL: FOR LOOP
• For statement
for i in 1 2 3 4 5 6
do mv $i Chap-$i
done
SHELL SCRIPTS
• You can put a sequence of shell commands in a file
• Shell scripts can have arguments: $1, $2, $3, etc.
• Same as
– Example: Make a file rhyme containing:
mv 1 Chap-1
mv 2 Chap-2
mv 3 Chap-3
mv 4 Chap-4
mv 5 Chap-5
mv 6 Chap-6
rev <$1 | sort | rev
- When you type
rhyme dictionary
– It outputs a rhyming dictionary to standard output
big
cat
dig
fat
hat
pig
• Other control statements: if, while, case
gib
tac
gid
taf
tah
gip
rev
sort
gib
gid
gip
tac
taf
tah
rev
big
dig
pig
cat
fat
hat
45
BACKGROUND PROCESSES
46
SEQUENTIAL AND PARALLEL EXECUTION
• If you type:
• (a ; b ; c) & (x ; y ; z) &
– make
all your files that have changed will be recompiled
and you wait until it is done
a
b
c
Process 1 runs a, b, c
x
y
z
Process 1 runs x, y, z
• If you type:
– make &
the compilations are started in the background
and you don’t have to wait to continue working
• Both of these process run in the background
47
48
8
Andy Tanenbaum
Computer Architecture,
Operating Systems and UNIX
49
9