W4118 Operating Systems OS OverviewJunfeng YangOutlineOS definitionsOS abstractions/conceptsOS structureOS evolutionWhat is OS?A program that acts as an intermediary between a user of a computer and the computer hardware.OSHWAppUserstuff betweenTwo popular definitions Top-down perspective: hardware abstraction layer, turn hardware into something that applications can useBottom-up perspective: resource manager/coordinator, manage your computers resourcesOS = hardware abstraction layerstandard library OS as virtual machineE.g. printf(hello world), shows up on screenApp can make system calls to use OS servicesWhy good?Ease of use: higher level of abstraction, easier to programReusability: provide common functionality for reuseE.g. each app doesnt have to write a graphics driverPortability / Uniformity: stable, consistent interface, different OS/version/hardware look same E.g. scsi/ide/flash disksWhy abstraction hard?What are the right abstractions ???Too low level ? Lose advantages of abstractionToo high level? All apps pay overhead, even those dont need Worse, may work against some apps E.g. DatabaseNext: example OS abstractionsTwo popular definitions Top-down perspective: hardware abstraction layer, turn hardware into something that applications can useBottom-up perspective: resource manager/coordinator, manage your computers resourcesOS = resource manager/coordinatorComputer has resources, OS must manage. Resource = CPU, Memory, disk, device, bandwidth, Memory managementFile system managementCPU schedulingNetwork stackOSMemoryCPU NICDiskSystem Call InterfaceHardwareShell gcc browserpptDevice driversDisk system managementOS = resource manager/coordinator (cont.)Why good?Sharing/Multiplexing: more than 1 app/user to use resourceProtection: protect apps from each other, OS from app Who gets what whenPerformance: efficient/fair access to resourcesWhy hard? Mechanisms v.s. policiesMechanism: how to do thingsPolicy: what will be doneIdeal case: general mechanisms, flexible policies Difficult to design rightOutlineOS definitionsOS abstractions/conceptsOS structureOS evolutionOS abstraction: processRunning program, stream of running instructions + process stateA key OS abstraction: the applications you use are built of processes Shell, powerpoint, gcc, browser, Easy to useProcesses are protected from each otherprocess = address spaceHide details of CPU, when&where to runProcess creation system callsint fork (void)Create a copy of the invoking processReturn process ID of new process in parentReturn 0 in childint execv (const char* prog, const char* argv[] )Replace current process with a new oneprog: program to runargv: arguments to pass to main()int wait (int * stat us)wait for a child to exitSimple Shell Example// parse user-typed com m and line into com m and and args// execute t he com m andswitch(pid = fork ()) { case -1: perror ( fork ); break; case 0: // child execv (com m and, args, 0); break; default : // parent wait (0); break; // wait for child to term inat e }Process communication system callsint pipe(int fds[2])Creates a one way communication channelfds[2] is used to return two file descriptorsBytes written to fds[1] will be read from fds[0]Often used together with fork() to create a channel between parent and childOS abstraction: threadminiprocesses, stream of instructions + thread stateConvenient abstraction to express concurrency in program execution and exploit parallel hardwareMore efficient communication than processesfor(;;) { int fd = accept_client (); create_thread(process_request , fd);}OS abstraction: fileArray of bytes, often persistent across rebootNice, clean way to read and write dataHide the details of disk devices (hard disk, CDROM, flash ) Related abstraction: directoryCollection of file entriesFile system callsint open(const char * path, int flags, int m ode)Opens a file and returns an integer called a file descriptor to use in other file system callsDefault file descriptors 0 = stdin, 1 = stdout, 2 = stderrint write(int fd, const char* buf, size_t sz)Writes sz bytes of data in buf to fd at current file offsetAdvance file offset by szint close(int fd)int dup2 (int oldfd, int newfd)makes newfd an exact copy of oldfdcloses newfd if it was validtwo file descriptors will share same offsetOutlineOS definitions and functionalitiesOS abstractions/conceptsOS structureOS evolutionOS structureCan define OS by structure: what goes into the kernel?Kernel: most interesting part of OS Can do everythingManages other parts of OSDifferent structures lead to differentPerformance, functionality, ease of use, security, reliability, portability, extensibility, cost, Tradeoffs depend on technology and workloadExample OS structure: monolithicMost traditional stuff in kernelUnix System ArchitectureExample OS structure: microkernelTry to move stuff out of kernelMinix 3 System ArchitectureExample OS structure: virtual machinesExports a fake hardware interface so that multiple OSes can run on top Non-virtual MachineVirtual MachineOutlineOS definitions and functionalitiesOS abstractions/conceptsOS structureOS evolutionOS evolutionMany outside factors affect OSUser needs + technology changes OS must evolveNew/better abstractions to usersNew/better algorithms to implement abstractionsNew/better low-level implementations (hw change)Current OS: evolution of these thingsMajor trend in HistoryHardware: cheaper and cheaperComputers/user: increasesTimeline70s: mainframe, 1 / organization80s: minicomputer, 1 / group90s: PC, 1 / user70s: mainframeHardware:Huge, $$$, slowIO: punch card, line printerOSsimple library of device drivers (no resource coordination)Human OS: single programmer/operator programs, runs, debugsOne job at a timeProblem: poor performance (utilization / throughput)Machine $$$, but idle most of the time because programmer slowBatch ProcessingBatch: submit group of jobs together to machineOperator collects, orders, runs (resource coordinator)Why good? can
View Full Document