1 introduction to operating systems.pptwebpages.iust.ac.ir/hsalimi/courses/87-88-2/os/slides/session...

28
Operating Systems Hadi Salimi Computer Engineering Department Iran University of Science and Technology Tehran, Iran [email protected] Spring 2009 Course motivation and goals Course motivation and goals Programming computer hardware directly is difficult Operating systems provide a layer Operating systems provide a layer between applications and computer h d (VM) hardware (VM) Understanding operating system concepts is essential to many advanced programming tasks 2 advanced programming tasks

Upload: duongdien

Post on 06-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Operating Systems

Hadi SalimiComputer Engineering Department

Iran University of Science and Technologyy gyTehran, Iran

[email protected] 2009

Course motivation and goalsCourse motivation and goals

Programming computer hardware g g pdirectly is difficultOperating systems provide a layerOperating systems provide a layer between applications and computer h d (VM)hardware (VM)Understanding operating system concepts is essential to many advanced programming tasks

2

advanced programming tasks

Class outlineClass outline

Introduction and OverviewIntroduction and OverviewProcesses and threadsOperating system structuresOperating system structuresMemory managementSchedulingSchedulingInput/OutputFile SystemsySecurity

3

TextbookTextbook

Andrew S. Tanenbaum. “Operating Systems design and implementation”, 3nd ed., Prentice Hall, 2006.Abraham Silberschatz, Galvin, and Gagne. “OperatingAbraham Silberschatz, Galvin, and Gagne. Operating Systems Concepts”, 7nd ed., John Wiley and Sons, 2005Willi St lli “O ti S t ” 4 d dWilliam Stallings. “Operating Systems”, 4nd ed., Prentice Hall, 2001.Andrew S. Tanenbaum. “Modern Operating Systems”, p g y ,2nd ed., Prentice Hall, 2001.

4

Overview:Overview:

What is an operating system?Operating systems historyThe zoo of modern operating systemsReview of computer hardwareOperating system conceptsSystem callsOperating system structure

U i t f t th ti tUser interface to the operating systemAnatomy of a system call

5

Samples of Operating SystemsSamples of Operating Systems

IBSYS (IBM 7090)OS/360 (IBM 360)

MACHOS/360 (IBM 360)TSS/360 (360 mod 67)Michigan Terminal

Apollo DOMAINUnix (System V & BSD)Apple Mac (v 1– v 9)

SystemCP/CMS & VM 370MULTICS (GE 645)

Apple Mac (v. 1 v. 9)MS-DOSWindows NT, 2000, XP( )

Alto (Xerox PARC)Pilot (Xerox STAR)CP/M

Novell NetwareLinuxFreeBSDCP/M

IRIXSolaris

FreeBSDPalmOSPocketPC

6

MVSVxWorks

VxWorks

Samples of Operating Systems (continue )Samples of Operating Systems (continue…)

7

What is an Operating System?What is an Operating System?

An Operating System is a program that acts as an intermediary/interface between a user of a computer and the computer hardware.

It is an extended machineHides the messy details which must be performedHides the messy details which must be performedPresents user with a virtual machine, easier to use

It is a resource managerEach program gets time with the resource

8

Each program gets space on the resource

The Operating System controls the machinecontrols the machine

Compiler Debugger

User

Application

OS Kernel

Hard

VideoGame

Application

Operating System

wareEditor App.

Hardware…Terminal

emulator

Browser

9

Static View of System Components

User 1 User 2 User 3 User 4 User n…

Compiler Editor Database Calculator WP

Operating SystemOperating System

Hardware

10

Dynamic View of System ComponentsDynamic View of System Components

11

L f C t S tLayers of a Computer System

EndUser

Programmer

ApplicationPrograms

Operating-System

Designer

O e ti S te

Utilities

Computer Hardware

Operating-System

12

History of Operating SystemsHistory of Operating Systems

First generation: 1945 – 1955V b Pl b dVacuum tubes, Plug boards

Second generation: 1955 – 1965Transistors, Batch systems

Third generation: 1965 – 1980Integrated circuits, Multiprogramming

Fourth generation: 1980 – presentFourth generation: 1980 – presentLarge scale integration, Personal computers

Next generation: ???Next generation: ???Systems connected by high-speed networks?Wid t?

13

Wide area resource management?

First generation: direct inputFirst generation: direct input

Run one job at a timeEnter it into the computer (might require rewiring!)Run itRecord the resultsRecord the results

Problem: lots of wasted computer time!Computer was idle during first and last stepsComputer was idle during first and last stepsComputers were very expensive!

Goal: make better use of an expensive commodity: computer time

14

