Operating Systems Hadi Salimi Computer Engineering Department Iran - - PDF document

operating systems
SMART_READER_LITE
LIVE PREVIEW

Operating Systems Hadi Salimi Computer Engineering Department Iran - - PDF document

Operating Systems Hadi Salimi Computer Engineering Department Iran University of Science and Technology y gy Tehran, Iran hsalimi@iust.ac.ir Spring 2009 Course motivation and goals Course motivation and goals Programming computer


slide-1
SLIDE 1

Operating Systems

Hadi Salimi Computer Engineering Department Iran University of Science and Technology y gy Tehran, Iran hsalimi@iust.ac.ir Spring 2009

Course motivation and goals Course motivation and goals

Programming computer hardware

g g p 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

slide-2
SLIDE 2

Class outline Class outline

Introduction and Overview Introduction and Overview Processes and threads Operating system structures Operating system structures Memory management Scheduling Scheduling Input/Output File Systems

y

Security

3

Textbook Textbook

Andrew S. Tanenbaum. “Operating Systems design

and implementation”, 3nd ed., Prentice Hall, 2006.

Abraham Silberschatz, Galvin, and Gagne. “Operating Abraham Silberschatz, Galvin, and Gagne. Operating

Systems Concepts”, 7nd ed., John Wiley and Sons, 2005 Willi St lli “O ti S t ” 4 d d

William Stallings. “Operating Systems”, 4nd ed.,

Prentice Hall, 2001.

Andrew S. Tanenbaum. “Modern Operating Systems”,

p g y , 2nd ed., Prentice Hall, 2001.

4

slide-3
SLIDE 3

Overview: Overview:

What is an operating system? Operating systems history The zoo of modern operating systems Review of computer hardware Operating system concepts System calls Operating system structure

U i t f t th ti t

User interface to the operating system Anatomy of a system call

5

Samples of Operating Systems Samples of Operating Systems

IBSYS (IBM 7090)

OS/360 (IBM 360)

MACH OS/360 (IBM 360) TSS/360 (360 mod 67) Michigan Terminal Apollo DOMAIN Unix (System V & BSD) Apple Mac (v 1– v 9)

System

CP/CMS & VM 370 MULTICS (GE 645) Apple Mac (v. 1

  • v. 9)

MS-DOS Windows NT, 2000, XP

( )

Alto (Xerox PARC) Pilot (Xerox STAR) CP/M Novell Netware Linux FreeBSD CP/M IRIX Solaris FreeBSD PalmOS PocketPC

6

MVS VxWorks VxWorks

slide-4
SLIDE 4

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 machine

Hides the messy details which must be performed

Hides the messy details which must be performed Presents user with a virtual machine, easier to use

It is a resource manager

Each program gets time with the resource

8

Each program gets space on the resource

slide-5
SLIDE 5

The Operating System controls the machine controls the machine

Compiler Debugger

User Application

OS Kernel

Hard

Video Game

Application Operating System ware

Editor

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 System Operating System Hardware

10

slide-6
SLIDE 6

Dynamic View of System Components Dynamic View of System Components

11

L f C t S t Layers of a Computer System

End User Programmer

Application Programs

Operating- System Designer

O e ti S te Utilities Computer Hardware Operating-System

12

slide-7
SLIDE 7

History of Operating Systems History of Operating Systems

First generation: 1945 – 1955

V b Pl b d

Vacuum tubes, Plug boards

Second generation: 1955 – 1965

Transistors, Batch systems

Third generation: 1965 – 1980

Integrated circuits, Multiprogramming

Fourth generation: 1980 – present Fourth generation: 1980 – present

Large scale integration, Personal

computers

Next generation: ???

Next generation: ???

Systems connected by high-speed

networks? Wid t?

13 Wide area resource management?

First generation: direct input First generation: direct input

Run one job at a time

Enter it into the computer (might require rewiring!) Run it

Record the results

Record the results

Problem: lots of wasted computer time!

Computer was idle during first and last steps

Computer was idle during first and last steps

Computers were very expensive!

Goal: make better use of an expensive

commodity: computer time

14

slide-8
SLIDE 8

Second generation: batch systems Second generation: batch systems

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

15

Put output tape on 1401, which prints output

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

$END

Data for program

$RUN $LOAD

FORTRAN program

$FORTRAN $JOB, 10,6610802, JANE DOE 16

slide-9
SLIDE 9

Third generation: multiprogramming Third generation: multiprogramming

Multiple jobs in memory

P d f

Protected from one

another

Operating system

Job 3 protected from each job as well

