MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 1 IntroductionTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
OutlineWhat is an operating systemThe history of Operating SystemHardware of operating systemImportant concepts of Operating System
What Is An Operating SystemA modern computer consists of:
One or more processorsMain memoryDisksPrintersVarious input/output devices
Managing all these components requires a layer of software the operating systemTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What is an Operating System?A modern computer is very complex. NetworkingDisksVideo/audio card.It is impossible for every application programmer to understand every detailA layer of computer software is introduced to provide a better, simpler, cleaner model of the resources and manage them
What Is An Operating SystemFigure 1-1. Where the operating system fits in.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
What is an Operating System?Users use various OSWindows, Linux, Mac OS etc.User interacts with shell or GUIpart of OS? they use OS to get their work doneIs device driver part of OS?
What is an Operating System?On top of hardware is OSMost computers have two modes of operation:Kernel mode and user modeOS runs in kernel mode, which has complete access to all hardware and can execute any instructionRest of software runs in user mode, which has limited capabilityShell or GUI is the lowest level of user mode software
What is an operating system?Two functions:From top to down: provide application programmers a clean abstract set of resources instead of hardware ones From down to top: Manage these hardware resources
The Operating System as an Extended MachineFigure 1-2. Operating systems turn ugly hardware into beautiful abstractions.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
As an extended machineAbstraction:CPUprocessStorage - filesMemory address space
4 types of people:Industrial engineer: design hardwareKernel designerApplication programmer: OSs userEnd users
The Operating System as a Resource ManagerAllow multiple programs to run at the same timeManage and protect memory, I/O devices, and other resourcesIncludes multiplexing (sharing) resources in two different ways: In timeIn spaceTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
As a resource managerModern OS runs multiple programs of multiple users at the same timeImagine what would happen if several programs want to print at the same time?How to account the resource usage of each process?Resources can be multiplexed:How to ensure fairness and efficiency?
summaryOperating system is a softwareIs a complex softwareRuns in kernel modeManages hardwareProvide a friendly interface for application programmer
History of Operating SystemsGenerations:
(194555) Vacuum Tubes(195565) Transistors and Batch Systems(19651980) ICs and Multiprogramming(1980Present) Personal ComputersTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
1st: vacuum tubesLarge and slowEngineers design, build, operate and maintain the computerAll programming is done with machine language, or by wiring circuits using cablesinsert plugboards into the computer and operateThe work is mainly numerical calculations
2nd: transistors and batch systemsAlso called mainframesComputers are managed by professional operatorsProgrammers use punch card to run programs; operators operate (load compiler, etc ) and collect output to the userComplains soon come:Human Operation between computer operationLead to batch systemCollect a batch of jobs in the input room, then read them into a magnetic tape; the same for output
2nd: Transistors and Batch Systems (1)Figure 1-3. An early batch system. (a) Programmers bring cards to 1401. (b)1401 reads batch of jobs onto tape.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (2)Figure 1-3. (c) Operator carries input tape to 7094. (d) 7094 does computing. (e) Operator carries output tape to 1401. (f) 1401 prints output. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Transistors and Batch Systems (4)Figure 1-4. Structure of a typical FMS job.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
3rd: IC and MultiprogrammingOS/360: a dinosaur stuck in a tar pitAims to adapts 1401/7904, covers all trades of lifeHowever, OS/360 introduces several key techniquesMulti-programming: solve the problem of CPU idlingSpooling: simultaneous peripheral operation on lineWhenever a job finishes, OS load a new job from disk to the empty-partition
Figure 1-5. A multiprogramming system with three jobs in memory.3rd: ICs and MultiprogrammingTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
3rd: Ics and MultiprogrammingProblems:3rd generation OS was well suited for big scientific calculations and massive data processingBut many programmers complain a lot for not be able to debug quickly. Why?And the solution to this problem would be.?Timesharing:A variant of multiprogrammingProvide both fast interactive service but also fits big batch work
3rd: IC and MultiprogrammingA system to be remembered: MULTICSA machine that would support hundreds of simultaneous timesharing users like the electricity system (like a web server nowadays)Introduces many brilliant ideas but enjoys no commercial successIts step-child is the well-known and time-honored UNIXSystem V/ FreeBSD, MINIX, Linux
4th: personal computersComputers have performance similar to 3rd generation, but prices drastically differentCP/MFirst disk-based OS1980, IBM PC, Basic Interpreter, DOS, MS-DOSGUI--LisaApple: user friendlyMS-DOS with GUI Win95/98/mewinNT/xp
Summary4 generations OSDevelops with hardware and user needsMulti-user, multi-programming, time-sharing
Computer Hardware ReviewFigure 1-6. Some of the components of a simple personal computer.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Hardware: processorBrain of computerFetches instruction from memory and executeCycle of CPU: fetch, decode, executeCPU has registers to store variable and temporary result: load from memory to register; store from register to memoryProgram counter: next instruction to fetchStack pointer: the top of the current stackPSW: program status word, priority, mode
A referenceAdam Smith: Wealth of Nation
Of the Division of labor
One man draws out the wire, another straights it, a third cuts it, a fourth points it, a fifth grinds it at the topOne person could make up to forth-eight thousand pins in a day
CPU PipeliningFigure 1-7. (a) A three-stage pipeline. (b) A superscalar CPU.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
CPU PipelineAccelerate the executionCause headaches to OS/compiler writers
For superscalar: instructions are often executed out of order
Figure 1-8. (a) A quad-core chip with a shared L2 cache. (b) A quad-core chip with separate L2 caches.Multithreaded and Multicore ChipsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-9. A typical memory hierarchy. The numbers are very rough approximations.Memory (1)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
memoryMemory is where computer fetch and store data, ideally, it should be both chip/largeThe best people can do, is to construct a memory hierarchyCache lines:Memory divided into cache lines; the mostly used ones are stored in cachesCache hit, cache missCache: whenever there is disparity in usage or speed; used to improve performance
Questions when dealing with cache:
When to put a new item into the cache.Which cache line to put the new item in.Which item to remove from the cache when a slot is needed.Where to put a newly evicted item in the larger memory.Memory (2)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-10. Structure of a disk drive.DisksTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
DisksCheap and large: two orders better than RAMSlow: three orders worse than RAMMechanical movement to fetch dataOne or more platterrotate rpmInformation is stored on concentric circlesArm, track, cylinder, sectorDisk helps to implement Virtual MemoryWhen no enough memory is available, disks are used as the storage, and memory as cache
Figure 1-11. (a) The steps in starting an I/O device and getting an interrupt. I/O DevicesTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
I/O devicesTwo parts: a controller and a deviceController: to provide a simpler interface to OSDevice driver: talks to controller, give commands and accepts responseBusy waiting/interrupt/DMA
Booting the ComputerBIOSbasic input/output systemOn the parentboard, low-level I/O softwareChecks RAM, keyboard and other basic devicesDetermine the boot device: floppy, CD-ROM, diskFirst sector of the boot-device is read into memoryThe sector contains program to check which partition is activeThen a secondary boot-loader is read into memory and reads in operating system from the active partition
The Operating System ZooMainframe operating systemsServer operating systemsMultiprocessor operating systemsPersonal computer operating systemsHandheld operating systemsEmbedded operating systemsSensor node operating systemsReal-time operating systemsSmart card operating systemsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
ProcessesAddress spacesFilesInput/OutputProtectionThe shellOntogeny recapitulates phylogenyLarge memoriesProtection hardwareDisksVirtual memoryOperating System ConceptsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
processesProcessAddress space: 0-4G; executable program, programs data, and its stackOther resources like: registers, files, alarms, related processes, and other informationA process is fundamentally a container that holds information for a program to run
Processes
Figure 1-13. A process tree. Process A created two child processes, B and C. Process B created three child processes, D, E, and F.Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Address SpaceThe memory used by a process, in conceptMOS allows multiple processes in memory simultaneouslySome processes need more memory than physically available virtual memory
Figure 1-14. A file system for a university department.Files (1)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-15. (a) Before mounting, the files on the CD-ROM are not accessible. (b) After mounting, they are part of the file hierarchy.Files (2)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-16. Two processes connected by a pipe.Files (3)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
System calls System calls is the interface users contact with OS and hardwareSystem calls vary from system to system, but the underlying concepts are similar
Figure 1-17. The 11 steps in making the system call read(fd, buffer, nbytes).System CallsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-18. Some of the major POSIX system calls. System Calls for Process ManagementTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-18. Some of the major POSIX system calls. System Calls for File Management (1)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-18. Some of the major POSIX system calls. System Calls for File Management (2)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-18. Some of the major POSIX system calls. Miscellaneous System CallsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-19. A stripped-down shell. A Simple ShellTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-20. Processes have three segments: text, data, and stack.Memory LayoutTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-21. (a) Two directories before linking /usr/jim/memo to asts directory. (b) The same directories after linking.LinkingTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-22. (a) File system before the mount. (b) File system after the mount.MountingTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-23. The Win32 API calls that roughly correspond to the UNIX calls of Fig. 1-18.Windows Win32 APITanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Monolithic systems basic structure:
A main program that invokes the requested service procedure.A set of service procedures that carry out the system calls.A set of utility procedures that help the service procedures.Operating Systems StructureTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-25. Structure of the THE operating system.Layered SystemsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-26. Structure of the MINIX 3 system.MicrokernelsTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-27. The client-server model over a network.Client-Server ModelTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Figure 1-29. (a) A type 1 hypervisor. (b) A type 2 hypervisor.Virtual Machines (2)Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
The C languageHeader filesLarge programming projectsThe model of run time
The World According to CTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
World according to COperating systems are large C programs consisting of many pieces written by many programmersC languageData types, variables, control statementsHeader files: declaration, definition, macrosFor a large programming project
Figure 1-30. The process of compiling C and header files to make an executable.The Model of Run TimeTanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639
Large programming projectsC preprocessor:Gets the header, expand macros, handling conditional compilationCompiler.c -.o LinkerCombine all .o to an executable program; traditionally a.out
Gcc: preprocess-assemble-compile-linkgcc -E hello.c o hello.igcc -S hello.i -o hello.sgcc -c hello.s o hello.ogcc hello.o o hello
ldd hello
*A modern computer is a complex system. Its impossible for every application programmer to understand how all these thing work in detail. Furthermore, managing all these components and using them optimally is an exceedingly challenging job. therefore, OS is introduced to provide user programs with a better, simpler, cleaner model of the computer and handle all the resources.User uses various kinds of OS.*