64
18 September 2008 CIS 340 # 1 Operating System Control program for the execution of application programs An interface between applications and hardware An intermediary between a user of a computer and the computer hardware

18 September 2008CIS 340 # 1 Operating System Control program for the execution of application programs An interface between applications and hardware

Embed Size (px)

Citation preview

18 September 2008 CIS 340# 1

Operating System

• Control program for the execution of application programs

• An interface between applications and hardware

• An intermediary between a user of a computer and the computer hardware

# 2

Operating System Objectives• Convenience

– Makes the computer more convenient to use• Efficiency

– Allows computer system resources to be used in an efficient manner

• Ability to evolve– Permit effective development, testing, and

introduction of new system functions without interfering with service

18 September 2008 CIS 340# 3

Layers of Computer System

# 4

Services Provided by the Operating System

• Program development– Editors and debuggers

• Program execution• Access to I/O devices• Controlled access to files• System access

# 5

Services Provided by the Operating System

• Error detection and response– Internal and external hardware errors

• Memory error• Device failure

– Software errors• Arithmetic overflow• Access forbidden memory locations

– Operating system cannot grant request of application

# 6

Services Provided by the Operating System

• Accounting– Collect usage statistics– Monitor performance– Used to anticipate future enhancements– Used for billing purposes

18 September 2008 CIS 340# 7

Operating System: Other Services• Allows multiple, concurrent computations

– Allows through enabling resources allocation

• Controls interactions between concurrent computations– Enforces rules to securely execute the

computations without losing integrity

• Supports interactions of computations among different computer systems– Handles networking interactions

18 September 2008 CIS 340# 8

Operating System Definitions

Resource allocator – Manages and allocates resources

Control program – Controls the execution of user programs– Controls operations of I/O devices

Kernel – Portion of operating system running at all times in main memory– All and anything else being application programs– Contains most frequently used functions– Also called the nucleus

9

18 September 2008 CIS 340# 10

Migration of OS Concepts and Features through Platforms

Batch

TIME SHARE

18 September 2008 CIS 340# 11

Computer-System Architecture

1. Control Unit

2. Arithmetic / Logic Unit

3. Memory

18 September 2008 CIS 340# 12

Hardware FeaturesHW realization supporting OS services

• Memory protection– Do not allow the memory area containing the

monitor to be altered– User program executes in user mode

• Certain instructions may not be executed– Monitor executes in system mode

• Kernel mode• Privileged instructions are executed• Protected areas of memory may be

accessed

18 September 2008 CIS 340# 13

Hardware FeaturesHW realization supporting OS services

• Timer– Prevents a job from monopolizing the system

• Privileged instructions– Certain machine level instructions to be

executed only by the monitor• Interrupts

– Early computer models did not have this capability

18 September 2008 CIS 340# 14

Computer-System Operation: Premises

• I/O devices and the CPU can execute concurrently

• Each device controller handles a particular device type

• Each device controller has a local buffer• CPU moves data from/to main memory

to/from local buffers• I/O is from the device to local buffer of

controller• Interrupt generated by device controller

informs CPU about end of controller’s task

18 September 2008 CIS 340# 15

Interrupts: Expectations• Transfers control to the interrupt service

routine • Interrupt vector contains the addresses of all

the service routines• Interrupt architecture saves the address of the

interrupted instruction• A trap is a software-generated interrupt

caused either by an error or a user request.• An operating system is interrupt driven

Def:

Interrupt service routine (ISR)• An interrupt handler,

– also known as an interrupt service routine (ISR), – is a callback subroutine in an operating system or 

device driver – whose execution is triggered by the reception of an interrupt.– have a multitude of functions, which vary based on the

reason the interrupt was generated and the speed at which the interrupt handler completes its task.

• An interrupt handler is a low-level counterpart of event handlers. – These handlers are initiated by either hardware interrupts or

interrupt instructions in software, – used for servicing hardware devices and transitions between

protected modes of operation such as system calls.

18 September 2008 CIS 340# 16

Interrupt vector• In computing, an interrupt vector is

– the memory address of an interrupt handler, – or an index into an array called an

interrupt vector table or dispatch table containing the memory addresses of interrupt handlers.

• When an interrupt is generated,– the processor saves its execution state via a 

