chapter 2: operating-system structures

36
Silberschatz, Galvin and Gagne ©2009 perating System Concepts – 8 th Edition Chapter 2: Operating- System Structures T. Yang, 2012 Partially based on the OSCE text book

Upload: yan

Post on 04-Jan-2016

47 views

Category:

Documents


4 download

DESCRIPTION

Chapter 2: Operating-System Structures. Yang, 2012 Partially based on the OSCE text book. Chapter 2: Operating-System Structures. Operating System Services & User OS Interface System Calls System Programs (System utilities) Operating System Design and Implementation Virtual Machines. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 2:  Operating-System Structures

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8th Edition

Chapter 2: Operating-System Structures

T. Yang, 2012Partially based on the OSCE text book

Page 2: Chapter 2:  Operating-System Structures

Chapter 2: Operating-System Structures

Operating System Services & User OS Interface

System Calls System Programs (System utilities) Operating System Design and

Implementation Virtual Machines

Page 3: Chapter 2:  Operating-System Structures

A View of Operating System Services

Page 4: Chapter 2:  Operating-System Structures

Linux Layers

Page 5: Chapter 2:  Operating-System Structures

Nachos system Layers

Base Operating System (Linux for our class)

Nachos kernel threads

Thread 1 Thread 2 Thread N

Nachos OS modules(Threads mgm, File System, Code execution/memory mapping,

System calls/Interrupt)

Simulated MIPS Machine(CPU, Memory, Disk, Console)

User processUser process

Projects 2&3

Project 1

Page 6: Chapter 2:  Operating-System Structures

OS UI: Shell Command Interpreter

Page 7: Chapter 2:  Operating-System Structures

OS User Interface: GUI

Page 8: Chapter 2:  Operating-System Structures

Programming API – OS System Call

Page 9: Chapter 2:  Operating-System Structures

Standard C Library Example

C program invoking printf() library call, which calls write() system call

Page 10: Chapter 2:  Operating-System Structures

System Calls System calls: Programming interface to the

services provided by the OS

Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use Three most common APIs are

Win32 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)

Why use APIs rather than system calls?

Page 11: Chapter 2:  Operating-System Structures

System Calls System calls: Programming interface to the

services provided by the OS

Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use Three most common APIs are

Win32 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)

Why use APIs rather than system calls? Portability. Simplicity.

Page 12: Chapter 2:  Operating-System Structures

Types of System Calls

Process control File management Device management Information maintenance Communications Protection

Page 13: Chapter 2:  Operating-System Structures

Examples of Windows and Unix System Calls

Page 14: Chapter 2:  Operating-System Structures

Transition from User to Kernel Mode

Page 15: Chapter 2:  Operating-System Structures

Unix I/O CallsfileHandle = open(pathName, flags)

A file handle is a small integer, valid only within a single process, to operate on the device or file

Pathname: a name in the file system. In unix, devices are put under /dev. E.g. /dev/ttya is the first serial port, /dev/sda the first SCSI drive

Flags: read only, read/write, append etc… Mode may be added as the third argument for file

permissionerrorCode = close(fileHandle)

Kernel will free the data structures associated

Page 16: Chapter 2:  Operating-System Structures

Unix I/O Calls byteCount = read(fileHandle, buf, count)

Read at most count bytes from the device and put them in the byte buffer buf. Bytes placed from 0th byte.

Kernel can give the process fewer bytes, user process must check the byteCount to see how many were actually returned.

A negative byteCount signals an error (value is the error type)

byteCount = write(fileHandle, buf, count) Write at most count bytes from the buffer buf Actual number written returned in byteCount A negative byteCount signals an error

Page 17: Chapter 2:  Operating-System Structures

17

Copy file1 to file2#command syntax: copy file1 file2#include <stdio.h>#include <fcntl.h>#define BUF_SIZE 8192void main(int argc, char* argv[]) { int input_fd, output_fd; int ret_in, ret_out; char buffer[BUF_SIZE]; /* Create input file descriptor */ input_fd = open (argv [1], O_RDONLY); if (input_fd == -1) { printf ("Error in openning the input file\n"); return; }

Page 18: Chapter 2:  Operating-System Structures

18

copy file1 file2 /* Create output file descriptor */ output_fd = open(argv[2], O_WRONLY | O_CREAT, 0644); if(output_fd == -1){ printf ("Error in openning the output file\n"); return; } /* Copy process */ while((ret_in = read (input_fd, &buffer, BUF_SIZE)) > 0){ ret_out = write (output_fd, &buffer, ret_in); if(ret_out != ret_in){ /* Write error */ printf("Error in writing\n"); } } close (input_fd); close (output_fd);}

Page 19: Chapter 2:  Operating-System Structures

System Programs/Utilities Categories of System programs/utilities

Process status and management File /directory manipulation File modification and text processing Programming language support (compilers) Program loading and execution Communications Application programs

Most users’ view of the operation system is defined by system programs, not the actual system calls

Page 20: Chapter 2:  Operating-System Structures

Linux Utility Programs

Page 21: Chapter 2:  Operating-System Structures

OS Design & Implementation

Start by defining goals and specifications

Affected by Choice of hardware User goals –

convenient to use, easy to learn, reliable, safe, and fast

System goals – easy to design, implement, and

maintain, as well as flexible, reliable, error-free, and efficient

Page 22: Chapter 2:  Operating-System Structures

OS Design Principles

Separate policy (what to do) and mechanism (how to do) Why?

Layered structure Modular Monolithic kernel vs.

Microkernel

Maximize flexibility

Page 23: Chapter 2:  Operating-System Structures

Layered Approach 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.

Page 24: Chapter 2:  Operating-System Structures

MS-DOS: Simple Layer Structure

written to provide the most functionality in the least space

Page 25: Chapter 2:  Operating-System Structures

Traditional UNIX System Structure

Page 26: Chapter 2:  Operating-System Structures

Modular approach Object-oriented Each core component is separate Each talks to the others over known

interfaces Each is loadable as needed within the kernel

Page 27: Chapter 2:  Operating-System Structures

27

Monolithic Kernel vs. Microkernel

Page 28: Chapter 2:  Operating-System Structures

Microkernel System Structure Moves as much from the kernel into “user” space Communication takes place between user modules

using message passing

Benefits: Easier to extend a microkernel Easier to port the operating system to new

architectures More reliable (less code is running in kernel mode) More secure

Weakness: Performance overhead of user space to kernel

space communication

Page 29: Chapter 2:  Operating-System Structures

Mac OS X Structure

Page 30: Chapter 2:  Operating-System Structures

Virtual Machines

A virtual machine takes the layered approach

A virtual machine provides an interface identical to the underlying bare hardware.

The host creates the illusion that each guest has its own processor and virtual memory/storage.

Page 31: Chapter 2:  Operating-System Structures

Virtual Machines (Cont.)

(a) Non-virtual machine (b) virtual machine

Page 32: Chapter 2:  Operating-System Structures

VMware Architecture

Page 33: Chapter 2:  Operating-System Structures

The Java Virtual Machine

Page 34: Chapter 2:  Operating-System Structures

New OS Interface for Applications

Google Android

Microsoft WindowsPhone 7 Apple iOS

Application Store Android MarketApp Marketplace AppStore

User InterfaceJava Application Framework Silverlight Cocoa

Browser WebkitInternet Explorer Webkit

3D Graphics OpenGL DirectX OpenGL

Main programming language Java C# Objective-C

Virtual machine Dalvik VM CLR None

Page 35: Chapter 2:  Operating-System Structures

Android (Linux-based)

Page 36: Chapter 2:  Operating-System Structures

Apple iOS

Unix-based