summer 2015 silicon valley university confidential1 operating systems dr. jerry shiao, silicon...

51
Summer 2015 SILICON VALLEY UNIVERSITY CONFIDENTIAL 1 Operating Systems Dr. Jerry Shiao, Silicon Valley University

Upload: emery-bishop

Post on 13-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Summer 2015SILICON VALLEY UNIVERSITY

CONFIDENTIAL 1

Operating Systems

Dr. Jerry Shiao, Silicon Valley University

SILICON VALLEY UNIVERSITY CONFIDENTIAL 2

Operating System Structures Operating System Overview

Operating System Objectives Operating System Development

Design Issues. Evolution of Operating System Structures and Capabilities

Layered Approach to Operating System Design. Modular Kernel. Micro Kernel.

Virtual Machines. View three aspects of an Operating System:

Services provided by the system. Interface made available to users and programmers. Components and their interconnections.

Viewpoints of the Users, Programmers, and OS Designers. System Calls System Programs or Utilities

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 3

Operating System Structures Operating System Objectives

Operating System is a program that controls the execution of application programs and acts as an interface between applications and computer hardware.

Convenience: Makes a computer more convenient to use. Efficiency: Allows the Computer System resources to be used in an efficient

manner. Ability to evolve: Should be constructed to permit the effective development,

testing and introduction of new system functions without interfering with service. Operating System as a User/Computer Interface

User views Computer System in terms of a set of applications.

Programmer make use of system programs as an interface to the Computer System.

The Operating System masks the details of the Computer System hardware from the programmer and provides the programmer with a convenient interface for using the Computer System.

Copyright @ 2009 Pearson Education, Inc.

End User

Programmer

SILICON VALLEY UNIVERSITY CONFIDENTIAL 4

Operating System Structures Operating System as Resource Manager Operating System as a control mechanism:

Operating System functions as computer software: Program or suite of programs executed by processor.

Operating System must relinquish control to allow other (User) programs to execute.

Main ResourcesManaged by Operating System

Copyright @ 2009 Pearson Education, Inc.

Memory:Kernel functions resides in memory.User programs and data occupy the rest.

Processor(s):OS determines how much time devoted to each user program.

I/O Devices:OS decides when I/O device can be used by program in execution.OS controls access and use of files.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 5

Operating System Structures

Development of Operating System Five Major Theoretical Advances in Operating System Development:

Processes Memory Management Information Protection and Security Scheduling and Resource Management System Structure

Design Issue: Processes Fundamental to the structure of Operating System. Definition of a Process:

Program in execution. Instance of a program running on a computer. Entity that can be assigned to and executed on a processor. Unit of activity characterized by a single sequential thread of execution, a

current state, and an associated set of system resources. Concept of the process is the foundation to resolving the timing

and synchronization problems caused by: Multiprogramming Batch Operations. Time Sharing. Real-Time Transaction Systems.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 6

Operating System Structures

Design Issue: Processes (Cont) Multiprogramming Batch Operations:

Designed to keep the processor and I/O devices (including storage devices) simultaneously busy to achieve maximum efficiency.

Interrupt-Driven I/O or DMA allow processor to issue I/O command for one job and schedule another job for execution.

Time-Sharing: Designed to be responsive to needs of individual user and supporting many

users simultaneously. Real-Time Transaction Processing:

Designed to be responsive to applications (queries or updates against database in Airline Reservation System).

System software to coordinate the different activities difficult: Improper Synchronization: Lost signal when waiting for event ( I/O Complete

). Failed Mutual Exclusion: Two users fail to lock-out when using shared

resource ( Writing to File ). Non-determinate Program Operation: Programs writing shared memory

areas, altering program execution. Deadlocks: Two programs waiting for each other to release desired

resource.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 7

Operating System Structures

Design Issue: Processes (Cont) Process: Foundation to systematically monitor and control programs

executing on the Processor. An Executable Program. Associated data (variables, work space, buffers, etc). Execution context of the program.

Execution Context: Internal data used by Operating System to supervise and control the

process. Contents of the processor registers ( Program Counter, Data Registers ). State of the process

Running or ready to run (Runqueue). Uninterruptible sleep (usually I/O). Interruptible sleep (waiting for event). Zombie (Terminated but parent has not received status). Stopped (Job control signal or being traced).

Priority of the process. Process is a Data Structure.