context switch, and– begins execution of the interrupt handler at the

interrupt vector.

18 September 2008 CIS 340# 17

18 September 2008 CIS 340# 18

I/O Devices Sloooooooooooow

EX: System Utilization:

18 September 2008 CIS 340# 19

EX: UniprogrammingProcessor must

wait for I/O instruction to

complete before preceding

Processor must wait for I/O

instruction to complete before

preceding

18 September 2008 CIS 340# 20

EX: Multiprogrammingwith Three Programs

Processor experiences less

lapses

18 September 2008 CIS 340# 21

CONSIDER: Utilization Histograms

18 September 2008 CIS 340# 22

EX: Sample Program Execution Attributes

18 September 2008 CIS 340# 23

EX: Typical I/O Rates for Devices

# 24

Process

• Consists of three components–An executable program–Associated data needed by the

program–Execution context of the program

• All information the operating system needs to manage the process

# 25

Process

# 26

Memory Management

• Process isolation• Automatic allocation and management• Support of modular programming• Protection and access control• Long-term storage

# 27

Virtual Memory

• Allows programmers to address memory from a logical point of view

• No hiatus between the execution of successive processes while one process was written out to secondary store and the successor proceess was read in

# 28

Virtual Memory and File System• Implements long-term store• Information stored in named objects

called files

# 29

Paging

• Allows process to be comprised of a number of fixed-size blocks, called pages

• Virtual address is a page number and an offset within the page

• Each page may be located any where in main memory

• Real address or physical address in main memory

# 30

Virtual Memory

# 31

Virtual Memory Addressing

18 September 2008 CIS 340# 32

18 September 2008 CIS 340# 33

OS Key Elements

18 September 2008 CIS 340# 34

Problems Arising with System Software

1. Improper synchronization– Ensure a process waiting for an

I/O device receives the signal

2. Failed mutual exclusion– Memory overwrites

3. Nondeterminate program operation– Program A should only depend on

input to it– Activities of other programs

should not influence Program A’s outcome

4. Deadlocks

18 September 2008 CIS 340# 35

System Structure

• A series of levels– Each level performs a related subset of

functions– Each level relies on the next lower level to

perform more primitive functions

LEVELS(1-4) Process Hardware Levels

(5-7) Concepts with Multiprogramming (8-13) Deal with External Objects

18 September 2008 CIS 340# 36

Process Hardware Levels

• Level 1– Electronic circuits– Objects are registers, memory cells, and logic

gates– Operations are clearing a register or reading a

memory location

• Level 2– Processor’s instruction set– Operations such as add, subtract, load, and store

• Level 3– Adds the concept of a procedure or subroutine,

plus call/return operations

• Level 4– Interrupts

18 September 2008 CIS 340# 37

Concepts with Multiprogramming

• Level 5– Process as a program in execution– Suspend and resume processes

• Level 6– Secondary storage devices– Transfer of blocks of data

• Level 7– Creates logical address space for

processes– Organizes virtual address space

into blocks

18 September 2008 CIS 340# 38

Deal with External Objects (p 1 / 2)

• Level 8– Communication of information and

messages between processes• Level 9

– Supports long-term storage of named files

• Level 10– Provides access to external

devices using standardized interfaces

18 September 2008 CIS 340# 39

Deal with External Objects (p 2 / 2)

• Level 11– Maintains the association

between the external and internal identifiers

• Level 12– Provides full-featured facility for

the support of processes• Level 13

– Provides an interface to the operating system for the user

18 September 2008 CIS 340# 40

Modern Operating Systems: Concepts

• Microkernel architecture• Multithreading• Symmetric multiprocessing

(SMP)

# 41

Modern Operating Systems

• Distributed operating systems–Provides the illusion of a single

main memory space and single secondary memory space

# 42

Modern Operating Systems

• Object-oriented design–Used for adding modular extensions

to a small kernel–Enables programmers to customize

an operating system without disrupting system integrity

# 43

Windows Architecture

• Modular structure for flexibility• Executes on a variety of hardware

platforms• Supports application written for other

operating system

44

# 45

Operating System Organization• Modified microkernel architecture

– Not a pure microkernel – Many system functions outside of the

microkernel run in kernel mode• Any module can be removed, upgraded, or

