COS 109 Wednesday October 21 • Housekeeping – Midterm next week 90 minutes to take it No class next Wednesday (can do midterm here then) Will be available from Wednesday 1201 AM to Friday 1159PM on blackboard Midterm review Next Monday (10/26) at 7PM in room to be announced – • Today’s class – Software we depend on The operating system (continued) The file system The cloud Fetching as part of Fetch/Execute cycle • Fetch is Event driven – The window manager listens for an event From keyboard Key down/key up From mouse Mouse motion, mouse button up or down From other device Game controller Speech interface • Identify where the command occurred – In which window on the screen • Identify the action that must be taken – Examples Type text into Word window Click command in window of executing program Click on resize corner of window Click on icon from window Click on icon from task bar Parsing commands – Type text into Word window Text is passed to Word program – Click command in window of executing program Command is passed to executing program – Click on resize corner of window Window manager Listens to mouse for stretching changes the geometry of the screen The application might tell the window manager how – Click on icon from window Action to be taken is identified – Click on icon from task bar Sleepy program comes back to life Parsing commands • Possibilities – Pass information to an existing command Type text into Word window Click command in window of executing program – Start new command Click on icon from window – Wake up existing command Click on icon from task bar – Modify the geometry of the display Click on resize corner of window Executing existing commands • Type text into Word window – Text is passed to Word program • Word program has previously been put into RAM. It is storing the text in space it has in RAM, so the new text is added to that RAM. – Von Neumann model – How is RAM managed? What if you need more What if you overflow your memory? What happens when you quit? Starting new command (cont.) • Have to identify the command – How to start Word Enter from a command line Select Word from the Start menu Click on icon for Word Click on a shortcut to the icon for Word Click on a file called Something.doc Click on an unidentified file and tell it to use Word to open Starting new command • Have to identify the command – How to start Word Enter from a command line Start>Run> C:\Program Files\Microsoft Office\Office15\WinWord.exe – Icons are just an improved User Interface In UNIX, use keyboard to create the command line In Windows, use mouse to click on icons. Starting new command (cont.) • Click on a file called Something.doc or Something.docx • Windows registry keeps track of such things – Basic file associations .doc or .docx Word .jpg Default Image viewer .vbs Visual Basic .mp3 .wav etc. various music formats – A newly installed program may change file associations Starting new command (cont.) • Once the command is found • • • • – C:\Program Files\Microsoft Office\Office15\WinWord.exe Locate the command on the disk Move the command to RAM Add it to the list of commands being executed Let it run How do you find it on disk? How do you know where to load it in RAM? How do you keep track of all running programs? The Window Manager • Maintains the geometry • Identifies events with windows • Confusion – Windows 7,8,10, … is the operating system – Underneath runs the window manager • How does the window manager work? Unresolved questions • • • • • How How How How How is RAM managed? do you find it on disk? do you know where to load it in RAM? do you keep track of all running programs? does the window manager work? • Answer – This is what the operating system does What an operating system does • manages CPUs, schedules and coordinates running programs – switches CPU among programs that are actually computing – suspends programs that are waiting for something (e.g., disk, network) – keeps individual programs from hogging resources • manages memory (RAM) – – – – loads programs in memory so they can run swaps them to disk and back if there isn’t enough RAM (virtual memory) keeps separate programs from interfering with each other and with the operating system itself (protection) • manages and coordinates input/output to devices – disks, display, keyboard, mouse, network, ... – keeps separate uses of shared devices from interfering with each other – provides uniform interface to disparate devices • manages files on disk (file system) – provides hierarchy of directories and files for storing information To run a program, the operating system must • fetch program to be run (usually from disk) • load it into RAM – maybe only part, with more loaded as it runs (dynamic libraries) • transfer control to it • provide services to it while it runs – reading and writing info on disk – communications with other devices • regain control and recover resources when program is finished • protect itself from errant program behavior • share memory & other resources among multiple programs running "at the same time" – manage memory, disks, network, ... – protect programs from each other – manage allocation of CPUs among multiple activities Managing memory • Initially – Some space reserved for the operating system – Rest of space for user programs • When a new program starts – Gets space for execution – Gets space for data • As a program executes – Can ask for more space – Can free up space • When a program stops – It’s memory is released Memory management Initially Op. Sys Memory management Initially Start Word Op. Sys Op. Sys Word.exe Word data Memory management Initially Op. Sys Op. Sys Start Word Word.exe Word needs More memory Word data Word data2 Memory management Initially Op. Sys Op. Sys Start Word Word.exe Word needs More memory Word data Word data2 Start Browser Broswer Memory management Initially Op. Sys Op. Sys Start Word Word.exe Word needs more memory Word data Word data2 Start Browser Word needs more memory Broswer Word data3 memory manager makes sure that boundaries between programs are maintained Memory management Op. Sys Op. Sys Start Word Word.exe Word.exe Word needs more memory Word data Word data Word data2 Word data2 Initially Start Browser Word needs more memory Op. Sys Browser Free Space Word Word data3 data3 Memory management Initially Start Word Op. Sys Word needs more memory Start Browser Op. Sys Op. Sys Word.exe Word.exe Word data Free space Word data2 Word data2 Word needs more memory Free Space Free Space Exit Browser Word Word Word frees space data3 data3 What if you run out of memory? • Use virtual memory – Have some memory in RAM, some in disk – Hide the details from the user – Make choices effectively paging Virtual Memory Browser data 2 Op. Sys Word.exe Word Word data data2 Browser Browser data Word Memory mapper data3 Requests for memory go through the memory mapper which finds the needed pages Virtual memory on disk Sidebar on speed • Difference between register, cache, RAM, disk – Registers are right there – can access right away – Cache is with the CPU – quickly accessible – RAM requires a request onto the bus Address decoding Returning data on the bus – Disk requires Request onto the bus Determining where data is on disk Spinning disk platter to get there Gathering data, putting it on the bus. Operating system controls devices • operating system hides physical properties of devices – device has specific capabilities, parameters, etc. – hardware and software in device and OS present these at higher level – e.g., printer logical view: put characters out in 66 lines of 80 characters physical view: paint individual bits of characters in raster across page – e.g., CD-ROM logical view: file system just like the one on the hard drive physical view: long spiral of individual bits read by a laser • OS uses device drivers to control physical devices – driver code has detailed knowledge of how to operate a particular device – implemented as functions that provide interface between specific capabilities of a device and what the operating system expects – loaded as part of OS as needed, e.g., when a device is plugged in ("Windows has found new hardware") • drivers insulate OS and application programs from specific properties of devices Virtual machines • running other OS's on top of an OS – e.g., VMWare, VirtualBox, Parallels, Xen, HyperV, ... • system calls from applications to "guest" OS are intercepted by "host" OS – e.g., guest == Windows 7 or Linux, host == MacOSX • passed to guest OS, which handles them by converting into system calls to host OS • not the same as "dual boot" Win app Win app Windows 7 Mac app(s) Virtualbox (Mac app) Mac OSX A quantitative moment "The number of American children killed by guns has doubled every year since 1950." Nancy Day, Violence in Schools: Learning in Fear (1996) Much too high, much too low, or plausible? Website of the day • http://projectalexandria.net/ File systems and databases: managing information • file: sequence of bytes stored on a computer – content is arbitrary; any structure is imposed by the creator of the file, not by the operating system • file system: software that provides hierarchical storage and organization of files, usually on a single computer – part of the operating system • database: integrated collection of logically related records – data is organized and structured for efficient systematic access – may be distributed across lots of machines & geographically dispersed • database system: software that provides efficient access to information in a database – not usually part of the operating system File systems: managing stored information • logical structure: users and programs see a hierarchy of folders (or directories) and files – a folder contains references to folder and files – "root" folder ultimately leads to all others – a file is just a sequence of bytes contents determined and interpreted by programs, not the operating system – a folder is a special file that contains names of other folders & files plus other information like size, time of change, etc. contents are completely controlled by the operating system • physical structure: disk drives operate in tracks, sectors, etc. – other storage devices have other physical properties • the operating system converts between these two views – does whatever is necessary to maintain the file/folder illusion – hides physical details so that programs don't depend on them – presents a uniform interface to disparate physical media • the "file system" is the part of the operating system that does this conversion [ Physical devices for file systems ] • • • • • hard disk (inside or external, e.g., via USB) CD-ROM, DVD flash drives (USB, SD card, ...) network drive RAM [ Disks ] • • • a place to store information when the power is turned off usually based on rotating magnetic surfaces or solid-state devices logical / functional structure: folders (directories) and files – – – – your information: papers, mail, music, web page, … programs and their data: Firefox, Word, iTunes, … operating system(s): Windows, MacOS, Unix/Linux, ... bookkeeping info: where things are physically How the file system converts logical to physical • disk is physically organized into sectors, or blocks of bytes – each sector is a fixed number of bytes, like 512 or 1024 or …) – reading and writing always happens in sector-sized blocks • each file occupies an integral number of blocks – files never share a block – some space is wasted: a 1-byte file wastes all but 1 byte of the block • if a file is bigger than one block, it occupies several blocks – the blocks are not necessarily adjacent on the disk • need a way to keep track of the blocks that make up the file • this is usually done by a separate "file allocation table" that lists the blocks that make up each file – this table is stored on disk too so it persists when machine is turned off – lots of ways to implement this Converting logical to physical, continued • every block is part of some file, or reserved by operating system, or unused • "file allocation table" keeps track of blocks – by chaining/linking them together first block of a file points to second, second points to third, etc. last block doesn't point to a successor (because it doesn't have one) – or (much more common) by some kind of table or array that keeps track of related blocks • also keeps track of unused blocks – disk starts out with most blocks unused ("free") some are reserved for file allocation table, etc. – as a file grows, blocks are removed from the unused list and attached to the list for the file: to grow a file, remove a block from the list of unused blocks and add it to the blocks for the file Converting logical to physical: directories • a directory / folder is a file – stored in the same file system – uses the same mechanisms • but it contains information about other files and directories • the directory entry for a file tells where to find the blocks • the directory entry also contains other info about the file – name (e.g., midterm.doc) – size in bytes, date/time of changes, access permissions – whether it's an ordinary file or a directory • the file system maintains the info in a directory – very important to keep directory info consistent – application programs can change it only indirectly / implicitly