Chapter 2 OperatingSystem Structures Operating System Concepts with



















































- Slides: 51
Chapter 2: Operating-System Structures Operating System Concepts with Java – 8 th Edition 2. 1 Silberschatz, Galvin and Gagne © 2009
Chapter 2: Operating-System Structures n Operating System Services n User Operating System Interface n System Calls n Types of System Calls n System Programs n Operating System Design and Implementation n Operating System Structure n Virtual Machines n Operating System Debugging n Operating System Generation n System Boot Operating System Concepts with Java – 8 th Edition 2. 2 Silberschatz, Galvin and Gagne © 2009
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 with Java – 8 th Edition 2. 3 Silberschatz, Galvin and Gagne © 2009
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 Command-Line (CLI), Graphics User Interface (GUI), 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 with Java – 8 th Edition 2. 4 Silberschatz, Galvin and Gagne © 2009
A View of Operating System Services Operating System Concepts with Java – 8 th Edition 2. 5 Silberschatz, Galvin and Gagne © 2009
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 with Java – 8 th Edition 2. 6 Silberschatz, Galvin and Gagne © 2009
Operating System Services (Cont. ) n Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing l Resource allocation - When multiple users or multiple jobs running concurrently, resources must be allocated to each of them 4 Many types of resources - such as CPU cycles, main memory, I/O, and file storage. 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 l 4 4 4 Protection involves ensuring that all access to system resources is controlled Security of the system from outsiders requires user authentication, extends to defending external I/O devices from invalid access attempts 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 with Java – 8 th Edition 2. 7 Silberschatz, Galvin and Gagne © 2009
User Operating System Interface - CLI n Command Line Interface (CLI) or command interpreter allows direct command entry. l Sometimes implemented in kernel, sometimes by systems program l Sometimes multiple flavors implemented – shells. In UNIX there are multiple command interpreters/shells (e. g. C, Bourne, Korn) which provide similar functionality and the shell used depends on user preference. l Main function of a command interpreter is to fetch a command from a user and execute it. 4 Sometimes commands built-in, sometimes just names of programs. 4 If the latter, adding new features doesn’t require shell modification Operating System Concepts with Java – 8 th Edition 2. 8 Silberschatz, Galvin and Gagne © 2009
User Operating System Interface - CLI n UNIX implements most such user commands through system programs. n The command interpreter/shell does not understand the command; rather it uses the command to identify a file (e. g. rm) to be loaded into memory and executes it. n E. g. rm file. txt would search for a file called rm, load it into memory and execute it with the file. txt parameter. n So programmers can easily add new commands to the system by creating new files with the proper names. The shell can be small and does not need to be changed for new commands to be added. Operating System Concepts with Java – 8 th Edition 2. 9 Silberschatz, Galvin and Gagne © 2009
User Operating System Interface - CLI Operating System Concepts with Java – 8 th Edition 2. 10 Silberschatz, Galvin and Gagne © 2009
Bourne Shell Command Interpreter Operating System Concepts with Java – 8 th Edition 2. 11 Silberschatz, Galvin and Gagne © 2009
User Operating System Interface - GUI n User-friendly desktop metaphor interface l Usually mouse, keyboard, and monitor l Icons represent files, programs, actions, etc l Various mouse buttons over objects in the interface cause various actions (provide information, options, execute function, open directory (known as a folder) l Invented at Xerox PARC n Many systems now include both CLI and GUI interfaces l Microsoft Windows is GUI with CLI “command” shell l Apple Mac OS X as “Aqua” GUI interface with UNIX kernel underneath and shells available l Solaris is CLI with optional GUI interfaces (Java Desktop, KDE) Operating System Concepts with Java – 8 th Edition 2. 12 Silberschatz, Galvin and Gagne © 2009
The Mac OS X GUI Operating System Concepts with Java – 8 th Edition 2. 13 Silberschatz, Galvin and Gagne © 2009
System Calls n Programming interface to the services provided by the OS n Typically written in a high-level language (C or C++) though certain low level tasks (e. g. where hardware must be accessed directly) may need to be written in assembly 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 Win 32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) Operating System Concepts with Java – 8 th Edition 2. 14 Silberschatz, Galvin and Gagne © 2009
Example of System Calls n System call sequence to copy the contents of one file to another file Operating System Concepts with Java – 8 th Edition 2. 15 Silberschatz, Galvin and Gagne © 2009
System Call Implementation n Typically, a number associated with each system call l System-call interface maintains a table indexed according to these numbers n The system call interface intercepts function calls in the API and invokes intended system call in OS kernel (kernel mode) and returns status of the system call and any return values n The caller need know nothing about how the system call is implemented l 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 4 Managed by run-time support library (set of functions built into libraries included with compiler) Operating System Concepts with Java – 8 th Edition 2. 16 Silberschatz, Galvin and Gagne © 2009
API – System Call – OS Relationship Operating System Concepts with Java – 8 th Edition 2. 17 Silberschatz, Galvin and Gagne © 2009
Standard C Library Example n C program invoking printf() library call, which calls write() system call Operating System Concepts with Java – 8 th Edition 2. 18 Silberschatz, Galvin and Gagne © 2009
System Call Parameter Passing n Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers 4 In some cases, may be more parameters than registers l Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register 4 This approach taken by Linux and Solaris l Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system l Block and stack methods do not limit the number or length of parameters being passed l Operating System Concepts with Java – 8 th Edition 2. 19 Silberschatz, Galvin and Gagne © 2009
Parameter Passing via Table Operating System Concepts with Java – 8 th Edition 2. 20 Silberschatz, Galvin and Gagne © 2009
Types of System Calls n Process control n File management n Device management n Information maintenance n Communications n Protection Operating System Concepts with Java – 8 th Edition 2. 21 Silberschatz, Galvin and Gagne © 2009
Examples of Windows and Unix System Calls Operating System Concepts with Java – 8 th Edition 2. 22 Silberschatz, Galvin and Gagne © 2009
MS-DOS execution (a) At system startup (b) running a program Operating System Concepts with Java – 8 th Edition 2. 23 Silberschatz, Galvin and Gagne © 2009
Free. BSD Running Multiple Programs Operating System Concepts with Java – 8 th Edition 2. 24 Silberschatz, Galvin and Gagne © 2009
System Programs n System programs provide a convenient environment for program development and execution. The can be divided into: l File manipulation (e. g. cp, mv, mkdir, rm) l Status information (e. g. date, check amount of free memory – free, chkdsk, number of users) l File modification (e. g. pico or vi editors) l Programming language support (e. g. compilers, assemblers, interpreters) l Program loading and execution l Communications (e. g. creating connections among processes, send email, remote login with Telnet or SSH) l Application programs (e. g. spreadsheets) l Command interpreters or shells n Most users’ view of the operation system is defined by system programs, not the actual system calls Operating System Concepts with Java – 8 th Edition 2. 25 Silberschatz, Galvin and Gagne © 2009
System Programs n Provide a convenient environment for program development and execution l Some of them are simply user interfaces to system calls; others are considerably more complex n File management - 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 Operating System Concepts with Java – 8 th Edition 2. 26 Silberschatz, Galvin and Gagne © 2009
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 - Compilers, assemblers, debuggers and interpreters sometimes provided n Communications - 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 with Java – 8 th Edition 2. 27 Silberschatz, Galvin and Gagne © 2009
System Programs (Cont. ) n System programs themselves use system calls. Operating System Concepts with Java – 8 th Edition 2. 28 Silberschatz, Galvin and Gagne © 2009
Operating System Design and Implementation n Internal structure of different Operating Systems can vary widely n Start by defining goals and specifications n 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 with Java – 8 th Edition 2. 29 Silberschatz, Galvin and Gagne © 2009
MS-DOS Layer Structure Operating System Concepts with Java – 8 th Edition 2. 30 Silberschatz, Galvin and Gagne © 2009
Layered Approach n Modern O/S’ are very large and complex and hence are partitioned into modules with well defined I/Ps, O/Ps, and functions. n Simpler O/S’ were often monolithic systems which meant that change to one part could result in many other changes. n The operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; 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 with Java – 8 th Edition 2. 31 Silberschatz, Galvin and Gagne © 2009
UNIX n Traditional UNIX OS is layered. n 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 the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level Operating System Concepts with Java – 8 th Edition 2. 32 Silberschatz, Galvin and Gagne © 2009
Traditional UNIX System Structure Operating System Concepts with Java – 8 th Edition 2. 33 Silberschatz, Galvin and Gagne © 2009
Layered Operating System Concepts with Java – 8 th Edition 2. 34 Silberschatz, Galvin and Gagne © 2009
Mac OS X Structure Operating System Concepts with Java – 8 th Edition 2. 35 Silberschatz, Galvin and Gagne © 2009
Modules n Most modern operating systems implement kernel modules (i. e. modular kernel). 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 This design allows: l Kernel to provide core services yet also allows certain features to be implemented dynamically (e. g. device and bus drivers for specific hardware can be added to the kernel as well as support for different file systems can be added as loadable modules. ) l Core Kernel module has only core functions and knowledge how to load and communicate with other modules. Operating System Concepts with Java – 8 th Edition 2. 36 Silberschatz, Galvin and Gagne © 2009
Solaris Modular Approach Operating System Concepts with Java – 8 th Edition 2. 37 Silberschatz, Galvin and Gagne © 2009
Virtual Machines n A virtual machine provides an interface identical to the underlying bare hardware. n The operating system host creates the illusion that a process has its own processor and (virtual memory). n Each guest is provided with a (virtual) copy of underlying computer. Operating System Concepts with Java – 8 th Edition 2. 38 Silberschatz, Galvin and Gagne © 2009
Virtual Machines (Cont. ) (a) Nonvirtual machine (b) virtual machine Operating System Concepts with Java – 8 th Edition 2. 39 Silberschatz, Galvin and Gagne © 2009
Hypervisor n Hypervisor (also called a virtual machine monitor or VMM) is a program that allows multiple guest operating systems (guest VMs) to share a single hardware host. n There are two types of hypervisors: Type 1 (or bare metal) and Type 2. n Type 1 example: Xen and VMWare ESXi n Type 2 example: Fusion, Player Operating System Concepts with Java – 8 th Edition 2. 40 Silberschatz, Galvin and Gagne © 2009
Hypervisor n Hypervisors use a thin layer of code in software to allocate resources in real-time. It controls I/O and memory management. n A Type 1 hypervisor runs on bare metal, which means it doesn't need an operating system to function on a server. Typically it provides higher performance than a Type 2 hypervisor and is preferred in production environments. n A Type 2 hypervisor requires an operating system to run, so it's not a workhorse for running multiple VMs due to the overhead of the host OS. But they are suitable in test environments and also allow the user to continue using their pre-existing applications and OS along with new VMs on the same hardware. Operating System Concepts with Java – 8 th Edition 2. 41 Silberschatz, Galvin and Gagne © 2009
Java n Java consists of: 1. Programming language specification 2. Application programming interface (API) 3. Virtual machine specification Operating System Concepts with Java – 8 th Edition 2. 42 Silberschatz, Galvin and Gagne © 2009
The Java Virtual Machine Operating System Concepts with Java – 8 th Edition 2. 43 Silberschatz, Galvin and Gagne © 2009
The Java Virtual Machine Java portability across platforms. Operating System Concepts with Java – 8 th Edition 2. 44 Silberschatz, Galvin and Gagne © 2009
The Java Development Kit Operating System Concepts with Java – 8 th Edition 2. 45 Silberschatz, Galvin and Gagne © 2009
Java Operating Systems The JX operating system Operating System Concepts with Java – 8 th Edition 2. 46 Silberschatz, Galvin and Gagne © 2009
Operating-System Debugging n Debugging is finding and fixing errors, or bugs. n OSes generate log files containing error information. n Failure of an application can generate core dump file capturing memory of the process. n Operating system failure can generate crash dump file containing kernel memory. n Beyond crashes, performance tuning can optimize system performance. n Kernighan’s Law: “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. ” n DTrace tool in Solaris, Free. BSD, Mac OS X allows live instrumentation on production systems. l Probes fire when code is executed, capturing state data and sending it to consumers of those probes. Operating System Concepts with Java – 8 th Edition 2. 47 Silberschatz, Galvin and Gagne © 2009
Solaris 10 dtrace Following System Call Operating System Concepts with Java – 8 th Edition 2. 48 Silberschatz, Galvin and Gagne © 2009
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 SYSGEN program obtains information concerning the specific configuration of the hardware system. n Booting – starting a computer by loading the kernel. n Bootstrap program – code stored in ROM that is able to locate the kernel, load it into memory, and start its execution. Operating System Concepts with Java – 8 th Edition 2. 49 Silberschatz, Galvin and Gagne © 2009
System Boot n An operating system must be made available to hardware so hardware can start it. l Small piece of code – bootstrap loader, locates the kernel, loads it into memory, and starts it. l Sometimes two-step process where boot block at fixed location loads bootstrap loader. l When power initialized on system, execution starts at a fixed memory location. 4 Firmware is used to hold initial boot code. Operating System Concepts with Java – 8 th Edition 2. 50 Silberschatz, Galvin and Gagne © 2009
End of Chapter 2 Operating System Concepts with Java – 8 th Edition 2. 51 Silberschatz, Galvin and Gagne © 2009