Second generation: batch systemsSecond generation: batch systems

Bring cards to 1401Read cards onto input tapePut input tape on 7094Perform the computation, writing results to output tapePut output tape on 1401 which prints output

15

Put output tape on 1401, which prints output

Structure of a typical 2nd generation jobStructure of a typical 2nd generation job

$ENDData forprogram

$RUN

$LOADFORTRANprogram

$FORTRAN

$JOB, 10,6610802, JANE DOE

16

Third generation: multiprogrammingThird generation: multiprogramming

Multiple jobs in memoryP d fProtected from one another

Operating system Job 3

protected from each job as wellResources (timeJob 1

Job 2Memory

Operating

Resources (time, hardware) split between jobsStill t i t ti

Job 1partitions

Operatingsystem

Still not interactiveUser submits jobComputer runs it

17

User gets results minutes (hours, days) later

Multi taskingMulti tasking

Job 1

Op

erat

Main C

Task 1

Task 2

Job 2

Job 3

ing

System

n M

emo

ry

CP

U

Resource utilizationResource utilizationMultiprogramming, multitasking, and multiple users.Time sharing.

18

Response time.

TimesharingTimesharing

Multiprogramming allowed several jobs to be active at one time

Initially used for batch systemsCheaper hardware terminals interactive useCheaper hardware terminals → interactive use

Computer use got much cheaper and easierNo more “priesthood”No more priesthoodQuick turnaround meant quick fixes for problems

19

Types of modern operating systemsTypes of modern operating systems

Mainframe operating systems: MVSServer operating systems: FreeBSD, SolarisMultiprocessor operating systems: Cellular IRIXPersonal computer operating systems: XP, LinuxPDA operating systems: PalmOS, PocketPCReal-time/embedded operating systems: VxWorks, QNXSmart card operating s stemsSmart card operating systems

⇒Some operating systems can fit into more than one category

20

category

Computer Hardware ReviewComputer Hardware Review

Computer block diagramp gComponents of a simple personal computercomputerCPU internalsMemorMemoryStorage pyramidDisk drive structureAnatomy of a device request

21

y qStructure of a large Pentium system

Control UnitInput Unit Output Unit

Computer

CPUMonitorPrinterALU

Control UnitKeyboardMouseScanner

Input Unit Output Unit

CPU

Registers Bank

ModemModem

Cache Memory

Main Memory ROMRAM

MemorySecondary MemoryHD FD CD Flash

22

Tertiary MemoryTape

Computer Components: Top-Level Viewp p p

MAR - Memory Address Register

address for next read or write

MBR - Memory Buffer Register

data to be written into memorydata to be written into memory

receives data read from memory

I/OAR - I/O Address

specifies a particular I/O device

I/OBR - I/O Buffer

exchange of data between an I/Oexchange of data between an I/O module and the processor

23

Components of a simple personal computerComponents of a simple personal computer

OutsideOutsideworld

Hard drivecontroller

Videocontroller

USBcontroller

Networkcontrollercontrollercontroller controller controller

CPU Computer internals(inside the “box”)

24

Memory( )

CPU internals

Execute

CPU internals

ExecuteunitFetch

unitDecode

unit

Executeunit

Executeunit

Holding buffer

Fetchunit

Decodeunit

Executeunit

Fetchunit

Decodeunit

(a) A three-stage Pipelined CPU (b) A Superscalar CPU

25

MemoryMemory

Address

0x0002ffff

Address

0x0002ffffUser 2 program

and data

0x00027fff

0x0002b000

0x0002ffff

Limit

User 2 data

User 1 dataLimit2

Base20x00029000

0x0002bfff

0x0002ffff

0x0002d000

User 1 programand data

0x0001dfff

0x00023000

0x00027fff

Base

Limit

User programBase1

Limit1

2

0x0001dfff

0x00023000

0x00024fff

Operatingsystem

0x0001dfff

0x00000000

Operatingsystem

0x0001dfff

0x00000000

Single base/limit pair: set for each processT b /li it i t f f d t

26

Two base/limit registers: one for program, one for data

Storage pyramid

Access latencyCapacity

Storage pyramid

y

1 ns

2–5 ns

< 1 KB

1 MB

Registers

Cache (SRAM)

Better

50 ns

5 ms

1 GB

200 GB

( )

Main memory (DRAM)

Magnetic disk

50 sec> 1 TB Magnetic tape

Goal: really large memory with very low latency

Better

y g y y yLatencies are smaller at the top of the hierarchyCapacities are larger at the bottom of the hierarchy

Solution: move data between levels to create illusion of

27

large memory with low latency

Disk drive structureDisk drive structure

sector

headData stored on surfaces

U f sector

platter

Up to two surfaces per platterOne or more platters per di k

cylinder

platter

track

disk

Data in concentric tracksTracks broken into sectors

cylinder

surfaces

256B-1KB per sector

Cylinder: corresponding tracks on all surfaces

spindle

surfacesData read and written by heads

Actuator moves heads

28

spindleactuatorHeads move in unison

Anatomy of a device requestAnatomy of a device request

Instruction

Interruptcontroller

CPU5 Disk

controller

3 2Instructionn

Instructionn+11: Interrupt

61 4Operating

systemInterrupt handler

3: Return

Left: sequence as seen by hardwareRequest sent to controller, then to diskDisk responds signals disk controller which tells interrupt

p

2: Process interrupt

Disk responds, signals disk controller which tells interrupt controllerInterrupt controller notifies CPU

Ri ht i t t h dli ( ft i t f i )

29

Right: interrupt handling (software point of view)

Operating system ComponentsOperating system Components

Process ManagementMemory ManagementFile ManagementI/O ManagementProcess SchedulerInter Process CommunicationNetwork UnitC d I t tCommand InterpreterSecurity Management

30

ProcessesProcesses

Process: program in executionAddress space (memory) theAddress space (memory) the program can useState (registers, including program counter & stack pointer)

A

pointer)OS keeps track of all processes in a process tableProcesses can create other

