Chapter 2: Operating-System Structures - Carnegie Mellon University

1y ago
8 Views
2 Downloads
2.62 MB
59 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Brady Himes
Transcription

Chapter 2: Operating-SystemStructuresOperating System Concepts – 10th EditionSilberschatz, Galvin and Gagne 2018

Chapter 2: Operating-System StructuresOperating System ServicesUser and Operating System-InterfaceSystem CallsSystem ServicesLinkers and LoadersWhy Applications are Operating System SpecificOperating-System Design and ImplementationOperating System StructureBuilding and Booting an Operating SystemOperating System DebuggingOperating System Concepts – 10th Edition2.2Silberschatz, Galvin and Gagne 2018

ObjectivesIdentify services provided by an operating systemIllustrate how system calls are used to provide operatingsystem servicesCompare and contrast monolithic, layered, microkernel,modular, and hybrid strategies for designing operatingsystemsIllustrate the process for booting an operating systemApply tools for monitoring operating system performanceDesign and implement kernel modules for interacting with aLinux kernelOperating System Concepts – 10th Edition2.3Silberschatz, Galvin and Gagne 2018

Operating System ServicesOperating systems provide an environment for execution of programsand services to programs and usersOne set of operating-system services provides functions that arehelpful to the user:User interface - Almost all operating systems have a userinterface (UI). Varies between Command-Line (CLI), Graphics UserInterface (GUI), touch-screen, BatchProgram execution - The system must be able to load aprogram into memory and to run that program, end execution,either normally or abnormally (indicating error)I/O operations - A running program may require I/O, which mayinvolve a file or an I/O deviceOperating System Concepts – 10th Edition2.4Silberschatz, Galvin and Gagne 2018

Operating System Services (Cont.)One set of operating-system services provides functions that are helpful tothe user (Cont.):File-system manipulation - The file system is of particular interest.Programs need to read and write files and directories, create and deletethem, search them, list file Information, permission management.Communications – Processes may exchange information, on the samecomputer or between computers over a network Communications may be via shared memory or through messagepassing (packets moved by the OS)Error detection – OS needs to be constantly aware of possible errors May occur in the CPU and memory hardware, in I/O devices, in userprogram For each type of error, OS should take the appropriate action toensure correct and consistent computing Debugging facilities can greatly enhance the user’s andprogrammer’s abilities to efficiently use the systemOperating System Concepts – 10th Edition2.5Silberschatz, Galvin and Gagne 2018

Operating System Services (Cont.)Another set of OS functions exists for ensuring the efficient operation of thesystem itself via resource sharingResource allocation - When multiple users or multiple jobs runningconcurrently, resources must be allocated to each of them Many types of resources - CPU cycles, main memory, file storage,I/O devices.Logging - To keep track of which users use how much and what kindsof computer resourcesProtection and security - The owners of information stored in amultiuser or networked computer system may want to control use ofthat information, concurrent processes should not interfere with eachother Protection involves ensuring that all access to system resources iscontrolled Security of the system from outsiders requires user authentication,extends to defending external I/O devices from invalid accessattemptsOperating System Concepts – 10th Edition2.6Silberschatz, Galvin and Gagne 2018

A View of Operating System ServicesOperating System Concepts – 10th Edition2.7Silberschatz, Galvin and Gagne 2018

User Operating System Interface - CLICLI or command interpreter allows direct command entrySometimes implemented in kernel, sometimes by systemsprogramSometimes multiple flavors implemented – shellsPrimarily fetches a command from user and executes itSometimes commands built-in, sometimes just names ofprograms If the latter, adding new features doesn’t require shellmodificationOperating System Concepts – 10th Edition2.8Silberschatz, Galvin and Gagne 2018

Bourne Shell Command InterpreterOperating System Concepts – 10th Edition2.9Silberschatz, Galvin and Gagne 2018