Executing or awaiting execution.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 8

Operating System Structures

Design Issue: Processes (Cont)

Copyright @ 2009 Pearson Education, Inc.

Process Index: Index into the Process List.

Program Counter: Next instruction in the process to execute.

Base and Limit Registers: Region in memory occupied by the process.

Process List: One entry for each process. Pointer to the block of memory containing the process.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 9

Operating System Structures Development of Operating System Design Issue: Memory Management

Operating System five principle Storage Management requirements: Process Isolation: Prevent independent process from interfering with other’s

memory. Automatic Allocation and Management: Programs dynamically allocated

across memory hierarchy ( Virtual Memory ). Support of Modular Programming. Protection and Access Control: Support sharing of memory, when required

by processes. Long-Term Storage: Support storing of information persistently.

Requirements meet by Virtual Memory and File System Facilities. Virtual Memory (MMU Memory Management Unit):

Facility that allows programs to address memory from logical point of view, without regard to the amount of main memory physically available.

Necessary to keep multiple user jobs in Main Memory concurrently. Paging System divided process into fixed-sized blocks that can be located

anywhere in Main Memory and on secondary storage. Virtual Address: Page number and Offset within page.

File System: Stores information in named objects, Files. Files used by Operating System as unit of Access Control and Protection.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 10

Operating System Structures

Design Issue: Memory Management (Cont)

Copyright @ 2009 Pearson Education, Inc.

Secondary Memory (disk) can hold many fixed-length pages. A user program consists of some number of pages. Pages for all programs plus the Operating System are on disk, as files.

Main memory consists of a number of fixed-length frames, each equal to the size of a page.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 11

Operating System Structures

Design Issue: Memory Management (Cont)

Copyright @ 2009 Pearson Educaton, Inc.

Address Translation Hardware (Memory Management Unit) is interposed between the processor and memory.

Virtual Address maps programs reference locations into real Main Memory addresses.

Virtual Address not in memory, portion of contents of memory is swapped out to auxiliary memory and desired block of data swapped in.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 12

Operating System Structures Development of Operating System Design Issue: Information Protection and Security Growth in Time-Sharing Systems has increased concerns in

controlling access to Computer System and information stored on the Computer System.

Operating System has built-in protection and security mechanism. Four Protection and Security catagories:

Availability: Protecting the system against interruption. Denial-of-Service attacks. Viruses, Worms

Confidentiality: Protect data from unauthorized access. User Authentication. Access Control for File System.

Data Integrity: Protect data from unauthorized modification. Symmetric and Asymmetric Encryption algorithms.

Authenticity: Verifying the identity of users and validity of messages or data.

Symmetric and Asymmetric Encryption algorithms. Message Digest.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 13

Operating System Structures Development of Operating System Design Issue: Scheduling and Resource Management Key responsibility of Operating System:

Manage available resources (Main Memory, I/O Devices, Processor(s)). Schedule available resources use by processes.

Resource Allocation and Scheduling Policy Factors: Fairness: Processes (in same class or category) have fair access to

resources. Differential Responsiveness: Different service requirements require

different allocation and scheduling decisions. Efficiency: Maximize throughput, minimize response time, and maximize

users. Major elements in scheduling of processes and allocation of

resources: Short-term Queues, Long-term Queues, and I/O Queues. Queue strategies: Round-Robin, Priority Levels. Interrupt Handler: Operating System receives control of the processor.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 14

Operating System Structures Design Issue: Scheduling and Resource Management (Cont)

Copyright @ 2009 Pearson Education, Inc.

Queues: List of processes waiting for resources.

Operating System regains control of CPU to schedule processes.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 15

Operating System Structures Development of Operating System Design Issue: Operating System’s System Structure Complexity requires focus on the Software Structure.

MAC OS X has over 85 million lines of code. Windows 7 has over 40 million lines of code. Linux 3.1 over 15 million lines of code (Debian Distribution over 67 million).

Full featured Operating System problems: Large code base more likely to have latent bugs that are not caught during QA

testing and appear in the field. Latent bugs must be fixed and reworked. Performance degrades after bug fixes or upgrades. Complexity makes it vulnerable to viruses, worms, and unauthorized access.

How can Operating System’s System Structure be organized to limit effort in diagnosing and fixing errors? Modularity: Modules with well-defined interfaces facilitates system evolution