replaced without rewriting the entire system

# 46

Kernel-Mode Components• Executive

– Contains base operating system services• Memory management• Process and thread management• Security• I/O• Interprocess communication

• Kernel– Consists of the most used components

# 47

Kernel-Mode Components• Hardware abstraction layer (HAL)

– Isolates the operating system from platform-specific hardware differences

• Device drivers– Translate user I/O function calls into specific

hardware device I/O requests• Windowing and graphics systems

– Implements the graphical user interface (GUI)

# 48

Windows Executive• I/O manager• Cache manager• Object manager• Plug and play manager• Power manager• Security reference monitor• Virtual memory manager• Process/thread manager• Configuration manager• Local procedure call (LPC) facility

# 49

User-Mode Processes

• Special system support processes–Ex: logon process and the session

manager• Service processes• Environment subsystems• User applications

# 50

Client/Server Model• Simplifies the Executive

– Possible to construct a variety of APIs• Improves reliability

– Each service runs on a separate process with its own partition of memory

– Clients cannot not directly access hardware• Provides a uniform means for applications to

communicate via LPC• Provides base for distributed computing

# 51

Threads and SMP

• Operating system routines can run on any available processor

• Different routines can execute simultaneously on different processors

• Multiple threads of execution within a single process may execute on different processors simultaneously

• Server processes may use multiple threads• Share data and resources between process

# 52

Windows Objects• Encapsulation

– Object consists of one or more data items and one or more procedures

• Object class or instance– Create specified instances of an object

• Inheritance– Support to some extent in the Executive

• Polymorphism

# 53

UNIX

• Hardware is surrounded by the operating system software

• Operating system is called the system kernel

• Comes with a number of user services and interfaces–Shell–Components of the C compiler

# 54

UNIX

System call• Is how a program requests a service from an operating system's 

kernel that it does not normally have permission to run. • Provide the interface between a process and the operating system. • Most operations interacting with the system require permissions not

available to a user level process requires the use of system calls.– e.g. I/O performed with a device present on the system, – or any form of communication with other processes

• On Unix, Unix-like and other POSIX-compatible operating systems, popular system calls – open, read, write, close,wait, execve, fork, exit, and kill.

• Many of today's operating systems have hundreds of system calls. – For example,Linux has over 300 different calls, FreeBSD has

over 500[1], while Plan 9 has 51.

18 September 2008 CIS 340# 55

System calls 5 categories• Process Control.

– load– execute– create process– terminate process– get/set process attributes– wait for time, wait event, 

signal event– allocate, free memory

• File management.– create file, delete file– open, close– read, write, reposition– get/set file attributes

• Device Management.– request device, release device– read, write, reposition– get/set device attributes– logically attach or detach devices

• 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– transfer status information– attach or detach remote devices

18 September 2008 CIS 340# 56

# 57

UNIX Kernel

# 58

Modern UNIX Kernel

# 59

Modern UNIX Systems

• System V Release 4 (SVR4)• Solaris 9• 4.4BSD• Linux

18 September 2008 CIS 340# 61

Transactional Properties:

ACID Test

A tomicity: If several components must come together for a process, then each

atomic process operates correctly or entire combination

aborts

C onsistency: A service is correct when

executed in its entirety and false or incorrect data is not

introduced into the component databases

I solation: If several clients request the

same service at the same time and access the same data, the

overall result will be as if they were alone – isolated -- in the

system

D urability: Completed transactions are complete

and durable (have duration?)If necessary, redoing and undoing of changes in case of failures can

occur

TP-Monitor

transactional coordination

CLIENT

services

Application 1 Application 3Application 2

user program

CLIENT

SERVER

18 September 2008 CIS 340# 62

Simple Batch Systems“Monitors”

• Software • Controlled sequence of events• Program branches back to monitor when

finished

Job Control Language (JCL)• Special type of programming language• Provides instruction to the monitor

– What compiler to use?– What data to use?

18 September 2008 CIS 340# 63

Time Sharing

• Uses multiprogramming to handle multiple interactive jobs

• Processor’s time is shared among multiple users

• Multiple users simultaneously access the system through terminals

18 September 2008 CIS 340# 64

EX: Multiprogramming and Multiprocessing