Resources (time

Job 1 Job 2 Memory Operating

Resources (time,

hardware) split between jobs Still t i t ti Job 1 partitions Operating system

Still not interactive

User submits job Computer runs it 17 User gets results minutes

(hours, days) later

Multi tasking Multi tasking

Job 1 Operat Main C

Task 1 Task 2

Job 2 Job 3 ing System n Memory CPU

Resource utilization Resource utilization

Multiprogramming, multitasking, and multiple users. Time sharing.

18

Response time.

slide-10
SLIDE 10

Timesharing Timesharing

Multiprogramming allowed several jobs to be

active at one time

Initially used for batch systems

Cheaper hardware terminals interactive use

Cheaper hardware terminals → interactive use

Computer use got much cheaper and easier

No more “priesthood” No more priesthood Quick turnaround meant quick fixes for problems

19

Types of modern operating systems Types of modern operating systems

Mainframe operating systems: MVS Server operating systems: FreeBSD, Solaris Multiprocessor operating systems: Cellular IRIX Personal computer operating systems: XP, Linux PDA operating systems: PalmOS, PocketPC Real-time/embedded operating systems: VxWorks,

QNX Smart card operating s stems

Smart card operating systems

⇒Some operating systems can fit into more than one

category

20

category

slide-11
SLIDE 11

Computer Hardware Review Computer Hardware Review

Computer block diagram

p g

Components of a simple personal

computer computer

CPU internals

Memor

Memory Storage pyramid Disk drive structure Anatomy of a device request

21

y q

Structure of a large Pentium system

Control Unit Input Unit Output Unit Computer CPU

Monitor Printer

ALU Control Unit

Keyboard Mouse Scanner

Input Unit Output Unit CPU Registers Bank

Modem Modem

Cache Memory

Main Memory ROM RAM

Memory

Secondary Memory HD FD CD Flash

22

Tertiary Memory Tape

slide-12
SLIDE 12

Computer Components: Top-Level View p p p

MAR - Memory Address Register

address for next read or write

MBR - Memory Buffer Register

data to be written into memory data 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/O exchange of data between an I/O

module and the processor

23

Components of a simple personal computer Components of a simple personal computer

Outside Outside world

Hard drive controller Video controller USB controller Network controller controller controller controller controller CPU

Computer internals (inside the “box”)

24

Memory

( )

slide-13
SLIDE 13

CPU internals

Execute

CPU internals

Execute unit Fetch unit Decode unit Execute unit Execute unit Holding buffer Fetch unit Decode unit Execute unit Fetch unit Decode unit

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

25

Memory Memory

Address

0x0002ffff

Address

0x0002ffff

User 2 program and data

0x00027fff 0x0002b000 0x0002ffff Limit

User 2 data User 1 data

Limit2 Base2 0x00029000 0x0002bfff 0x0002ffff 0x0002d000

User 1 program and data

0x0001dfff 0x00023000 0x00027fff Base Limit

User program

Base1 Limit1

2

0x0001dfff 0x00023000 0x00024fff

Operating system

0x0001dfff 0x00000000

Operating system

0x0001dfff 0x00000000

Single base/limit pair: set for each process

T b /li it i t f f d t

26

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

slide-14
SLIDE 14

Storage pyramid

Access latency Capacity

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 y

Latencies are smaller at the top of the hierarchy Capacities 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 structure Disk drive structure

sector head

Data stored on surfaces

U f

sector platter

Up to two surfaces per

platter

One or more platters per

di k

cylinder platter track

disk

Data in concentric tracks

Tracks broken into sectors

cylinder surfaces

256B-1KB per sector

Cylinder: corresponding

tracks on all surfaces

spindle surfaces

Data read and written by

heads

Actuator moves heads 28

spindle actuator

Heads move in unison

slide-15
SLIDE 15

Anatomy of a device request Anatomy of a device request

Instruction Interrupt controller CPU 5 Disk controller 3 2 Instructionn Instructionn+1 1: Interrupt 6 1 4 Operating system Interrupt handler 3: Return

Left: sequence as seen by hardware

Request sent to controller, then to disk

Disk responds signals disk controller which tells interrupt

p 2: Process interrupt

Disk responds, signals disk controller which tells interrupt

controller

Interrupt 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 Components Operating system Components

Process Management Memory Management File Management I/O Management Process Scheduler Inter Process Communication Network Unit

C d I t t

Command Interpreter Security Management

30

slide-16
SLIDE 16

Processes Processes

  • Process: program in execution
  • Address space (memory) the
  • Address space (memory) the

program can use

  • State (registers, including

program counter & stack pointer)

A

pointer)

  • OS keeps track of all

processes in a process table

  • Processes can create other

B C D

processes

  • Process tree tracks these

relationships

  • A is the root of the tree

E F G

  • A is the root of the tree
  • A created three child

processes: B, C, and D

  • C created two child

E d F

31

processes: E and F

  • D created one child process:

G

Memory image of a Unix process Memory image of a Unix process

Processes have three

t

0x7f f f f f f f

segments

Text: program code Data: program data

Stack 0x7f f f f f f f