without impacting other modules. Hierarchical layers and information abstraction.

Operating System is a series of levels. Each lower level performs a related subset (more primitive) of the functions

required of the Operating System. Changes in one level does not require changes in another levell:

Decomposed one large problem into a number of more manageable subproblems.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 16

Operating System Structures Design Issue: Operating System’s System Structure (Cont) Define Goals and Specifications - Type of Operating System:

Batch, Time-Sharing, Single User, Multi-User, Distributed, Real-Time, General Purpose.

Different requirements create large variety of solutions: VxWorks: Real-Time Embedded System. MVS: Multi-User for IBM Mainframes. MS-DOS: Single User System. UNIX / Linux: Time-Sharing

Software Engineering Prinicples Separation of Policy from Mechanism. Mechanism determines how to do something.

Watch-Dog Time Out prevents system hanging. Clock Interrupt occurs every system tick.

Policies determine what will be done. How long the timer is set before Watch-Dog Time Out. Clock Interrupt used to schedule processes based on priority policy.

Implementation Mostly written in C Programming Language.

Code written faster, easier to understand, easier to port to other hardware solution.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 17

Operating System Structures

Design Issue: Operating System’s System Structure (Cont) Operating System Structure Simple Structure

Levels of functionality not separated. User applications access I/O routines and hardware. Example, MS-DOS.

Levels of functionality separated, but kernel one large monolithic code. Example, UNIX.

Copyright @ 2009 John Wiley & Sons Inc.

( The Users )

Shell and CommandsCompilers and InterpretersSystem Libraries

System Call Interface to the UNIX Kernel

Signals Terminal HandlingCharacter I/O SystemTerminal Drivers

File SystemSwapping Block I/O SystemDisk and TapeDrivers.

CPU SchedulingPage SwapDemand PagingVirtual Memory

System Call Interface to the UNIX Kernel

Term ControllersTerminals.

Memory ControllersPhysical Memory

Disk ControllersDisks and Tapes

Application Programs

Resident System Program

MS-DOS Device Drivers

ROM BIOS Device Drivers

SILICON VALLEY UNIVERSITY CONFIDENTIAL 18

Operating System Structures

Design Issue: Operating System’s System Structure (Cont) Modularity: Changes to inner working of the system more controlled. Layered Approach

Operating System divided into number of layers. Bottom layer ( Layer 0 ) is the hardware. Top layer ( Layer N ) is the user interface. Layer Functionality: Abstract object made of data and operations that

can manipulate those data. The Operating System layer consists of data structures and a set of routines

that can be invoked by higher-level layer. The Operating System layer can only invoke operations on lower-level layer.

Advantages: Simplifies implementation of the Operating System. Layer can only use

functions and services of lower-level layer. Simplifies debugging, and system verification. Once one layer is debugged,

its operations is assumed correct and next layer can be debugged. Disadvantages:

Defining the Operating System layers. Execution flow has to flow downward.

Overhead of calling the functions of each layer as the execution flow flows downward.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 19

Operating System Structures

Design Issue: Operating System’s System Structure (Cont) Layered Approach

Copyright @ 2009 John Wiley & Sons Inc.

Layer NUser Interface

Layer NUser Interface

. . .

Layer 1

Layer 0Hardware

Control and data execution flow downstream.

Hides existence of certain data structures, operations, and hardware from higher-level layers.

Difficulty:-How to define the various layers.-Less efficient than other types.- Adds overhead to the system call.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 20

Operating System Structures Design Issue: Operating System’s System Structure (Cont)

Lower layers have shorter time scale. Layer 13 at user level communicates with user at slow pace (in seconds). Layer 1 at hardware level communicates in micro or nanoseconds.

Levels 13 – 8: Operating System deals with external objects

Copyright @ 2009 Pearson Education, Inc.

Level Name Objects Example Ops

13 Shell User Programming Environment: Interface to Operating System for user.

Bourne, C, Bash

12 User processes User processes: Process control (Virtual Address space, parameters, info for process management).

Quit, Kill

11 Directories Directories: Mapping file name to inode to locate object.

Create, destroy, attach, search, list

10 Devices External: Printers, Displays, KeyboardsAccess using standard interfaces.

Open, Close, R/W

9 File System Files: Abstract entities. Create, Destroy, Open, Close, R/W

8 Communications Pipes: Sharing and syncing processes. Create, Destroy, Open, Close, RW

