Chapter 2 System Structures Operating System Concepts 9

















































- Slides: 49

Chapter 2: System Structures Operating System Concepts – 9 th Edition, Silberschatz, Galvin and Gagne © 2013

Chapter 2: System Structures n 2. 1 Operating System Services n 2. 2 User Operating System Interface n 2. 3 System Calls n 2. 4 Types of System Calls n 2. 5 System Programs n 2. 6 Operating-System Design and Implementation n 2. 7 Operating-System Structure n 2. 8 Operating-System Debugging n 2. 9 Operating-System Generation n 2. 10 System Boot Operating System Concepts – 9 th Edition 2. 2 Silberschatz, Galvin and Gagne © 2013

Objectives n To describe the services an operating system provides to users, processes, and other systems n To discuss the various ways of structuring an operating system n To explain how operating systems are installed and customized and how they boot Operating System Concepts – 9 th Edition 2. 3 Silberschatz, Galvin and Gagne © 2013

2. 1 Operating-System Services n One set of operating-system services provides functions that are helpful to the user: l User interface - Almost all operating systems have a user interface (UI) 4 Varies between Graphics User Interface (GUI), Command-Line Interface (CLI), Batch l Program execution - The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error) l I/O operations - A running program may require I/O, which may involve a file or an I/O device l File-system manipulation - The file system is of particular interest. Obviously, programs need to read and write files and directories, create and delete them, search them, list file Information, permission management. Operating System Concepts – 9 th Edition 2. 4 Silberschatz, Galvin and Gagne © 2013

Operating System Services (Cont. ) n One set of operating-system services provides functions that are helpful to the user (Cont. ): l Communications – Processes may exchange information, on the same computer or between computers over a network 4 Communications may be via shared memory or through message passing (packets moved by the OS) l Error detection – OS needs to be constantly aware of possible errors 4 May occur in the CPU and memory hardware, in I/O devices, in user program 4 For each type of error, OS should take the appropriate action to ensure correct and consistent computing 4 Debugging facilities can greatly enhance the user’s and programmer’s abilities to efficiently use the system Operating System Concepts – 9 th Edition 2. 5 Silberschatz, Galvin and Gagne © 2013

A View of Operating System Services Operating System Concepts – 9 th Edition 2. 6 Silberschatz, Galvin and Gagne © 2013

Operating System Services (Cont. ) n Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them 4 Many types of resources - Some (such as CPU cycles, main memory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code l Accounting - To keep track of which users use how much and what kinds of computer resources l Protection and security - The owners of information stored in a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other 4 Protection involves ensuring that all access to system resources is controlled 4 Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts l 4 If a system is to be protected and secure, precautions must be instituted throughout it. A chain is only as strong as its weakest link. Operating System Concepts – 9 th Edition 2. 7 Silberschatz, Galvin and Gagne © 2013

2. 2 User and Operating-System Interface n Command Line Interface (CLI) or command interpreter allows direct command entry l Primarily fetches a command from user and executes it 4 Sometimes – Executed in kernel (efficient) 4 Sometimes – l built-in kernel commands just names of system programs Adding new features doesn’t require shell modification (convenient) Sometimes multiple flavors implemented 4 Many shells in UNIX-like OSes Operating System Concepts – 9 th Edition 2. 8 Silberschatz, Galvin and Gagne © 2013

Bourne Shell Command Interpreter Operating System Concepts – 9 th Edition 2. 9 Silberschatz, Galvin and Gagne © 2013

User Operating System Interface - GUI n Graphical user interface (GUI) l l l User-friendly desktop metaphor interface Usually mouse, keyboard, and monitor Icons represent files, programs, actions, etc Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder)) Invented at Xerox PARC 4 http: //zh. wikipedia. org/wiki/%E 5%B 8%95%E 7%BE%85%E 5%A 7%E 5%A 4%9 A%E 7%A 0%94%E 7 %A 9%B 6%E 4%B 8%AD%E 5%BF%83 n Many systems now include both CLI and GUI interfaces Microsoft Windows has GUI with CLI “cmd” shell l Apple Mac OS X has “Aqua” GUI interface with UNIX kernel underneath and shells available l Solaris has shells with optional GUI interfaces (Java Desktop, KDE) l Operating System Concepts – 9 th Edition 2. 10 Silberschatz, Galvin and Gagne © 2013

