cs120: lecture 6

27
1 CS120: Lecture 6 MP Johnson Hunter [email protected]

Upload: murray

Post on 08-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

CS120: Lecture 6. MP Johnson Hunter [email protected]. Agenda. Review OSs: History/motiv Duties Multiple processes Modern history - Stephenson. Program exec: add. Machines  OS. Can now write programs Complex programs still very difficult I/O, mem management, etc. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS120: Lecture 6

1

CS120: Lecture 6

MP Johnson

Hunter

[email protected]

Page 2: CS120: Lecture 6

2

Agenda• Review

• OSs:– History/motiv– Duties– Multiple processes– Modern history - Stephenson

Page 3: CS120: Lecture 6

3

Program exec: add

Page 4: CS120: Lecture 6

4

Machines OS

• Can now write programs

• Complex programs still very difficult

• I/O, mem management, etc.

• Need an operating system

Page 5: CS120: Lecture 6

5

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

Page 6: CS120: Lecture 6

6

Software taxonomy

Page 7: CS120: Lecture 6

7

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

Page 8: CS120: Lecture 6

8

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

Page 9: CS120: Lecture 6

9

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

Page 10: CS120: Lecture 6

10

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

Page 11: CS120: Lecture 6

11

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

Page 12: CS120: Lecture 6

12

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…

Page 13: CS120: Lecture 6

13

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

Page 14: CS120: Lecture 6

14

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

Page 15: CS120: Lecture 6

15

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

Page 16: CS120: Lecture 6

16

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

Page 17: CS120: Lecture 6

17

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

Page 18: CS120: Lecture 6

18

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

Page 19: CS120: Lecture 6

19

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

Page 20: CS120: Lecture 6

20

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 often hung

Page 21: CS120: Lecture 6

21

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

Page 22: CS120: Lecture 6

22

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”

Page 23: CS120: Lecture 6

23

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

Page 24: CS120: Lecture 6

24

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!

Page 25: CS120: Lecture 6

25

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)

Page 26: CS120: Lecture 6

26

Modern OS history

• Unix AT&T early 1970s• Apple II CLI late 70s• QDOSTim Patterson early 80s

– Purchase by Bill Gates for $50k • MS-DOS 1982• MacOS Apple 1984• Win3.0 MS 1990• Linux Linus Torvalds 1991• NT MS 1993• Win95 MS 1995• x64 MS 2005

Page 27: CS120: Lecture 6

27

• Stephenson…

• hw

• For next time: read ch 4