SILICON VALLEY UNIVERSITY CONFIDENTIAL 21

Operating System Structures Design Issue: Operating System’s System Structure (Cont) Levels 5 – 7: Operating System and Multiprogramming support. Levels 4 – 1: Processor Hardware.

Copyright @ 2009 Pearson Education, Inc.

Level Name Objects Example Ops

7 Virtual Memory Segments/Pages: Virtual Memory blocks moved between Main Memory and Disk.

Read, Write, Fetch.

6 Local Secondary Store

Blocks of data: Positioning and transfer of data.

Read, Write, Allocate, Free

5 Primitive Processes

Primitive processes, Semaphores, Ready List: Process is program in execution.

Suspend, Resume, Wait, Signal.

4 Interrupts Interrupt-Handling Programs: Process saves current context.

Invode, Mask, Unmask, Retry

3 Procedures Procedures, Call-Stack, Display: Concept of procedure and call/return ops.

Mark, Stack, Call, Return

2 Instruction Set Evaluation Stack, Microprogram, Interpreter, Scalar,

Local, store, add, sbutract, branch

1 Electronics Circuits

Register, Gates, Buses, … Clear, transfer, activation,Complemnt

SILICON VALLEY UNIVERSITY CONFIDENTIAL 22

Operating System Structures Development of Operating System Evolution of Operating System Structure and Capabilities Design Elements creating change in nature of Operating System:

Hardware Arena: Multi-processor Systems, Increased Processor Speeds, High-Speed Networking, Increased size of Memory Storage Devices.

Application Arena: Multimedia Applications, Internet and Web Access, Client/Server Computing.

Security: Increased threats and attacks with viruses, worms, hacking New ways of Organizing the Operating System:

MicroKernel Architecture: Assigns few essential functions to Kernel (Address Spaces, IPC, Scheduling). Other OS Services are User mode processes, decoupled from Kernel mode.

Multithreading: Process becomes collection of threads, for concurrent operation.

Symmetric Multiprocessing: Operating System of an SMP schedules processes or threads across all of the processors.

Distributed Operating Systems: Single system for a cluster of separate Computer Systems (Illusion of unified memory and file system).

Object-Oriented Design: Modularization to the Kernel, allows customization without disrupting system integrity.

Copyright @ 2009 Pearson Education, Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 23

Operating System Structures Evolution of Operating System Structure and Capabilities (Cont) Microkernel Condensed kernel, all nonessential components of the kernel moved

to user space. Many Operating System services now in user space.

Kernel supports process and memory management. User programs communicates with Operating System services ( in

user space ) using message passing through the microkernel. Operating Systems:

Carnegie Mellon MACH Kernel: DEC UNIX, MAC OS X. QNX: Real-time Operating System. Windows NT partially microkernel. Windows XP initial design was microkernel before becoming monolithic.

Benefits: Operating System extension by adding new services in user space. Porting microkernel to another platform simplier. More security and reliability because Operating System services are in user space

(i.e. service failure in user space will not crash microkernel). Problems:

Performance degradation caused by message passing.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 24

Operating System Structures Evolution of Operating System Structure and Capabilities (Cont)

www.wikihow.com

SILICON VALLEY UNIVERSITY CONFIDENTIAL 25

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) Modular Kernel

Core Component: Links in additional modules during boot time or run time.

Dynamic Loadable Modules for: Device and Bus Drivers for specific hardware. Drivers for different file systems.

Similar to Layered System Kernel sections has protected interfaces. Modules not restricted to calling only layer below interfaces.

Similar to Microkernel Core function with other modules loaded

dynamically as needed. Microkernel requires message passing,

loadable modules does not need to use message passing.

Apple Mac OS X hybrid Layered System with MACH Microkernel

as one layer.

Copyright @ 2009 John Wiley & Sons Inc.

Application Environments and Common Services

MBSD Operatng System

Mach Operating SystemKernel Environment

SILICON VALLEY UNIVERSITY CONFIDENTIAL 26

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) Virtual Machines – Layered Approach

Hardware abstraction of the CPU, memory, disk into separate execution environment.

Each separate execution environment appear as one computer system.

Benefit Run several execution environment ( Virtual Machines ), but share the

same hardware. Resource optimization. Light resource systems can be combined with other

light resource systems to share resources on one computer system. Data Center System consolidation. Do not need a computer system for each environment.

