270 likes | 370 Views
CS120: Lecture 6. MP Johnson Hunter mpjohnson@gmail.com. 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.
E N D
CS120: Lecture 6 MP Johnson Hunter mpjohnson@gmail.com
Agenda • Review • OSs: • History/motiv • Duties • Multiple processes • Modern history - Stephenson
Machines OS • Can now write programs • Complex programs still very difficult • I/O, mem management, etc. • Need an operating system
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
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
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
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
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
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
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…
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
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
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
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
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
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
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
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
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
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”
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
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!
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)
Modern OS history • Unix AT&T early 1970s • Apple II CLI late 70s • QDOS Tim 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
Stephenson… • hw • For next time: read ch 4