B C D

processesProcess tree tracks these relationshipsA is the root of the tree

E F GA is the root of the treeA created three child processes: B, C, and DC created two child

E d F

31

processes: E and FD created one child process: G

Memory image of a Unix processMemory image of a Unix process

Processes have three t0x7fffffff segments

Text: program codeData: program data

Stack0x7fffffff

Statically declared variablesAreas allocated by malloc() or new (heap)malloc() or new (heap)

StackAutomatic variablesProcedure call informationData

Data

Address space growthText: doesn’t growData: grows “up”

Text

32

Data: grows upStack: grows “down”

0x00000000

Synchronization and deadlockSynchronization and deadlock

33

(a) A Potential deadlock (b) An Actual deadlock

Hierarchical file systemsHierarchical file systems

34

File system for a university department

MountingMounting

Before mounting, files on floppy are inaccessible

After mounting floppy on b,files on floppy are part of file hierarchy

35

files on floppy are part of file hierarchy

Inter-process communicationInter process communication

Processes may want to exchange information with each thother

Many ways to do this, includingNetworkPipe (special file): A writes into pipe, and B reads from it

Process Process

A B

Pipe

Two processes connected by a pipe

36

Two processes connected by a pipe

Types of OS structuresTypes of OS structures

Monolithic systemLayered systemVirtual machineExokernelClient/Server

37

Monolithic systemMonolithic system

MainMainprocedure

ServiceProcedures

UtilityProcedures

38

Simple structuring model for a monolithic system

Monolithic system…Monolithic system…

Applicationsns

User space

Kernel space

System call interface

Kernel space

MM = Memory Manager

PS P S h d l

MM PS IPC FS

Kernel

PS = Processor Scheduler

IPC = Inter Process Communication

MM PS IPC FS

I/O Net …

FS = File System

I/O = Input/Output manager

Net = Network manager

39

Net = Network manager

Layered systemLayered system

UserLayer 5

User ApplicationUser space Layer 4

Message Interpreter

Har

I/O ManagementKernel spaceLayer 3

Layer 2

P S h d li

Memory Management

rdware

Layer 1

Structure of the THE operating system

Process SchedulingLayer 0

40

Structure of the THE operating system

Virtual machineVirtual machine

App1 App2 App3

VM/370

CMS (VMW)

Linux

pp1 pp2 pp3

CMS (VMW) CMS (VMW)

Windows NT FreeBSDI/O instructions

System calls

Calls to simulate I/O

Bare hardware

VM/370Calls to simulate I/O

“Real” I/O instructions

First widely used in VM/370 with CMS (Conversational Monitor System)

Available today in VMwareAllows users to run any x86-based OS on top of Linux or NTAllows users to run any x86 based OS on top of Linux or NT

“Guest” OS can crash without harming underlying OSOnly virtual machine fails—rest of underlying OS is fine

“Guest” OS can even use raw hardware

41

Guest OS can even use raw hardwareVirtual machine keeps things separated

ExokernelExokernel

Same as Virtual machineAssign one virtual computer to any userAllocate sub set of resource to any virtual machine

42

Client/Server

Cli t P T i lCli t Fil M

Client/Server

Microkernel

Clientprocess

Processserver

Terminalserver

Clientprocess

Fileserver