Statically declared

variables

Areas allocated by

malloc() or new (heap) malloc() or new (heap)

Stack

Automatic variables Procedure call information

Data Data

Address space growth

Text: doesn’t grow Data: grows “up”

Text

32 Data: grows up Stack: grows “down”

0x00000000

slide-17
SLIDE 17

Synchronization and deadlock Synchronization and deadlock

33

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

Hierarchical file systems Hierarchical file systems

34

File system for a university department

slide-18
SLIDE 18

Mounting Mounting

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 communication Inter process communication

Processes may want to exchange information with each

th

  • ther

Many ways to do this, including

Network Pipe (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

slide-19
SLIDE 19

Types of OS structures Types of OS structures

Monolithic system Layered system Virtual machine Exokernel Client/Server

37

Monolithic system Monolithic system

Main Main procedure Service Procedures Utility Procedures

38

Simple structuring model for a monolithic system

slide-20
SLIDE 20

Monolithic system… Monolithic system…

Applicatio ns ns

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 system Layered system

User

Layer 5

User Application

User space

Layer 4

Message Interpreter

Har

I/O Management

Kernel space

Layer 3 Layer 2

P S h d li Memory Management

rdware

Layer 1

Structure of the THE operating system

Process Scheduling

Layer 0

40

Structure of the THE operating system

slide-21
SLIDE 21

Virtual machine Virtual machine

App1 App2 App3 VM/370 CMS (VMW) Linux pp1 pp2 pp3 CMS (VMW) CMS (VMW) Windows NT FreeBSD I/O instructions System calls Calls to simulate I/O Bare hardware VM/370 Calls to simulate I/O “Real” I/O instructions

  • First widely used in VM/370 with CMS (Conversational Monitor System)
  • Available today in VMware
  • Allows users to run any x86-based OS on top of Linux or NT
  • Allows users to run any x86 based OS on top of Linux or NT
  • “Guest” OS can crash without harming underlying OS
  • Only virtual machine fails—rest of underlying OS is fine
  • “Guest” OS can even use raw hardware

41

  • Guest OS can even use raw hardware
  • Virtual machine keeps things separated

Exokernel Exokernel

Same as Virtual machine Assign one virtual computer to any user Allocate sub set of resource to any virtual

machine

42

slide-22
SLIDE 22

Client/Server

Cli t P T i l Cli t Fil M

Client/Server

Microkernel Client process Process server Terminal server Client process File server Memory server

User mode Kernel mode e e

  • de

Client obtains service by sending messages to server The client-server model

Processes (clients and OS servers) don’t share memory

C i ti i i

sending messages to server processes

Communication via message-passing Separation reduces risk of “byzantine” failures

Examples include Mach, QNX, early versions of Windows

43

NT

Client/Server… Client/Server…

Applicatio ns ns System call interface

User space Process Scheduler File System Device manager

Micro Kernel Kernel space IPC Memory Management Synchronization

44

Memory Management Synchronization

slide-23
SLIDE 23

Client/Server… Client/Server…

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

45

System calls System calls

Programs want the OS to perform a service

Access a file Create a process

Others

Others…

Accomplished by system call

Program passes relevant information to OS

Program passes relevant information to OS

OS performs the service if

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

OS checks information passed to make sure it’s OK

Don’t want programs reading data into other programs’

!

46

memory!

slide-24
SLIDE 24

System calls… System calls…

Applications Applications Applications

User space K l

Applications Applications Applications System call interface

Kernel space MM PS IPC FS MM PS IPC FS I/O Net

OS Component

47

Making a system call Making a system call

System call:

d(fd b ff l th)

0xffffffff Library

read(fd,buffer,length)

Program pushes

arguments, calls library

Return to caller Trap to kernel (read call)

Library sets up trap, calls

OS

OS handles system call

Trap to kernel Trap code in register User space 2 3 8

OS handles system call Control returns to library Library returns to user

Increment SP Call read Push arguments 1 4 7 9

program

There are 9 steps in

making the system call

Push arguments Dispatch Sys call Kernel space 1 5 6 User code

48

making the system call

Dispatch y handler space (OS) 0

slide-25
SLIDE 25

System calls for files & directories System calls for files & directories

Call Description

fd = open(name how) Open a file for reading and/or writing fd = 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 calls More system calls

Call Description

pid = fork() Create a child process identical to the parent parent 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 1970 MINIX S t ll

50

( ) p MINIX System calls

slide-26
SLIDE 26

A simple shell A 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 Calls System Calls

52

Some UNIX and Win32 API calls

slide-27
SLIDE 27

Review Review

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 more Why are multiprogrammed systems much more

difficult to implement than are batch systems?

What is timesharing? How does it differ from

g multiprogramming?

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 use What 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

slide-28
SLIDE 28

Computer architecture Computer 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 interaction OS 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