Host computer system is protected from the Virtual Machines. Virtual Machines are protected from other Virtual Machines. Ideal Operatidng system research and development.

Crash of Virtual Machine will not crash the host Operating System or other Virtual Machines.

System development occur along with normal host system operation, dedicated downtime for system development not needed.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 27

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) Virtual Machines

Copyright @ 2009 John Wiley & Sons Inc.

Processes

Kernel

Hardware

Processes

Kernel

Hardware

VM1 VM2

Processes

Kernel

Hardware

Processes

Kernel

Hardware

VM3

Virtual MachineImplementation

Hardware

ProgrammingInterface

SILICON VALLEY UNIVERSITY CONFIDENTIAL 28

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) Virtual Machines Implementation Concepts

Virtual User Mode and Virtual Kernel Mode switching handled by Virtual Machine Monitor ( VMM ).

Virtualization require hardware support in CPU. Intel Vitualization Technology ( VT ) has extra instruction set ( Virtual

Machine Extensions ). Extended Page Tables ( EPT ) allows each Virtual Machine to have its own

Page Table. AMD Virtualization Technology.

VMWare Workstation commercial application that abstracts Intel X86 and compatible hardware into isolated Virtual Machine. Runs as an application under host operating systems of Windows or

Linux. Virtualization Layer: Abstracts physical hardware into Virtual Machines

running as guest operating systems ( virtual CPU, memory, disk drives, network interfaces ),

Copyright @ 2009 John Wiley & Sons Inc.

Virtualization Layer

SILICON VALLEY UNIVERSITY CONFIDENTIAL 29

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) VMware

Copyright @ 2009 John Wiley & Sons Inc.

Guest Operating System(free BSD)Virtual CPUVirtual MemoryVirtual Devices

Guest Operating System(Windows NT)Virtual CPUVirtual MemoryVirtual Devices

Guest Operating System(Windows XP)Virtual CPUVirtual MemoryVirtual Devices

Host Operating System( Linux )

Application Application ApplicationApplication

Hardware

CPU Memory I/O Devices

SILICON VALLEY UNIVERSITY CONFIDENTIAL 30

Operating System Structures

Evolution of Operating System Structure and Capabilities (Cont) Java Virtual Machines ( JVM ) Specification for an abstract computer

JVM on top of Host Operating System (i.e. Windows, Linux, MAC OS X) Class Loader: Loads the compiled .class files ( bytecode output ). Java Interpreter: Executes the bytecode. Just-In-Time Compiler: Bytecode from Java Compiler converted into

native machine languate. Java Interpreter does not need to interpret the bytecode.

Copyright @ 2009 John Wiley & Sons Inc.

Class Loader

Java Interpreter

Host System(Windows, Linux)

Java API .class files

Java Program .class files

SILICON VALLEY UNIVERSITY CONFIDENTIAL 31

Operating System Structures Operating System Environment Operating System provides environment for execution of

programs. View the Operating System from three aspects:

Services provided by the system. Interface made available to users and programmers. Components and their interconnections.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 32

Operating System Structures Operating System Services Services: Helpful For User:

User Interface – Command Line Interface, Batch Job Interface ( files ), Graphical User Interface ( GUI ).

Program Execution – Load program into memory, execute the program, and terminate the program normally or abnormally.

I/O Operations – User cannot control I/O directly, Operating System has to provide an interface through System Calls.

File System Manipulations – Create/Delete/Open/Read/Write files and directories.

Communications – Process communication via shared memory or though message passing.

Error Detection – Operating System must ensure correct and consistent computing,

Services: Ensuring Effective Operation of the Operating System Resource Allocation – Manages CPU cycles, main memory, file storage, for

multiple users or jobs concurrently executing. Accounting – Accumulating resource usage for accounting and system

configuration. Protection and Security – Protection ensures all access to system resources are

controlled. Security requires user authentication to gain access to system resources.

Copyright @ 2009 John Wiley & Sons Inc.

Services

SILICON VALLEY UNIVERSITY CONFIDENTIAL 33

Operating System Structures Operating System Services

Copyright @ 2009 John Wiley & Sons Inc.

User and Other System Programs

GUI Batch Command Line

User Interfaces

System Calls

ProgramExecution

I/OOperations

File System

Communication

Recourse Allocator

Accounting

ErrorDetection

