Chapter 2 Operating System Structures Joe Mc Carthy

  • Slides: 56
Download presentation
Chapter 2: Operating System Structures Joe Mc. Carthy CSS 430: Operating Systems - OS

Chapter 2: Operating System Structures Joe Mc. Carthy CSS 430: Operating Systems - OS Structures 1

Outline • Announcements / updates – Gayle Laakman Mc. Dowell, Th, 10/11, 4: 30

Outline • Announcements / updates – Gayle Laakman Mc. Dowell, Th, 10/11, 4: 30 pm, UW 2 -005 – GUIs / IDEs for remotely accessing uw 1 -320 -lab – Catalyst Go. Post guidelines • Questions on Programming Assignment 1? • Sample programs – Using fork(), pipe(), dup 2(), close(), execlp() • Chapter 2: Operating Systems Structures – Including more on fork(), pipe(), dup 2(), close(), execlp() • Live programming experiments (time permitting) • Next time – Chapter 3: Processes CSS 430: Operating Systems - OS Structures 2

Comfort, Growth & Panic Zones http: //www. alljapaneseallthetime. com/blog/comfort-zone-growth-zone-panic-zone Goal: stretch as much as

Comfort, Growth & Panic Zones http: //www. alljapaneseallthetime. com/blog/comfort-zone-growth-zone-panic-zone Goal: stretch as much as possible from your comfort zone into your growth zone while avoiding your panic zone TMI / too much help [on forum] comfort zone CSS 430: Operating Systems - OS Structures 3

Sample Programs • C++ programs using fork(), pipe(), dup 2() • ~css 430/examples/processmgmt on

Sample Programs • C++ programs using fork(), pipe(), dup 2() • ~css 430/examples/processmgmt on uw 1 -320 -lab • Recommendation: • Decompose problem into small[er] chunks • Experiment with small changes (compile, test, debug) • testpipe[0 -2]. cpp – Send “hello” through pipe to STDOUT – Differences: • hardcoded string vs. argv[1], write() vs execlp() • pipedup 2[a-f]. cpp – Using system calls to do ‘ps –A | tr a-z A-Z’ – Differences • Parent vs. child calling ps vs. tr • Using read() & write() vs. execlp() for tr CSS 430: Operating Systems - OS Structures 4

Chapter 2: OS Structures • • • Operating System Services User Operating System Interface

Chapter 2: OS Structures • • • Operating System Services User Operating System Interface System Calls Types of System Calls System Programs Operating System Design and Implementation Operating System Structure Virtual Machines Operating System Debugging Operating System Generation System Boot Material derived, in part, from Operating Systems Concepts with Java, 8 th Ed. © 2009 Silberschatz, Galvin & Gagne CSS 430: Operating Systems - OS Structures 5

A View of Operating System Services CSS 430: Operating Systems - OS Structures 6

A View of Operating System Services CSS 430: Operating Systems - OS Structures 6

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

System Calls • Programming interface to the services provided by the OS • Typically written in a high-level language (C or C++) • Mostly accessed by programs via a high-level Application Program Interface (API) rather than direct system call use • Three common APIs are • Win 32 API for Windows • POSIX API for POSIX-based systems UNIX, Linux, Mac OS X) • Java API for the Java virtual machine (JVM) • Why use APIs rather than system calls? (Note that the system-call names used throughout this text are generic) CSS 430: Operating Systems - OS Structures 7

Example of System Calls • System call sequence to copy the contents of one

Example of System Calls • System call sequence to copy the contents of one file to another file CSS 430: Operating Systems - OS Structures 8

Example of System Calls • System call sequence to copy the contents of one

Example of System Calls • System call sequence to copy the contents of one file to another file CSS 430: Operating Systems - OS Structures 9

Example of Standard API • Consider the Read. File() function in the Win 32

Example of Standard API • Consider the Read. File() function in the Win 32 API—a function for reading from a file • A description of the parameters passed to Read. File() – HANDLE file—the file to be read – LPVOID buffer—a buffer where the data will be read into and written from – DWORD bytes. To. Read—the number of bytes to be read into the buffer – LPDWORD bytes. Read—the number of bytes read during the last read – LPOVERLAPPED ovl—indicates if overlapped I/O is being used CSS 430: Operating Systems - OS Structures 10

