Transcript PPT

CS120: Lecture 6
MP Johnson
Hunter
[email protected]
1
Agenda
• Review
• OSs:
– History/motiv
– Duties
– Multiple processes
– Modern history - Stephenson
2
Program exec: add
3
Machines  OS
• Can now write programs
• Complex programs still very difficult
• I/O, mem management, etc.
• Need an operating system
4
OSs
• Stephenson: “An OS … was a very long
string of ones and zeroes that, when
properly installed and coddled, gave you
the ability to manipulate other very long
strings of ones and zeroes.”
• OS = prog / set or progs that
– Manages computer, files
– Helps you run programs
5
Software taxonomy
6
OS parts, tasks
• Shell: provide access
– Command-line, GUI (window manager)
– Give access to files
• Kernel: system housekeeping
– Booting
– Mem manage
– Security
– Comm with device drivers
– Process management
7
Booting
• Starting up the comp, so programs can run
• Last time saw:
– Can run prog, once instructions are in RAM
– Another prog could write them to RAM
– …but who runs that prog?
• Prob: for every running prog, some other
prog must have run it
8
Booting
• Short for “bootstrapping”
• Legend: German nobleman Baron
Münchhausen lifted himself out of a
swamp, by pulling his own hair
• Later version: pulled seft out of the sea,
but pulling his boot straps
9
Booting
• Soln: small prog (“bootstrap”) stored in ROM
memory
• At system startup, PC points to bootstrap
• When it runs, it copies OS into RAM
– And points PC there (JUMP)
• Now OS can take over…
– And load/run other programs
• Another analogy: throw bundle of roap
10
Booting
• Depending on ROM/BIOS, many
machines look for floppy/CD/USB
– Try to boot from there
• People install Linux on USB flash or iPod
– Boot from that
• Can also “dual-boot”
– Bootstrap asks users which OS
11
Mem manage
• Saw that PC points to mem location
• Each program has own space
• OS prevents from reading/writing other
program’s data
• Prob: may not have enough RAM to hold
all programs user runs
• Soln: virtual memory
– Redirect RAM request to HD
– Slow…
12
Security
• Commonest idea: login
– Prompt for user/pass
– In Win, press ctr-alt-del to login (why?)
• Finer-grain:
– Read/write permissions for each file/dir
• Some programs can’t write to HD
– Java applets, ActiveX
• Should they be able to listen on mic? Slashdot
13
Device drivers
• Main OS talks to device drivers
• They talk to device controllers,
– Which talk to device
• General msgs sent from OS become more
explicit
• OS doesn’t need to know about your partic
printer
– It just needs the right device driver
• Abstraction
Win x65
14
OS motiv
• In old days: each program run indy
– User writes prog, waits in line, runs, leaves
• First change: separate user, machine
– All programs given to computer operator, run by him,
results given back
• Next change: get all jobs, run as group
–
–
–
–
“batch processing”
Job described in JCL (job control lang)
Fast, automatic
But: if some bug, must start over from start
15
OS motiv
•  interactive programming/apps
– Command-line or GUI
• Convenient for user
• But slow: wasted time while waiting for user
input
• Not everyone gets a mainframe
• So other programs wait longer in line
• Soln: time-sharing (user jobs) / multitasking
(processes)
– one of major tasks of modern OS
16
Multiple processes
• Process/job/thread = single program
running
• Process state:
– Vals regs
– Vals in (its) RAM
– Program counter val
• Process != program
– Could have two instances of one prog running
– E.g., dbl-click on Notepad twice
17
Multiple processes
• Very common:
–
–
–
–
Clock prog ticks
Doc prints
Browser loads
Playing game
• NT has >100 processes, before you run anything
• Some machines have mult processors
– “dual-core”
• But usually >> processes running
– Can’t simply assign 1 to each processor
•  time-sharing
18
Time-sharing
• Keep track of running processes in
process table
– Vars for each process
– Where it’s at
• Divide time into time-slices
– E.g., 50 ms
• At end of timeslice, have interrupt
– Store info for curr proc in P.T.
– Restart another process from where left off
19
Time-sharing
• Has some overhead
– Memory of P.T.
– Time to switch
• But overall saves time
– Better uses time when waiting for user
• Modern OSs have “preemtive multitasking”
• In Win 95/3.1, OS less strict about
interrupting
20
•  often hung
Mult. procs  compet for resources
• What if 2 progs want to print/draw/read at same
time?
• Only 1 can have access at once, or else conflict
•  OS must control access how?
•
•
•
•
Simple idea: use a flag
1/0, set/clear, says whether printer in use
On req, if clear, allow and set; o.w., make wait
When done, set clear, or give to waiting prog
21
Flags
• Countereg:
• Prog1 requests prn
– Check: clear, so…INTERUPT…set and given
• Prog2 requests prn
– Check: clear so…INTERUPT…set and given X
• Soln: make check-and-set a single op
– “semaphore”
22
Spooling
• Related is spooling
• Won’t discuss strategies, but idea is:
• When app wants to send job to device,
take it, keep in buffer until device is ready
• Common e.g.: print spooler
23
Deadlock
• Very serious problem
• Two processes both waiting for resources,
– Both dependent on other
– Both “block” each other
• P1: wants to upload from HD to netw card
– Has HD access, waiting for netw access
• P2: wants to download from new to HD
– Has netw access, waiting for HD access
•  deadlock!
24
Dining philosophers (Dijkstra)
• 5 philosophers eating sushi, around table
• 5 chopsticks between them
• To eat, phil must pick up two adjacent
chopsticks, one at time
– Sets them down after each bite
• Goal: give strategy avoiding
– Deadlock and
– Starvation (of any phil)
25
Modern OS history
• Unix
• Apple II
• QDOS
AT&T
CLI
Tim Patterson
early 1970s
late 70s
early 80s
– Purchase by Bill Gates for $50k 
•
•
•
•
•
•
•
MS-DOS
MacOS
Win3.0
Linux
NT
Win95
x64
Apple
MS
Linus Torvalds
MS
MS
MS
1982
1984
1990
1991
1993
1995
2005
26
• Stephenson…
• hw
• For next time: read ch 4
27