The Mac OS X GUI Operating System Concepts – 9 th Edition 2. 11 Silberschatz, Galvin and Gagne © 2013

Touchscreen Interfaces n Touchscreen devices require new interfaces l Mouse not possible or not desired l Actions and selection based on gestures l Virtual keyboard for text entry Operating System Concepts – 9 th Edition 2. 12 Silberschatz, Galvin and Gagne © 2013

2. 3 System Calls Programming interface to the services provided by the OS n Typically written in a high-level language (C or C++) n Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use n Three most common APIs are l Windows API for Windows l POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X) l Java API for the Java virtual machine (JVM) Operating System Concepts – 9 th Edition 2. 13 Silberschatz, Galvin and Gagne © 2013

Example of System Calls n System call sequence to copy the contents of one file to another file Operating System Concepts – 9 th Edition 2. 14 Silberschatz, Galvin and Gagne © 2013

Example of Standard API Operating System Concepts – 9 th Edition 2. 15 Silberschatz, Galvin and Gagne © 2013

System Call Implementation n Typically, a number associated with each system call System-call interface maintains a table indexed according to these numbers n The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values l n The caller need know nothing about how the system call is implemented Just needs to obey API and understand what OS will do as a result call l Most details of OS interface hidden from programmer by API l 4 Managed by run-time support library (set of functions built into libraries included with compiler) – #include in C, C++ – import in Java Operating System Concepts – 9 th Edition 2. 16 Silberschatz, Galvin and Gagne © 2013

API – System Call – OS Relationship Operating System Concepts – 9 th Edition 2. 17 Silberschatz, Galvin and Gagne © 2013

System Call Parameter Passing n Often, more information is required than simply identity of desired system call l Exact type and amount of information vary according to OS and call n Three general methods used to pass parameters to the OS l Simplest: Pass the parameters in registers 4 l In some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register (See next page) 4 This l approach taken by Linux and Solaris Parameters placed, or pushed onto the stack by the program and popped off the stack by the operating system n Block and stack methods do not limit the number or length of parameters being passed Operating System Concepts – 9 th Edition 2. 18 Silberschatz, Galvin and Gagne © 2013

Parameter Passing via Table Operating System Concepts – 9 th Edition 2. 19 Silberschatz, Galvin and Gagne © 2013

2. 4 Types of System Calls n Process control n File management n Device management n Information maintenance n Communications n Protection Operating System Concepts – 9 th Edition 2. 20 Silberschatz, Galvin and Gagne © 2013

Examples of Windows and Unix System Calls Operating System Concepts – 9 th Edition 2. 21 Silberschatz, Galvin and Gagne © 2013

Standard C Library Example n C program invoking printf() library call, which calls write() system call Operating System Concepts – 9 th Edition 2. 22 Silberschatz, Galvin and Gagne © 2013

Example: MS-DOS n Single-tasking n Single memory space n Shell (command interpreter) invoked when system booted n Simple method to run program l No process created l Loads program into memory, overwriting all but the kernel and the necessary part of shell n Program exit -> shell reloaded Operating System Concepts – 9 th Edition At system startup 2. 23 running a program Silberschatz, Galvin and Gagne © 2013

Example: Free. BSD UNIX n Multitasking n Multiple memory space n User login -> invoke user’s choice of shell (command interpreter) n Shell executes fork() system call to create process l Executes exec() to load program into process l Shell waits for process to terminate or continues with user commands n Process exits with code of l = 0 – no error l > 0 – error code Operating System Concepts – 9 th Edition 2. 24 Silberschatz, Galvin and Gagne © 2013

2. 5 System Programs System programs provide a convenient environment for program development and execution. n Some of them are simply user interfaces to system calls; others are considerably more complex n Most users’ view of the operation system is defined by system programs, not the actual system calls Operating System Concepts – 9 th Edition 2. 25 Silberschatz, Galvin and Gagne © 2013

