Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Lecture 2: OS Programming Interface T.Yang, CS 170 2015.

Slides:



Advertisements
Similar presentations
Dr. Kalpakis CMSC 421, Operating Systems Operating-System Structures.
Advertisements

Chap 2 System Structures.
Operating-System Structures
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
3.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 3: Operating-System Structures System Components Operating System.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 14, 2005 Chapter 2: Operating-System.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 2: Operating-System Structures.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
1/21/2008CSCI 315 Operating Systems Design1 Operating System Structures Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 2: Operating-System Structures
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
1/28/2004CSCI 315 Operating Systems Design1 Operating System Structures & Processes Notice: The slides for this lecture have been largely based on those.
Common System Components
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 2: Operating-System Structures.
Chapter 2 Operating System Structures
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 2: Operating-System Structures.
A. Frank - P. Weisberg Operating Systems Structure of Operating Systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures Modified from the text book.
1.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition CS270 Operating Systems Understanding of operating systems and fundamental.
Abhinav Kamra Computer Science, Columbia University 3.1 Operating System Concepts Silberschatz, Galvin and Gagne  2002 Chapter 3: Operating-System Structures.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
2.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 2: Operating-System Structures.
1 Chapter 2: Operating System Structures Dr. İbrahim Körpeoğlu Last Update: Sep 30, 2011 Bilkent University Department.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: System Structures.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 2: Operating-System Structures.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 14, 2005 Operating System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 1: Introduction.
Chapter 2: Operating-System Structures Adapted to COP4610 by Robert van Engelen.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Chapter 2: System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 2: System Structures Operating System Services.
2.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Overview of topics covered Operating System Services.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Operating System Services One set of operating-system.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 2: Operating-System Structures T.Yang, 2012 Partially based on the.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 6 System Calls OS System.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 2: Operating-System Structures.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
3.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 3: Operating-System Structures System Components Operating System.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
3.1 Operating System Chapter 3: Operating-System Structures System Components Operating System Services System Calls System Programs System Structure Virtual.
Operating Systems Structure what is the organizational principle?
Shan Gao Fall 2007 Department of Computer Science Georgia State University.
Silberschatz, Galvin and Gagne  Operating System Concepts UNIT II Operating System Services.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
A. Frank - P. Weisberg Operating Systems Structure of Operating Systems.
1.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Lecture 2: OS Structures (Chapter 2.7)
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
2.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition System Programs (p73) System programs provide a convenient environment.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
2.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 2: System Structures To describe the services an operating system provides.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 2: Operating-System Structures
Operating System Structures
Lecture 4: Operating System Structures
Chapter 2: Operating-System Structures
Ch 2 - Overview Interacting with services provided by the OS
Chapter 2: System Structures
Chapter 3: Operating-System Structures
Outline Chapter 2 (cont) OS Design OS structure
Chapter 2: Operating-System Structures
System calls….. C-program->POSIX call
Presentation transcript:

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Lecture 2: OS Programming Interface T.Yang, CS

What to Learn? Operating System Services & Interface System Calls System utilities OS Layers Virtual Machines

A View of Operating System Services

Role of system calls Compilers Web Servers Web Browsers Databases Word Processing Portable OS Library System Call Interface Portable OS Kernel Platform support, Device Drivers x86ARMPowerPC Ethernet a/b/g/nSCSIIDE Graphics PCI Hardware Software System User OS Application / Service

Linux Layers

Nachos system Layers Base Operating System (Linux for our class) Nachos kernel threads Thread 1Thread 2Thread N Nachos OS modules (Threads mgm, File System, Code execution/memory mapping, System calls/Interrupt) Simulated MIPS Machine (CPU, Memory, Disk, Console) User process Projects 2&3 Project 1

OS UI: Shell Command Interpreter

OS User Interface: GUI

Programming API – OS System Call

Standard C Library Example C program invoking printf() library call, which calls write() system call Kernel mode User mode

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?

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.

Types of System Calls Process control File management Device management Information maintenance Communications Protection

Examples of Windows and Unix System Calls

Transition from User to Kernel Mode

I/O & Storage Layers High Level I/O Low Level I/O Syscall File System I/O Driver Application / Service streams handles registers descriptors Commands and Data Transfers Disks, Flash, Controllers, DMA

Unix I/O Calls fileHandle = open(pathName, flags) A file handle (called file descriptor in Unix) is a small integer, pointing to a meta data structure about this file. Pathname: a name in the file system. Flags: read only, read/write, append etc… errorCode = close(fileHandle) Kernel will free the data structures associated

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

19 Copy file1 to file2 #command syntax: copy file1 file2 #include #define BUF_SIZE 8192 void 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; }

20 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); }

Shell A shell is a job control system Lets user execute system utilities/applications Windows, MacOS, Linux all have shells Typical format: cmd arg1 arg2... argn i/o redirection filters & pipes ls | more Proj 0

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

Linux Utility Programs

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

OS Design Principles Separate policy (what to do) and mechanism (how to do) Why? Layered structure Modular Monolithic kernel vs. Microkernel Maximize flexibility

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.

MS-DOS: Simple Layer Structure written to provide the most functionality in the least space

Traditional UNIX System Structure

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

30 Monolithic Kernel vs. Microkernel

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

Mac OS X Structure

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.

Virtual Machines (Cont.) (a) Non-virtual machine (b) virtual machine

VMware Architecture

The Java Virtual Machine

New OS Interface for Applications Google Android Microsoft Windows Phone 7Apple iOS Application StoreAndroid Market App MarketplaceAppStore User Interface Java Application FrameworkSilverlightCocoa BrowserWebkit Internet ExplorerWebkit 3D GraphicsOpenGLDirectXOpenGL Main programming languageJavaC#Objective-C Virtual machineDalvik VMCLRNone

Android (Linux-based)

Apple iOS Unix-based

What we have learned? Operating System Services & Interface System Calls System utilities OS Layers and Virtual Machines: Discuss later

Role of system calls and utilities Compilers Web Servers Web Browsers Databases Word Processing Portable OS Library System Call Interface Portable OS Kernel Platform support, Device Drivers x86ARMPowerPC Ethernet a/b/g/nSCSIIDE Graphics PCI Hardware Software System User OS Application / Service System utilities