Protection and Security Services

Operating System

Hardware

SILICON VALLEY UNIVERSITY CONFIDENTIAL 34

Operating System Structures User Operating System Interface Command Interpreter

Special Program initiated when user logs on ( interactive systems) or when a job is initiated.

UNIX / Linux multiple commands interpreters ( Bourne shell, C shell, Bourne-Again shell, Korn shell ).

Execute commands by: Command Interpreter contains code to execute the command. Command Interpreter implements most commands through system

programs. Command identifies a file or script to be loaded into memory and execute.

Graphical User Interface ( GUI ) Mouse-based window-and-pulldown menu system. Images or icons on the screen represents program, files, directories and system

functions. Supported by all Operating Systems:

Apple Computer - MAC OS Microsoft – Windows UNIX / Linux – X-Windows systems, K Desktop Environment (KDE),

GNOME Desktop

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 35

Operating System Structures Operating System Interface: System Calls

Interface to the services made available by an Operating System. Application Programming Interface ( API )

API ( specifies a set of functions ) used by application programs to make System Calls: User does not know how system call implemented.

APIs available to application programmers: Win32 API for Windows system. POSIX API for POSIX-based systems ( UNIX, Linux, MAC OS X ). Java API for programs running on the Java Virtual Machine.

How System Calls are used: Copy “source” to “destination” file.

Copyright @ 2009 John Wiley & Sons Inc.

Source File Destination FileAcquire input file name. Write prompt to screen. Accept Input.Acquire output file name. Write prompt to screen. Accept input.Open input file.Create output file.Read input file.Write output file.Close output file.Write completion message to screen.Terminate normally.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 36Summer 2015

Operating System Structures Operating System Interface: System Calls

strace : Monitors system calls and signals of executable.sau@buildbed-vm:~/class3> strace -c ls file1file1% time seconds usecs/call calls errors syscall------ ----------- ----------- --------- --------- ----------------100.00 0.000054 5 12 read 0.00 0.000000 0 1 write 0.00 0.000000 0 38 13 open 0.00 0.000000 0 27 close 0.00 0.000000 0 1 execve 0.00 0.000000 0 1 1 access 0.00 0.000000 0 3 brk 0.00 0.000000 0 2 ioctl 0.00 0.000000 0 4 munmap 0.00 0.000000 0 1 uname 0.00 0.000000 0 10 mprotect 0.00 0.000000 0 2 rt_sigaction 0.00 0.000000 0 1 rt_sigprocmask 0.00 0.000000 0 1 getrlimit 0.00 0.000000 0 39 mmap2 0.00 0.000000 0 1 stat64 0.00 0.000000 0 1 lstat64 0.00 0.000000 0 26 fstat64 0.00 0.000000 0 3 1 futex . . .------ ----------- ----------- --------- --------- ----------------100.00 0.000054 186 15 totalsau@buildbed-vm:~/class3>

SILICON VALLEY UNIVERSITY CONFIDENTIAL 37Summer 2015

Operating System Structures Operating System Interface: System Calls

System Call – Explicit request to the kernel made through a software interrupt.

Service provided in the kernel, cross the user-space / kernel boundary.

Linux C library – Provides the wrapper routines to issue a system call.

main() {

xyz()

}

User Application

xyz() {

“SYSCALL”

}

Linux C library

Wrapper routine

User Mode

system_call()

sys_call_table[] -> sys_xyz()

“SYSEXIT”

sys_xyz() {

}

System Call Handler System Call Service Routine

Load arguments:

1) Register eax = system call index.

2) Software Interrupt (Interrupt 0x80).

Kernel Mode

SILICON VALLEY UNIVERSITY CONFIDENTIAL 38

Operating System Structures Operating System Interface: System Calls C Library using System Calls

Copyright @ 2009 John Wiley & Sons Inc.

#include <stdio.h>int main ( ){. . .printf ( “Greetings” );. . .return 0;}

Standard C LibraryUser Mode

Kernel Mode

write ( )

write ( )System Call

C Library intercepts “printf” and invokes the System Call (s) in the Operating System.

C program invokes the printf( ) statement.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 39

Operating System Structures Operating System Interface: System Calls Three Methods to pass Parameters:

Registers – Limited in number of parameters. Address Pointer – Address of a structure containing number of parameters. Stack – Pushed onto call stack by program.