User Operating System Interface - GUIUser-friendly desktop metaphor interfaceUsually mouse, keyboard, and monitorIcons represent files, programs, actions, etcVarious mouse buttons over objects in the interface causevarious actions (provide information, options, execute function,open directory (known as a folder)Invented at Xerox PARCMany systems now include both CLI and GUI interfacesMicrosoft Windows is GUI with CLI “command” shellApple Mac OS X is “Aqua” GUI interface with UNIX kernelunderneath and shells availableUnix and Linux have CLI with optional GUI interfaces (CDE,KDE, GNOME)Operating System Concepts – 10th Edition2.10Silberschatz, Galvin and Gagne 2018

Touchscreen InterfacesnlTouchscreen devices require newinterfaceslMouse not possible or not desiredlActions and selection based ongestureslVirtual keyboard for text entryVoice commandsOperating System Concepts – 10th Edition2.11Silberschatz, Galvin and Gagne 2018

The Mac OS X GUIOperating System Concepts – 10th Edition2.12Silberschatz, Galvin and Gagne 2018

System CallsProgramming interface to the services provided by the OSTypically written in a high-level language (C or C )Mostly accessed by programs via a high-levelApplication Programming Interface (API) rather thandirect system call useThree most common APIs are Win32 API for Windows,POSIX API for POSIX-based systems (including virtuallyall versions of UNIX, Linux, and Mac OS X), and Java APIfor the Java virtual machine (JVM)Note that the system-call names used throughout this text aregenericOperating System Concepts – 10th Edition2.13Silberschatz, Galvin and Gagne 2018

Example of System CallsSystem call sequence to copy the contents of one file to another fileOperating System Concepts – 10th Edition2.14Silberschatz, Galvin and Gagne 2018

Example of Standard APIOperating System Concepts – 10th Edition2.15Silberschatz, Galvin and Gagne 2018

System Call ImplementationTypically, a number associated with each system callSystem-call interface maintains a table indexed according tothese numbersThe system call interface invokes the intended system call in OSkernel and returns status of the system call and any return valuesThe caller need know nothing about how the system call isimplementedJust needs to obey API and understand what OS will do as aresult callMost details of OS interface hidden from programmer by API Managed by run-time support library (set of functions builtinto libraries included with compiler)Operating System Concepts – 10th Edition2.16Silberschatz, Galvin and Gagne 2018

API – System Call – OS RelationshipOperating System Concepts – 10th Edition2.17Silberschatz, Galvin and Gagne 2018

System Call Parameter PassingOften, more information is required than simply identity of desiredsystem callExact type and amount of information vary according to OSand callThree general methods used to pass parameters to the OSSimplest: pass the parameters in registersIn some cases, may be more parameters than registersParameters stored in a block, or table, in memory, andaddress of block passed as a parameter in a register This approach taken by Linux and SolarisParameters placed, or pushed, onto the stack by the programand popped off the stack by the operating system Block and stack methods do not limit the number or length ofparameters being passedOperating System Concepts – 10th Edition2.18Silberschatz, Galvin and Gagne 2018

Parameter Passing via TableOperating System Concepts – 10th Edition2.19Silberschatz, Galvin and Gagne 2018

Types of System CallsProcess controlcreate process, terminate processend, abortload, executeget process attributes, set process attributeswait for timewait event, signal eventallocate and free memoryDump memory if errorDebugger for determining bugs, single step executionLocks for managing access to shared data between processesOperating System Concepts – 10th Edition2.20Silberschatz, Galvin and Gagne 2018

Types of System Calls (cont.)File managementcreate file, delete fileopen, close fileread, write, repositionget and set file attributesDevice managementrequest device, release deviceread, write, repositionget device attributes, set device attributeslogically attach or detach devicesOperating System Concepts – 10th Edition2.21Silberschatz, Galvin and Gagne 2018

Types of System Calls (Cont.)Information maintenanceget time or date, set time or dateget system data, set system dataget and set process, file, or device attributesCommunicationscreate, delete communication connectionsend, receive messages if message passing model to hostname or process name From client to serverShared-memory model create and gain access to memoryregionstransfer status informationattach and detach remote devicesOperating System Concepts – 10th Edition2.22Silberschatz, Galvin and Gagne 2018

Types of System Calls (Cont.)ProtectionControl access to resourcesGet and set permissionsAllow and deny user accessOperating System Concepts – 10th Edition2.23Silberschatz, Galvin and Gagne 2018

Examples of Windows and Unix System CallsOperating System Concepts – 10th Edition2.24Silberschatz, Galvin and Gagne 2018

Standard C Library ExampleC program invoking printf() library call, which calls write() system callOperating System Concepts – 10th Edition2.25Silberschatz, Galvin and Gagne 2018

Example: ArduinoSingle-taskingNo operating systemPrograms (sketch) loaded viaUSB into flash memorySingle memory spaceBoot loader loads programProgram exit - shellreloadedAt system startupOperating System Concepts – 10th Edition2.26running a programSilberschatz, Galvin and Gagne 2018

Example: FreeBSDUnix variantMultitaskingUser login - invoke user’s choice ofshellShell executes fork() system call to createprocessExecutes exec() to load program intoprocessShell waits for process to terminate orcontinues with user commandsProcess exits with:code 0 – no errorcode 0 – error codeOperating System Concepts – 10th Edition2.27Silberschatz, Galvin and Gagne 2018

System ServicesSystem programs provide a convenient environment for programdevelopment and execution. They can be divided into:File manipulationStatus information sometimes stored in a fileProgramming language supportProgram loading and executionCommunicationsBackground servicesApplication programsMost users’ view of the operation system is defined by systemprograms, not the actual system callsOperating System Concepts – 10th Edition2.28Silberschatz, Galvin and Gagne 2018

System Services (cont.)Provide a convenient environment for program development andexecutionSome of them are simply user interfaces to system calls; othersare considerably more complexFile management - Create, delete, copy, rename, print, dump, list,and generally manipulate files and directoriesStatus informationSome ask the system for info - date, time, amount of availablememory, disk space, number of usersOthers provide detailed performance, logging, and debugginginformationTypically, these programs format and print the output to theterminal or other output devicesSome systems implement a registry - used to store andretrieve configuration informationOperating System Concepts – 10th Edition2.29Silberschatz, Galvin and Gagne 2018

System Services (Cont.)File modificationText editors to create and modify filesSpecial commands to search contents of files or performtransformations of the textProgramming-language support - Compilers, assemblers,debuggers and interpreters sometimes providedProgram loading and execution- Absolute loaders, relocatableloaders, linkage editors, and overlay-loaders, debugging systemsfor higher-level and machine languageCommunications - Provide the mechanism for creating virtualconnections among processes, users, and computer systemsAllow users to send messages to one another’s screens,browse web pages, send electronic-mail messages, log inremotely, transfer files from one machine to anotherOperating System Concepts – 10th Edition2.30Silberschatz, Galvin and Gagne 2018

System Services (Cont.)Background ServicesLaunch at boot timeSome for system startup, then terminate Some from system boot to shutdown Provide facilities like disk checking, process scheduling, errorlogging, printingRun in user context not kernel contextKnown as services, subsystems, daemonsApplication programsDon’t pertain to systemRun by usersNot typically considered part of OSLaunched by command line, mouse click, finger pokeOperating System Concepts – 10th Edition2.31Silberschatz, Galvin and Gagne 2018

Linkers and LoadersSource code compiled into object files designed to be loaded into anyphysical memory location – relocatable object fileLinker combines these into single binary executable fileAlso brings in librariesProgram resides on secondary storage as binary executableMust be brought into memory by loader to be executedRelocation assigns final addresses to program parts and adjusts codeand data in program to match those addressesModern general purpose systems don’t link libraries into executablesRather, dynamically linked libraries (in Windows, DLLs) are loadedas needed, shared by all that use the same version of that same library(loaded once)Object, executable files have standard formats, so operating system knowshow to load and start themOperating System Concepts – 10th Edition2.32Silberschatz, Galvin and Gagne 2018

The Role of the Linker and LoaderOperating System Concepts – 10th Edition2.33Silberschatz, Galvin and Gagne 2018

Why Applications are Operating System SpecificApps compiled on one system usually not executable on otheroperating systemsEach operating system provides its own unique system callsOwn file formats, etcApps can be multi-operating systemWritten in interpreted language like Python, Ruby, andinterpreter available on multiple operating systemsApp written in language that includes a VM containing therunning app (like Java)Use standard language (like C), compile separately on eachoperating system to run on eachApplication Binary Interface (ABI) is architecture equivalent ofAPI, defines how different components of binary code can interfacefor a given operating system on a given architecture, CPU, etcOperating System Concepts – 10th Edition2.34Silberschatz, Galvin and Gagne 2018

Operating System Design and ImplementationDesign and Implementation of OS not “solvable”, but someapproaches have proven successfulInternal structure of different Operating Systems can vary widelyStart the design by defining goals and specificationsAffected by choice of hardware, type of systemUser goals and System goalsUser goals – operating system should be convenient to use,easy to learn, reliable, safe, and fastSystem goals – operating system should be easy to design,implement, and maintain, as well as flexible, reliable, error-free,and efficientOperating System Concepts – 10th Edition2.35Silberschatz, Galvin and Gagne 2018

Operating System Design and Implementation (Cont.)Important principle to separatePolicy: What will be done?Mechanism: How to do it?Mechanisms determine how to do something, policies decidewhat will be doneThe separation of policy from mechanism is a very importantprinciple, it allows maximum flexibility if policy decisions are tobe changed later (example – timer)Specifying and designing an OS is highly creative task ofsoftware engineeringOperating System Concepts – 10th Edition2.36Silberschatz, Galvin and Gagne 2018

ImplementationMuch variationEarly OSes in assembly languageThen system programming languages like Algol, PL/1Now C, C Actually usually a mix of languagesLowest levels in assemblyMain body in CSystems programs in C, C , scripting languages like PERL,Python, shell scriptsMore high-level language easier to port to other hardwareBut slowerEmulation can allow an OS to run on non-native hardwareOperating System Concepts – 10th Edition2.37Silberschatz, Galvin and Gagne 2018

Operating System StructureGeneral-purpose OS is very large programVarious ways to structure onesSimple structure – MS-DOSMore complex -- UNIXLayered – an abstractionMicrokernel -MachOperating System Concepts – 10th Edition2.38Silberschatz, Galvin and Gagne 2018

Monolithic Structure – Original UNIXUNIX – limited by hardware functionality, the original UNIXoperating system had limited structuring. The UNIX OSconsists of two separable partsSystems programsThe kernel Consists of everything below the system-call interfaceand above the physical hardware Provides the file system, CPU scheduling, memorymanagement, and other operating-system functions; alarge number of functions for one levelOperating System Concepts – 10th Edition2.39Silberschatz, Galvin and Gagne 2018

Traditional UNIX System StructureBeyond simple but not fully layeredOperating System Concepts – 10th Edition2.40Silberschatz, Galvin and Gagne 2018

Linux System StructureMonolithic plus modular designOperating System Concepts – 10th Edition2.41Silberschatz, Galvin and Gagne 2018

Layered ApproachThe operating system is dividedinto a number of layers (levels),each built on top of lowerlayers. The bottom layer (layer0), is the hardware; the highest(layer N) is the user interface.With modularity, layers areselected such that each usesfunctions (operations) andservices of only lower-levellayersOperating System Concepts – 10th Edition2.42Silberschatz, Galvin and Gagne 2018

MicrokernelsMoves as much from the kernel into user spaceMach example of microkernelMac OS X kernel (Darwin) partly based on MachCommunication takes place between user modules usingmessage passingBenefits:Easier to extend a microkernelEasier to port the operating system to new architecturesMore reliable (less code is running in kernel mode)More secureDetriments:Performance overhead of user space to kernel spacecommunicationOperating System Concepts – 10th Edition2.43Silberschatz, Galvin and Gagne 2018

Microkernel System StructureOperating System Concepts – 10th Edition2.44Silberschatz, Galvin and Gagne 2018

ModulesMany modern operating systems implement loadable kernelmodules (LKMs)Uses object-oriented approachEach core component is separateEach talks to the others over known interfacesEach is loadable as needed within the kernelOverall, similar to layers but with more flexibleLinux, Solaris, etcOperating System Concepts – 10th Edition2.45Silberschatz, Galvin and Gagne 2018

Hybrid SystemsMost modern operating systems are actually not one pure modelHybrid combines multiple approaches to addressperformance, security, usability needsLinux and Solaris kernels in kernel address space, somonolithic, plus modular for dynamic loading of functionalityWindows mostly monolithic, plus microkernel for differentsubsystem personalitiesApple Mac OS X hybrid, layered, Aqua UI plus Cocoaprogramming environmentBelow is kernel consisting of Mach microkernel and BSD Unixparts, plus I/O kit and dynamically loadable modules (calledkernel extensions)Operating System Concepts – 10th Edition2.46Silberschatz, Galvin and Gagne 2018

macOS and iOS StructureOperating System Concepts – 10th Edition2.47Silberschatz, Galvin and Gagne 2018

DarwinOperating System Concepts – 10th Edition2.48Silberschatz, Galvin and Gagne 2018

AndroidDeveloped by Open Handset Alliance (mostly Google)Open SourceSimilar stack to IOSBased on Linux kernel but modifiedProvides process, memory, device-driver managementAdds power managementRuntime environment includes core set of libraries and Dalvikvirtual machineApps developed in Java plus Android API Java class files compiled to Java bytecode then translatedto executable than runs in Dalvik VMLibraries include frameworks for web browser (webkit), database(SQLite), multimedia, smaller libcOperating System Concepts – 10th Edition2.50Silberschatz, Galvin and Gagne 2018

Android ArchitectureOperating System Concepts – 10th Edition2.51Silberschatz, Galvin and Gagne 2018

Building and Booting an Operating SystemOperating systems generally designed to run on a class of systemswith variety of perpheralsCommonly, operating system already installed on purchasedcomputerBut can build and install some other operating systemsIf generating an operating system from scratch Write the operating system source code Configure the operating system for the system on which itwill run Compile the operating system Install the operating system Boot the computer and its new operating systemOperating System Concepts – 10th Edition2.52Silberschatz, Galvin and Gagne 2018

Building and Booting LinuxDownload Linux source code (http://www.kernel.org)Configure kernel via “make menuconfig”Compile the kernel using “make”Produces vmlinuz, the kernel imageCompile kernel modules via “make modules”Install kernel modules into vmlinuz via “make modules install”Install new kernel on the system via “make install”Operating System Concepts – 10th Edition2.53Silberschatz, Galvin and Gagne 2018

System BootWhen power initialized on system, execution starts at a fixed memorylocationOperating system must be made available to hardware so hardware canstart itSmall piece of code – bootstrap loader, BIOS, stored in ROM orEEPROM locates the kernel, loads it into memory, and starts itSometimes two-step process where boot block at fixed locationloaded by ROM code, which loads bootstrap loader from diskModern systems replace BIOS with Unified Extensible FirmwareInterface (UEFI)Common bootstrap loader, GRUB, allows selection of kernel frommultiple disks, versions, kernel optionsKernel loads and system is then runningBoot loaders frequently allow various boot states, such as single usermodeOperating System Concepts – 10th Edition2.54Silberschatz, Galvin and Gagne 2018

Operating-System DebuggingDebugging is finding and fixing errors, or bugsAlso performance tuningOS generate log files containing error informationFailure of an application can generate core dump file capturingmemory of the processOperating system failure can generate crash dump file containingkernel memoryBeyond crashes, performance tuning can optimize system performanceSometimes using trace listings of activities, recorded for analysisProfiling is periodic sampling of instruction pointer to look forstatistical trendsKernighan’s Law: “Debugging is twice as hard as writing the code in thefirst place. Therefore, if you write the code as cleverly as possible, youare, by definition, not smart enough to debug it.”Operating System Concepts – 10th Edition2.55Silberschatz, Galvin and Gagne 2018

Performance TuningImprove performance by removing bottlenecksOS must provide means of computing and displaying measures of systembehaviorFor example, “top” program or Windows Task ManagerOperating System Concepts – 10th Edition2.56Silberschatz, Galvin and Gagne 2018

TracingCollects data for a specific event, such as steps involved in a systemcall invocationTools includestrace – trace system calls invoked by a processgdb – source-level debuggerperf – collection of Linux performance toolstcpdump – collects network packetsOperating System Concepts – 10th Edition2.57Silberschatz, Galvin and Gagne 2018

BCCDebugging interactions between user-level and kernel code nearlyimpossible without toolset that understands both and an instrumenttheir actionsBCC (BPF Compiler Collection) is a rich toolkit providing tracingfeatures for LinuxSee also the original DTraceFor example, disksnoop.py traces disk I/O activityMany other tools (next slide)Operating System Concepts – 10th Edition2.58Silberschatz, Galvin and Gagne 2018

Linux bcc/BPF Tracing ToolsOperating System Concepts – 10th Edition2.59Silberschatz, Galvin and Gagne 2018

End of Chapter 2Operating System Concepts – 10th EditionSilberschatz, Galvin and Gagne 2018

Operating System Concepts -10th Edition 2.8 Silberschatz, Galvin and Gagne 2018 User Operating System Interface - CLI CLI or command interpreter allows direct command entry Sometimes implemented in kernel, sometimes by systems program Sometimes multiple flavors implemented -shells Primarily fetches a command from user and executes it

Related Documents:

Part One: Heir of Ash Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26 Chapter 27 Chapter 28 Chapter 29 Chapter 30 .

TO KILL A MOCKINGBIRD. Contents Dedication Epigraph Part One Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Part Two Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18. Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 Chapter 24 Chapter 25 Chapter 26

DEDICATION PART ONE Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 PART TWO Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 Chapter 21 Chapter 22 Chapter 23 .

About the husband’s secret. Dedication Epigraph Pandora Monday Chapter One Chapter Two Chapter Three Chapter Four Chapter Five Tuesday Chapter Six Chapter Seven. Chapter Eight Chapter Nine Chapter Ten Chapter Eleven Chapter Twelve Chapter Thirteen Chapter Fourteen Chapter Fifteen Chapter Sixteen Chapter Seventeen Chapter Eighteen

18.4 35 18.5 35 I Solutions to Applying the Concepts Questions II Answers to End-of-chapter Conceptual Questions Chapter 1 37 Chapter 2 38 Chapter 3 39 Chapter 4 40 Chapter 5 43 Chapter 6 45 Chapter 7 46 Chapter 8 47 Chapter 9 50 Chapter 10 52 Chapter 11 55 Chapter 12 56 Chapter 13 57 Chapter 14 61 Chapter 15 62 Chapter 16 63 Chapter 17 65 .

HUNTER. Special thanks to Kate Cary. Contents Cover Title Page Prologue Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter

Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapter 18 Chapter 19 Chapter 20 . Within was a room as familiar to her as her home back in Oparium. A large desk was situated i

The Hunger Games Book 2 Suzanne Collins Table of Contents PART 1 – THE SPARK Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8. Chapter 9 PART 2 – THE QUELL Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Chapter 15 Chapter 16 Chapter 17 Chapt