Categories of System Programs n File management l Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories n Status information l Some ask the system for info - date, time, amount of available memory, disk space, number of users l Others provide detailed performance, logging, and debugging information l Typically, these programs format and print the output to the terminal or other output devices l Some systems implement a registry - used to store and retrieve configuration information Operating System Concepts – 9 th Edition 2. 26 Silberschatz, Galvin and Gagne © 2013

Categories of System Programs (Cont. ) n File modification Text editors to create and modify files l Special commands to search contents of files or perform transformations of the text n Programming-language support l Compilers, assemblers, debuggers and interpreters sometimes provided n Program loading and execution l Absolute loaders, relocatable loaders, linkage editors, and overlayloaders, debugging systems for higher-level and machine language n Communications l Provide the mechanism for creating virtual connections among processes, users, and computer systems l Allow users to send messages to one another’s screens, browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another l Operating System Concepts – 9 th Edition 2. 27 Silberschatz, Galvin and Gagne © 2013

2. 6 Operating-System Design and Implementation n Design and Implementation of OS have no complete solutions, but some approaches have proven successful l Internal structure of different operating systems can vary widely n Start by defining goals and specifications l Affected by choice of hardware, type of system n User goals and System goals l User goals – operating system should be convenient to use, easy to learn, reliable, safe, and fast l System goals – operating system should be easy to design, implement, and maintain, as well as flexible, reliable, error-free, and efficient Operating System Concepts – 9 th Edition 2. 28 Silberschatz, Galvin and Gagne © 2013

Operating System Design and Implementation (Cont. ) n Important principle to separate Policy: What will be done? Mechanism: How to do it? n The separation of policy from mechanism is a very important principle, it allows maximum flexibility if policy decisions are to be changed later n Specifying and designing OS is highly creative task of software engineering Operating System Concepts – 9 th Edition 2. 29 Silberschatz, Galvin and Gagne © 2013

Implementation of OS n Much variation Early OSes in assembly language l Then system programming languages like Algol, PL/1 l Now C, C++ n Actually usually a mix of languages l Lowest levels in assembly l Main body in C l Systems programs in C, C++, scripting languages like PERL, Python, shell scripts l n More high-level language easier to port to other hardware n The only possible disadvantages of implementing an OS in a high-level language are l Reduced speed and l Increased storage requirements Operating System Concepts – 9 th Edition 2. 30 Silberschatz, Galvin and Gagne © 2013

2. 7 Operating-System Structure n General-purpose OS is a very large program n Many structures shown as follows Operating System Concepts – 9 th Edition 2. 31 Silberschatz, Galvin and Gagne © 2013

2. 7. 1 Simple Structure Single-tasking MS-DOS n written to provide the most functionality in the least space l Not divided into modules l Although MS-DOS has some layer structure, its interfaces and levels of functionality are not well separated Operating System Concepts – 9 th Edition 2. 32 Silberschatz, Galvin and Gagne © 2013

A Little More than Simple Structure Multitasking UNIX n Limited by hardware functionality, the original UNIX operating system had limited structuring. n A UNIX OS consists of two separable parts l Systems programs l The kernel 4 Consists of everything below the system-call interface and above the physical hardware 4 Provides – file system, – – – CPU scheduling, memory management, and other operating-system functions Operating System Concepts – 9 th Edition 2. 33 Silberschatz, Galvin and Gagne © 2013

Traditional UNIX System Structure Beyond simple but not fully layered Operating System Concepts – 9 th Edition 2. 34 Silberschatz, Galvin and Gagne © 2013

2. 7. 2 Layered Approach n The operating system is divided into a number of layers (levels), each built on top of lower layers. l The bottom layer (layer 0), is the hardware; l The highest (layer N) is the user interface. n With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers Operating System Concepts – 9 th Edition 2. 35 Silberschatz, Galvin and Gagne © 2013

2. 7. 3 Microkernels n Moves as much from the kernel into “user” space n Mach example of microkernel l Mac OS X kernel (Darwin) partly based on Mach n Communication takes place between user modules using message passing n Benefits: Easier to extend a microkernel l Easier to port the operating system to new architectures l More reliable (less code is running in kernel mode) l More secure n Detriments: l Performance overhead of user space to kernel space communication l Operating System Concepts – 9 th Edition 2. 36 Silberschatz, Galvin and Gagne © 2013