API – System Call – OS Relationship CSS 430: Operating Systems - OS Structures

API – System Call – OS Relationship CSS 430: Operating Systems - OS Structures 11

Standard C Library Example • printf() C library call write() system call CSS 430:

Standard C Library Example • printf() C library call write() system call CSS 430: Operating Systems - OS Structures 12

System Call Parameter Passing • Often, more information is required than simply the name

System Call Parameter Passing • Often, more information is required than simply the name of the desired system call – Exact type & amount of information vary according to OS & call • Three general methods used to pass parameters to the OS CSS 430: Operating Systems - OS Structures 13

System Call Parameter Passing • Often, more information is required than simply the name

System Call Parameter Passing • Often, more information is required than simply the name of the desired system call – Exact type & amount of information vary according to OS & call • 3 general methods used to pass parameters to the OS – Simplest: pass the parameters in registers – Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register • This 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 • Advantages / disadvantages? CSS 430: Operating Systems - OS Structures 14

System Call Parameter Passing • Often, more information is required than simply the name

System Call Parameter Passing • Often, more information is required than simply the name of the desired system call – Exact type & amount of information vary according to OS & call • 3 general methods used to pass parameters to the OS – Simplest: pass the parameters in registers – Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register • This 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 • Advantages / disadvantages – Block and stack methods do not limit the number or length of parameters being passed CSS 430: Operating Systems - OS Structures 15

Parameter Passing via Table CSS 430: Operating Systems - OS Structures 16

Parameter Passing via Table CSS 430: Operating Systems - OS Structures 16

Types of System Calls • • • Process control File management Device management Status

Types of System Calls • • • Process control File management Device management Status Information Communications Protection CSS 430: Operating Systems - OS Structures 17

Process Control Process: a program loaded in memory and able to execute CSS 430:

Process Control Process: a program loaded in memory and able to execute CSS 430: Operating Systems - OS Structures 18

Process Control Process: a program loaded in memory and able to execute • OS

Process Control Process: a program loaded in memory and able to execute • OS Operations: • Create/terminate process • Get/set process attributes • Wait for time, event, signal • Allocate/free memory CSS 430: Operating Systems - OS Structures 19

Process Control Process: a program loaded in memory and able to execute Process states

Process Control Process: a program loaded in memory and able to execute Process states Memory File Descriptor Table Registers • OS Operations: • Create/terminate process • Get/set process attributes • Wait for time, event, signal • Allocate/free memory [Preview of Chapter 3] CSS 430: Operating Systems - OS Structures 20