Memoryserver

… User mode

Kernel modee e ode

Client obtains service by sending messages to server

The client-server model

Processes (clients and OS servers) don’t share memoryC i ti i i

sending messages to server processes

Communication via message-passingSeparation reduces risk of “byzantine” failures

Examples include Mach, QNX, early versions of Windows

43

NT

Client/Server…Client/Server…

Applicationsns

System call interface

User space

Process SchedulerFile System Device manager …

Micro Kernel

Kernel space

IPC

Memory Management Synchronization

44

Memory Management Synchronization

Client/Server…Client/Server…

The client-server model in a distributedThe client server model in a distributed system

45

System callsSystem calls

Programs want the OS to perform a serviceAccess a fileCreate a processOthersOthers…

Accomplished by system callProgram passes relevant information to OSProgram passes relevant information to OSOS performs the service if

The OS is able to do soThe service is permitted for this program at this timeThe service is permitted for this program at this time

OS checks information passed to make sure it’s OKDon’t want programs reading data into other programs’

!

46

memory!

System calls…System calls…

Applications ApplicationsApplications

User space

K l

Applications ApplicationsApplications

System call interface

Kernel space

MM PS IPC FSMM PS IPC FS

I/O Net …

OS Component

47

Making a system callMaking a system call

System call:d(fd b ff l th)

0xffffffffLibrary

read(fd,buffer,length)

Program pushes arguments, calls libraryReturn to caller

Trap to kernel

(read call)

Library sets up trap, calls OSOS handles system call

Trap to kernel

Trap code in registerUser

space2

3

8OS handles system callControl returns to libraryLibrary returns to user

Increment SP

Call read

Push arguments1

4 79

programThere are 9 steps in making the system call

Push arguments

DispatchSys call

Kernelspace

1

5 6

Usercode

48

making the system callDispatchy

handlerspace(OS)

0

System calls for files & directoriesSystem calls for files & directories

Call Descriptionfd = open(name how) Open a file for reading and/or writingfd = open(name,how) Open a file for reading and/or writing

s = close(fd) Close an open file

n = read(fd,buffer,size) Read data from a file into a buffer

n = write(fd,buffer,size) Write data from a buffer into a file

s = lseek(fd,offset,whence) Move the “current” pointer for a file

s = stat(name,&buffer) Get a file’s status information (in buffer)( , ) ( )

MINIX System calls

49

More system callsMore system calls

Call Descriptionpid = fork() Create a child process identical to the

parentparent

pid=waitpid(pid,&statloc,options) Wait for a child to terminate

s = execve(name,argv,environp) Replace a process’ core image

exit(status) Terminate process execution and return status

s = chdir(dirname) Change the working directory

s = chmod(name,mode) Change a file’s protection bits

s = kill(pid,signal) Send a signal to a process

seconds = time(&seconds) Get the elapsed time since 1 Jan 1970MINIX S t ll

50

( ) pMINIX System calls

A simple shellA simple shell

while (TRUE) { /* repeat forever */while (TRUE) { / repeat forever /type_prompt( ) ; /* display prompt */read_command (command, parameters); /* input from terminal */

if (fork() != 0) { /* fork off child process *//* Parent code */waitpid( -1, &status, 0); /* wait for child to exit */

} else {/* Child code */execve (command, parameters, 0); /* execute command */

}}}

51

System CallsSystem Calls

52

Some UNIX and Win32 API calls

ReviewReview

How does a batch operating system differ from lti d ti t ?a multiprogrammed operating system?

Why is multiprogramming useful?Why are multiprogrammed systems much moreWhy are multiprogrammed systems much more difficult to implement than are batch systems? What is timesharing? How does it differ from gmultiprogramming?What is an online system?What is a real time s stem?What is a real-time system?Which systems try to maximize throughput? Which ones try to minimize response time?

53

Which ones try to minimize response time?

What type of operating system would you useWhat type of operating system would you use

For editing a letter?For controlling a chemical reaction?For processing payroll?In a cellphone?In a toy?For surfing the web?For air traffic control?F i tifi i l ti ?For a scientific simulation?To play MP3?

54

Computer architectureComputer architecture

What connects the processor to memory?What are the components of the storage hierarchy?What is between the processor and I/O devices?What are the components of a disk?What are the components of a disk?What is an interrupt?Why are interrupts useful?Why are interrupts useful?What happens to program execution when an interrupt occurs?

55

interrupt occurs?

OS interactionOS interaction

Does it differ if the operating system is monolithic or a microkernel?What are the steps involved when the operating

t i lithi ?system is monolithic?What additional steps happen in case of a microkernel?microkernel?

56