Microkernel System Structure Operating System Concepts – 9 th Edition 2. 37 Silberschatz, Galvin and Gagne © 2013

2. 7. 4 Modules n Most modern operating systems implement kernel modules l Uses object-oriented approach l Each core component is separate l Each talks to the others over known interfaces l Each is loadable as needed within the kernel n Overall, similar to layers but with more flexible n Solaris modular approach: Operating System Concepts – 9 th Edition 2. 38 Silberschatz, Galvin and Gagne © 2013

2. 7. 5 Hybrid Systems n Most modern operating systems actually not one pure model l Hybrid combines multiple approaches to address performance, security, usability needs n Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality n Windows mostly monolithic, plus microkernel for different subsystem personalities n Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment l Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions) Operating System Concepts – 9 th Edition 2. 39 Silberschatz, Galvin and Gagne © 2013

Mac OS X Structure Operating System Concepts – 9 th Edition 2. 40 Silberschatz, Galvin and Gagne © 2013

i. OS n Apple mobile OS for i. Phone, i. Pad l Structured on Mac OS X, added functionality l Does not directly run OS X applications n Architecture of i. OS l Cocoa Touch Objective-C API for developing apps l Media services layer for graphics, audio, video l Core services provides cloud computing, databases l Core operating system, based on Mac OS X kernel Operating System Concepts – 9 th Edition 2. 41 Silberschatz, Galvin and Gagne © 2013

Android n Developed by Open Handset Alliance (led primarily by Google) l Open Source n Layered similar to i. OS n Based on Linux kernel but modified l Provides process, memory, device-driver management l Adds power management n Runtime environment includes core set of libraries and Dalvik virtual machine l Apps developed in Java plus Android API 4 Java class files compiled to Java bytecode then translated to executable that runs in Dalvik VM n Libraries include frameworks for web browser (webkit), database (SQLite), multimedia, smaller libc Operating System Concepts – 9 th Edition 2. 42 Silberschatz, Galvin and Gagne © 2013

Android Architecture Operating System Concepts – 9 th Edition 2. 43 Silberschatz, Galvin and Gagne © 2013

2. 8 Operating-System Debugging n Debugging is finding and fixing errors, or bugs l OSes generate log files containing error information l Failure of an application can generate core dump file capturing memory of the process l Operating system failure can generate crash dump file containing kernel memory n Kernighan’s Law: “Debugging is twice as hard as writing the code in the first place. l Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. ” Operating System Concepts – 9 th Edition 2. 44 Silberschatz, Galvin and Gagne © 2013

Performance Tuning n Improve performance by removing bottlenecks n OS must provide means of computing and displaying measures of system behavior n For example, l l UNIX “top” program or Windows Task Manager Operating System Concepts – 9 th Edition 2. 45 Silberschatz, Galvin and Gagne © 2013

DTrace n DTrace tool in Solaris, Free. BSD, Mac OS X allows live instrumentation on production systems n Probes fire when code is executed within a provider, capturing state data and sending it to consumers of those probes n Example of following XEvents. Queued system call move from libc library to kernel and back Operating System Concepts – 9 th Edition 2. 46 Silberschatz, Galvin and Gagne © 2013

DTrace n DTrace code to record amount of time each process with User. ID 101 is in running mode (on CPU) in nanoseconds Operating System Concepts – 9 th Edition 2. 47 Silberschatz, Galvin and Gagne © 2013

2. 9 Operating-System Generation n Operating systems are designed to run on any of a class of machines; the system must be configured for each specific computer site n To install an OS, we must run a special process without OS l SYSGEN (system generation) can obtain information concerning the specific configuration of the hardware system to generate the OS of the computer system Operating System Concepts – 9 th Edition 2. 48 Silberschatz, Galvin and Gagne © 2013

2. 10 System Boot n Booting – starting a computer by loading the kernel n Bootstrap loader – code stored in ROM or EPROM (BIOS), generally known as firmware, that is able to locate the kernel, load it into memory, and start its execution n Sometimes large operation systems need two-step process: l boot block at fixed location loads bootstrap loader l then the bootstrap loader locate the kernel, load it into memory, and start its execution Operating System Concepts – 9 th Edition 2. 49 Silberschatz, Galvin and Gagne © 2013