fork() int main( ) { int fd[2]; int pid; pid = fork() Process id

fork() int main( ) { int fd[2]; int pid; pid = fork() Process id of child (>0) if ( pipe( fd ) < 0 ) { perror( "pipe error" ); exit( EXIT_FAILURE ); } if ( ( pid = fork() ) < 0 ) { perror ( "fork error" ); exit( EXIT_FAILURE ); } … 0 parent fd[0] fd[1] pid … CSS 430: Operating Systems - OS Structures child fd[0] fd[1] pid … 21

pipe() int main( ) { int fd[2]; int pid; if ( pipe( fd )

pipe() int main( ) { int fd[2]; int pid; if ( pipe( fd ) < 0 ) { perror( "pipe error" ); exit( EXIT_FAILURE ); } if ( ( pid = fork() ) < 0 ) { perror ( "fork error" ); exit( EXIT_FAILURE ); } … http: //vip. cs. utsa. edu/classes/cs 3733 s 2009/notes/USP-06. html CSS 430: Operating Systems - OS Structures 22

pipe() + fork() int main( ) { int fd[2]; int pid; if ( pipe(

pipe() + fork() int main( ) { int fd[2]; int pid; if ( pipe( fd ) < 0 ) { perror( "pipe error" ); exit( EXIT_FAILURE ); } if ( ( pid = fork() ) < 0 ) { perror ( "fork error" ); exit( EXIT_FAILURE ); } … http: //vip. cs. utsa. edu/classes/cs 3733 s 2009/notes/USP-06. html CSS 430: Operating Systems - OS Structures 23

close() + dup 2() int main( ) { int fd[2]; int pid; if (

close() + dup 2() int main( ) { int fd[2]; int pid; if ( pipe( fd ) < 0 ) { … } if ( ( pid = fork() ) < 0 ) { …} … if ( pid > 0 ) { // parent close( fd[1] ); dup 2( fd[0], 0 ); close( fd[0] ); …} else { // child close( fd[0] ); dup 2( fd[1], 1 ); close( fd[1] ); execlp( "ps", "-A", NULL ); } … http: //vip. cs. utsa. edu/classes/cs 3733 s 2009/notes/USP-06. html CSS 430: Operating Systems - OS Structures 24

fork() + execlp() (pipedup 2 a. cpp) int main( ) { int fd[2]; int

fork() + execlp() (pipedup 2 a. cpp) int main( ) { int fd[2]; int pid; parent if ( pipe( fd ) < 0 ) { … } if ( ( pid = fork() ) < 0 ) { … } if ( pid > 0 ) { // parent close( fd[1] ); dup 2( fd[0], 0 ); close( fd[0] ); … } else { // child close( fd[0] ); fd[0] dup 2( fd[1], 1 ); fd[1] pid close( fd[1] ); … execlp( "ps", "-A", NULL ); } … child fd[0] fd[1] pid … pipedup 2 a CSS 430: Operating Systems - OS Structures ps -A 25

Resource Management • File Management [joemcc@uw 1 -320 -18 Thread. OS]$ ls -l -rw-------

Resource Management • File Management [joemcc@uw 1 -320 -18 Thread. OS]$ ls -l -rw------- 1 css 430 users 10193 Nov -rw------- 1 css 430 users 8603 Dec -rw-r--r-- 1 css 430 users 8395 Nov -rw------- 1 css 430 users 8817 Nov Kernel*. java 11 2004 Kernel_fil. java 23 2010 Kernel_hw 3 part 1. java 13 2004 Kernel. java 11 2004 Kernel_org. java • Device Management [joemcc@uw 1 -320 -18 Thread. OS]$ stat Kernel. java File: `Kernel. java' Size: 8395 Blocks: 24 IO Block: 32768 regular file Device: 17 h/23 d Inode: 130884 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1803/ css 430) Gid: ( 100/ users) Access: 2011 -11 -12 19: 40: 45. 00000 -0800 Modify: 2004 -11 -13 20: 36: 20. 00000 -0800 Change: 2011 -10 -17 14: 00: 43. 00000 -0700 CSS 430: Operating Systems - OS Structures 26

Resource Management • File Management – Create file, delete file – Open, close –

Resource Management • File Management – Create file, delete file – Open, close – Read, write, reposition file pointer – Get file attributes, set file attributes • Device Management – Request device, release device – Read, write, reposition read/write head – Get device attributes, set device attributes – Logically attach (mount) or detach (unmount) devices CSS 430: Operating Systems - OS Structures 27

Maintaining info / connections • Information Maintenance • Communication CSS 430: Operating Systems -

Maintaining info / connections • Information Maintenance • Communication CSS 430: Operating Systems - OS Structures 28

Maintaining info / connections • Information Maintenance – Get/set time or date – Get/set

Maintaining info / connections • Information Maintenance – Get/set time or date – Get/set system data – Get/set process, file or device attributes • Communication – Create/delete communication connection – Send/receive messages – Maintain communication status information CSS 430: Operating Systems - OS Structures 29

Windows & Unix System Calls CSS 430: Operating Systems - OS Structures 30

Windows & Unix System Calls CSS 430: Operating Systems - OS Structures 30

MS-DOS execution (a) At system startup (b) running a program CSS 430: Operating Systems

MS-DOS execution (a) At system startup (b) running a program CSS 430: Operating Systems - OS Structures 31

Free. BSD Running Multiple Programs CSS 430: Operating Systems - OS Structures 32

Free. BSD Running Multiple Programs CSS 430: Operating Systems - OS Structures 32

OS Design & Implementation • Important distinction: – Policy: What will be done? –

OS Design & Implementation • Important distinction: – Policy: What will be done? – Mechanism: How to do it? • Benefits: – Maximum flexibility – Policy changes need not entail mechanism changes & vice versa CSS 430: Operating Systems - OS Structures 33

Simple Structure • MS-DOS – Goal: most functionality in the least space – Not

Simple Structure • MS-DOS – Goal: most functionality in the least space – Not divided into modules – Interfaces & levels of functionality not well separated CSS 430: Operating Systems - OS Structures 34

Layered Approach • Modularity: – Each layer (level) uses functions & services only from

Layered Approach • Modularity: – Each layer (level) uses functions & services only from layer(s) directly below – Provides functions & services only to layer(s) directly above CSS 430: Operating Systems - OS Structures 35

Layered Approach to Networking CSS 430: Operating Systems - OS Structures 36

Layered Approach to Networking CSS 430: Operating Systems - OS Structures 36

Traditional UNIX System Structure CSS 430: Operating Systems - OS Structures 37

Traditional UNIX System Structure CSS 430: Operating Systems - OS Structures 37

UNIX • Two components – Systems programs • ls, rm, cp, mv, ps, grep,

UNIX • Two components – Systems programs • ls, rm, cp, mv, ps, grep, wc, … – The kernel • Everything below the system-call interface and above the physical hardware • Provides the file system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level CSS 430: Operating Systems - OS Structures 38

Microkernel System Structure • Moves as much from the kernel into “user” space •

Microkernel System Structure • Moves as much from the kernel into “user” space • Communication takes place between user modules using message passing • Benefits: • Detriments: CSS 430: Operating Systems - OS Structures 39

Microkernel System Structure • Moves as much from the kernel into “user” space •

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 • Detriments: – Performance overhead of user space to kernel space communication CSS 430: Operating Systems - OS Structures 40

Mac OS X Structure CSS 430: Operating Systems - OS Structures 41

Mac OS X Structure CSS 430: Operating Systems - OS Structures 41

Modules • Most modern operating systems implement kernel modules – Uses object-oriented approach –

Modules • Most modern operating systems implement kernel modules – Uses object-oriented approach – Each core component is separate – Each talks to the others over known interfaces – Each is loadable as needed within the kernel • Overall, similar to layers but with more flexible CSS 430: Operating Systems - OS Structures 42

Solaris Modular Approach CSS 430: Operating Systems - OS Structures 43

Solaris Modular Approach CSS 430: Operating Systems - OS Structures 43

Virtual Machines • A virtual machine takes the layered approach to its logical conclusion.

Virtual Machines • A virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware. • A virtual machine provides an interface identical to the underlying bare hardware. • The operating system host creates the illusion that a process has its own processor and (virtual memory). • Each guest is provided with a (virtual) copy of underlying computer. CSS 430: Operating Systems - OS Structures 44

Virtual Machines (a) Nonvirtual machine (b) virtual machine CSS 430: Operating Systems - OS

Virtual Machines (a) Nonvirtual machine (b) virtual machine CSS 430: Operating Systems - OS Structures 45

Solaris 10 with Two Containers CSS 430: Operating Systems - OS Structures 46

Solaris 10 with Two Containers CSS 430: Operating Systems - OS Structures 46

VMware Architecture CSS 430: Operating Systems - OS Structures 47

VMware Architecture CSS 430: Operating Systems - OS Structures 47

Java • Java consists of: 1. Programming language specification 2. Application programming interface (API)

Java • Java consists of: 1. Programming language specification 2. Application programming interface (API) 3. Virtual machine specification CSS 430: Operating Systems - OS Structures 48

The Java Development Kit CSS 430: Operating Systems - OS Structures 49

The Java Development Kit CSS 430: Operating Systems - OS Structures 49

Cloud Computing CSS 430: Operating Systems - OS Structures 50

Cloud Computing CSS 430: Operating Systems - OS Structures 50

http: //news. cnet. com/8301 -13953_3 -9917409 -80. html CSS 430: Operating Systems - OS

http: //news. cnet. com/8301 -13953_3 -9917409 -80. html CSS 430: Operating Systems - OS Structures 51

Amazon Web Services CSS 430: Operating Systems - OS Structures 52

Amazon Web Services CSS 430: Operating Systems - OS Structures 52

CSS 430: Operating Systems - OS Structures 53

CSS 430: Operating Systems - OS Structures 53

CSS 430: Operating Systems - OS Structures 54

CSS 430: Operating Systems - OS Structures 54

The Cost of Convenience CSS 430: Operating Systems - OS Structures 55

The Cost of Convenience CSS 430: Operating Systems - OS Structures 55

For next time • Readings – Chapters 3: Processes CSS 430: Operating Systems -

For next time • Readings – Chapters 3: Processes CSS 430: Operating Systems - OS Structures 56