Copyright @ 2009 John Wiley & Sons Inc.

X: Memory block containing parameters for call.

1) Load address X System call – Index associated with the System call.

2) System call Index ‘n’.

Address of memory block X.

Register

Use parameter from Register (Memory block X).

n

Address of system function for system call.

System Call Table

System call ‘n’ Function

Operating SystemUser Program

SILICON VALLEY UNIVERSITY CONFIDENTIAL 40

Operating System Structures Operating System Interface: System Calls Grouped into Six Categories

Process Control File Manipulation Device Manipulation Information Maintenance Communications

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 41

Operating System Structures Operating System Interface: System Calls Types of System Calls Process Control

End, Abort Abnormal termination, memory dump can be taken. Control transferred to Command Interpreter.

Load, Execute Make System Call to load and execute another program. Command Interpreter does this either the command line, GUI, or batch

command. Create Process, Terminate Process

Create parallel processes. Get Process Attributes, Set Process Attributes

Control attributes of created processes. Wait for Time

Process waiting to synchronize with other processes. Wait Event, Signal Event

Process waiting for an event and signalling event ( block shared data and releasing blocked share data ).

Allocate and Free Memory Memory resources used while process is running.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 42

Operating System Structures Types of System Calls File Manipulation

Create, Delete File. Open, Close File. Read, Write, Reposition File. Get File Attributes, Set File Attributes.

Device Manipulation Request Device, Release Device. Read, Write, Reposition. Get Device Attributes, Set Device Attributes. Logically Attach or Detach Devices.

Information Maintenance Get Time or Date, Set Time or Date. Get System Date, Set System Date. Get Process, File, or Device Attributes. Set Process, File, or Device Attributes.

Communications Create, Delete Communication Connection. Send, Receive Messages. Transfer Status Information. Attach or Detach Remote Devices,.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 43

Operating System Structures Windows and UNIX System Calls

Copyright @ 2009 John Wiley & Sons Inc.

Types of System Calls Windows UNIX

Process Control CreateProcess() fork()

ExitProcess() exit()

WaitForSingleObject()

wait()

File Manipulation CreateFile() open()

ReadFile() read()

WriteFile() write()

CloseHandle() close()

Device Manipulation SetConsoleMode() ioctl()

ReadConsole() read()

WriteConsole() write()

SILICON VALLEY UNIVERSITY CONFIDENTIAL 44

Operating System Structures Windows and UNIX System Calls

Copyright @ 2009 John Wiley & Sons Inc.

Types of System Calls Windows UNIX

Information Maintenance

GetCurrentProcessID() getpid()

SetTimer() alarm()

Sleep() sleep()

Communication CreatePipe() pipe()

CreateFileMapping() shmget()

MapViewOfFile() mmap()

Protection SetFileSecurity() chmod()

InitializeSecurityDescriptor()

umask()

SetSecurityDescriptorGroup()

chown()

Types of System Calls Process and Job Control

Single Tasking System – MS DOS Multi-Tasking System - UNIX

Kernel

Command Interpreter

Process A

Process B

Free Memory

SILICON VALLEY UNIVERSITY CONFIDENTIAL 45

Operating System Structures

Copyright @ 2009 John Wiley & Sons Inc.

Command Interpreter

Kernel

Command Interpreter

Free Memory

Kernel

Process

Free Memory

Loads program by overwritting most of Command Interpreter. Only process running.

Creates new process. Command Interpreter and process running.

MS-DOS

fork( ), PID = A

exec( )

fork( ), PID = B

exec( )

UNIX

SILICON VALLEY UNIVERSITY CONFIDENTIAL 46

Operating System Structures Types of System Calls File Management

Create and Delete Files or Directories File name and attributes.

Open / Read / Write / Reposition / Close Files Get / Set File Attributes

Device Management Physical Devices – Disk Drives, CD Drives Abstract or Virtual Devices – Files Device Management functions similar to File Management functions. Operating System combined into file-device structure. UNIX abstracts all devices to files (i.e. Mouse, Keyboard, Console, I/O Devices).

Information Maintenance Transferring info between user and Operating System (i.e. time, date, version,

number of current users, amount of free memory, amount of disk space, etc.). Debugging (i.e. strace program shows all system calls). Access process information (i.e. get process attributes or set process attributes).

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 47

Operating System Structures Types of System Calls Communication

