Chapter 2 OperatingSystem Structures Operating System Concepts 9

  • Slides: 27
Download presentation
Chapter 2: Operating-System Structures Operating System Concepts – 9 th Edition Silberschatz, Galvin and

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

System Calls n Programming interface to the services provided by the OS n Typically

System Calls n 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 Programming 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) Note that the system-call names used throughout this text are generic Operating System Concepts – 9 th Edition 2. 2 Silberschatz, Galvin and Gagne © 2013

Example of Standard API Operating System Concepts – 9 th Edition 2. 3 Silberschatz,

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

API – System Call – OS Relationship Operating System Concepts – 9 th Edition

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

Examples of Windows and Unix System Calls Operating System Concepts – 9 th Edition

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

Standard C Library Example n C program invoking printf() library call, which calls write()

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

Example: MS-DOS n Single-tasking n Shell invoked when system booted n Simple method to

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

Example: Free. BSD n Unix variant n Multitasking n User login -> invoke user’s

Example: Free. BSD n Unix variant n Multitasking n User login -> invoke user’s choice of shell 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: l code = 0 – no error l code > 0 – error code Operating System Concepts – 9 th Edition 2. 8 Silberschatz, Galvin and Gagne © 2013

Operating System Design and Implementation n Design and Implementation of OS not “solvable”, but

Operating System Design and Implementation n Design and Implementation of OS not “solvable”, but some approaches have proven successful n Internal structure of different Operating Systems can vary widely n Start the design 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 – 9 th Edition 2. 9 Silberschatz, Galvin and Gagne © 2013

Implementation n Much variation l Early OSes in assembly language l Then system programming

Implementation n Much variation l 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 n More high-level language easier to port to other hardware l But slower n Emulation can allow an OS to run on non-native hardware Operating System Concepts – 9 th Edition 2. 10 Silberschatz, Galvin and Gagne © 2013

Operating System Structure n General-purpose OS is very large program n Various ways to

Operating System Structure n General-purpose OS is very large program n Various ways to structure ones l Simple structure – MS-DOS l More complex -- UNIX l Layered – an abstrcation l Microkernel -Mach Operating System Concepts – 9 th Edition 2. 11 Silberschatz, Galvin and Gagne © 2013

Simple Structure -- MS-DOS n MS-DOS – written to provide the most functionality in

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

Non Simple Structure -- UNIX – limited by hardware functionality, the original UNIX operating

Non Simple Structure -- UNIX – limited by hardware functionality, the original UNIX operating system had limited structuring. The 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 – 9 th Edition 2. 13 Silberschatz, Galvin and Gagne © 2013

Traditional UNIX System Structure Beyond simple but not fully layered Operating System Concepts –

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

Layered Approach n The operating system is divided into a number of layers (levels),

Layered Approach 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 – 9 th Edition 2. 15 Silberschatz, Galvin and Gagne © 2013

Microkernel System Structure n Moves as much from the kernel into user space n

Microkernel System Structure 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: l 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 Operating System Concepts – 9 th Edition 2. 16 Silberschatz, Galvin and Gagne © 2013

Microkernel System Structure Operating System Concepts – 9 th Edition 2. 17 Silberschatz, Galvin

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

Modules n Many modern operating systems implement loadable kernel modules l Uses object-oriented approach

Modules n Many modern operating systems implement loadable 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 l Linux, Solaris, etc Operating System Concepts – 9 th Edition 2. 18 Silberschatz, Galvin and Gagne © 2013

Hybrid Systems n Most modern operating systems are actually not one pure model l

Hybrid Systems n Most modern operating systems are actually not one pure model l Hybrid combines multiple approaches to address performance, security, usability needs l Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality l 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. 19 Silberschatz, Galvin and Gagne © 2013

Mac OS X Structure Operating System Concepts – 9 th Edition 2. 20 Silberschatz,

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

i. OS n Apple mobile OS for i. Phone, i. Pad l Structured on

i. OS n Apple mobile OS for i. Phone, i. Pad l Structured on Mac OS X, added functionality l Does not run OS X applications natively 4 Also runs on different CPU architecture (ARM vs. Intel) 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. 21 Silberschatz, Galvin and Gagne © 2013

Android n Developed by Open Handset Alliance (mostly Google) l Open Source n Similar

Android n Developed by Open Handset Alliance (mostly Google) l Open Source n Similar stack to IOS 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 than runs in Dalvik VM n Libraries include frameworks for web browser (webkit), database (SQLite), multimedia, smaller libc Operating System Concepts – 9 th Edition 2. 22 Silberschatz, Galvin and Gagne © 2013

Android Architecture Operating System Concepts – 9 th Edition 2. 23 Silberschatz, Galvin and

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

Operating-System Debugging n Debugging is finding and fixing errors, or bugs n OS generate

Operating-System Debugging n Debugging is finding and fixing errors, or bugs n OS 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 l Sometimes using trace listings of activities, recorded for analysis l Profiling is periodic sampling of instruction pointer to look for statistical trends 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. ” Operating System Concepts – 9 th Edition 2. 24 Silberschatz, Galvin and Gagne © 2013

Performance Tuning n Improve performance by removing bottlenecks n OS must provide means of

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

DTrace n DTrace tool in Solaris, Free. BSD, Mac OS X allows live instrumentation

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. 26 Silberschatz, Galvin and Gagne © 2013

Dtrace (Cont. ) n DTrace code to record amount of time each process with

Dtrace (Cont. ) 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. 27 Silberschatz, Galvin and Gagne © 2013