Interprocess Message-Passing Model Connection setup between two processes in the same Computer System or

between two Computer Systems. Process name or Process Identifier (PID) Host name and Network Identifier ( IP address of remote host ).

Client – Server Model: Server is the receiving process waiting for a connecttion from the client process.

Interprocess Shared-Memory Model Processes “agree” to share memory owned by multiple processes. Structure of the memory area is determined by the process, not by Operating

System. Memory synchronization the responsibiilty of processess accessing the

shared memory. Protection

Protection provides mechanism for controlling Computer System’s resources. System calls allows set permission and get permission of resources ( i.e. files

and disks ). System calls to allow and deny user access to resources.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 48

Operating System Structures

System Programs System utilities provide environment to users for development and execution

of application programs. Some System Utilities are user interface to System Calls.

Categories of System Utilities: File Management: Programs to create, delete, copy, rename, print, dump, list and

manipulate files and directories (cp, rm, mv, mkdir). Status Information: Programs to return date, time, amount of available memory or

disk space, performance, logging information (date, df, iostat) File Modification: Text editors and programs for searching and modify text in the

file. Programming-Language support: Programs for development, i.e. compilers ,

assemblers, debuggers, interpreters for programming languages. Program Loading and Execution: Programs to load user applications for execution,

i.e. loaders. Communications: Programs to create a virtual connection between processes and

between computer systems, i.e. Web Browser, email. Application Programs for solving common problems:

Web Browsers, Word Processors, Spreadsheets, DataBase Systems, Compilers, Games (vi, emacs, gcc).

User impression and views of the Operating System usually seen through the System Utilities and Application Programs.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 49

Operating System Structures

Operating System Generation: Options: Number/Size of Buffers, type of CPU-scheduling algorithm, maximum

number of processes, target processor, network stack, type of drivers (MTD, I2C), type of file system (EXT2, EXT3, JFS).

System Boot Locates Kernel in firmware, loads into main memory, starts init process.

Firmware ( ROM ) Run diagnostics. Initialize CPU registers, device controllers, and contents of memory system. Operating System in ROM.

General Purpose Operating Systems Firmware runs diagnostics. Operating System in Disk. Loads boot block ( block zero ) from disk. Loads remainder of bootstrap

program. GRUB (GNU Grand Unified Bootloader): Bootstrap program for Linux

systems. Selects different Kernels or Initial RAM disks.

Copyright @ 2009 John Wiley & Sons Inc.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 50Summer 2015

Operating System Structures Linux In Desktop PC

During powerup, BIOS in host (X86 system) access the hard drive Master Boot Record.

In MBR is GRUB, Linux bootloader in Linux distributions. GRUB provides choice to boot one of multiple OS (i.e. Linux or Windows).

/boot/grub/grub.conf contains GRUB configuration file with menu selection (i.e. which OS) and disk partition containing Linux Kernel and the root file system.

GRUB loads Linux Kernel from /boot directory ( contains Linux Kernel(s), Kernel System Map(s), initrd (initial Ramdisk with drivers), Kernel config file(s) from Kernel build ).

Initrd is temporary root file system with executables (i.e. insmod) and drivers to mount the root file system on disk. After mounting, initrd is unmounted and memory freed.

NOTE: In embedded Linux systems, initrd is the final root file system.

Linux Kernel starts init process. Init process is the root/parent process of all other process executing on Linux.

Init process runs script, /etc/rc.d/rc.sysinit. Init process runs script, /etc/inittab, to execute scripts to start processes

based on the runlevel.

SILICON VALLEY UNIVERSITY CONFIDENTIAL 51Summer 2015

Operating System Structures Summary: Goals for Designing an Operating System

Viewpoints from the User and the System Services provided by the Operating System:

User Application Usage ( provide I/O interface, inter-process communication ) and

Operation of the system ( protection and security for system resources, resource allocation ).

User Operating System Interface: Command Interpreter (Linux shells). Graphical User Interface (Microsoft Windows, Linux X-Windows).

System Calls Application Level Process Control, File and Device Manipulation. System Programs providing environment for program development and

execution. Structure of the Operating System

Layered Approach (UNIX/Linux) Modularity ( Monolithic Kernel, Microkernel, Virtual Machines ).

Separate Policy Decisions from Implementation Details Change in Policy does not change the mechanism.

Operating System Generation System Boot: Bootstrap Loader