CMPS 111: Introduction to Operating Systems Professor Scott A. - - PowerPoint PPT Presentation

cmps 111 introduction to operating systems
SMART_READER_LITE
LIVE PREVIEW

CMPS 111: Introduction to Operating Systems Professor Scott A. - - PowerPoint PPT Presentation

CMPS 111: Introduction to Operating Systems Professor Scott A. Brandt sb rand t@cs .ucsc .edu h t tp : / /www.cse .ucsc .edu /~sb randt / 111 Chapter 1 Class outline Introduction, concepts, review & historical


slide-1
SLIDE 1

Chapter 1

CMPS 111: Introduction to Operating Systems

Professor Scott A. Brandt

sb rand t@cs .ucsc .edu h t tp : / /www.cse .ucsc .edu /~sb randt / 111

slide-2
SLIDE 2

Chapter 1

2 CMPS 111, UC Santa Cruz

Class outline

Introduction, concepts, review & historical

perspective

Processes

Synchronization Scheduling Deadlock

Memory management, address translation, and

virtual memory

Operating system management of I/O File systems Security & protection Distributed systems (as time permits)

slide-3
SLIDE 3

Chapter 1

3 CMPS 111, UC Santa Cruz

Overview: Chapter 1

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

User interface to the operating system Anatomy of a system call

slide-4
SLIDE 4

Chapter 1

4 CMPS 111, UC Santa Cruz

What is an operating system?

A program that runs on the “raw” hardware and supports

Resource Abstraction Resource Sharing

Abstracts and standardizes the interface to the user across

different types of hardware

Virtual machine hides the messy details which must be performed

Manages the hardware resources

Each program gets time with the resource Each program gets space on the resource

May have potentially conflicting goals:

Use hardware efficiently Give maximum performance to each user

slide-5
SLIDE 5

Chapter 1

5 CMPS 111, UC Santa Cruz

Operating system timeline

First generation: 1945 – 1955

Vacuum tubes Plug boards

Second generation: 1955 – 1965

Transistors Batch systems

Third generation: 1965 – 1980

Integrated circuits Multiprogramming

Fourth generation: 1980 – present

Large scale integration Personal computers

Next generation: ???

Systems connected by high-speed networks? Wide area resource management?

slide-6
SLIDE 6

Chapter 1

6 CMPS 111, UC Santa Cruz

First generation: direct input

Run one job at a time

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

Problem: lots of wasted computer time!

Computer was idle during first and last steps Computers were very expensive!

Goal: make better use of an expensive commodity:

computer time

slide-7
SLIDE 7

Chapter 1

7 CMPS 111, UC Santa Cruz

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

slide-8
SLIDE 8

Chapter 1

8 CMPS 111, UC Santa Cruz

$END $RUN $LOAD

Structure of a typical 2nd generation job

$FORTRAN $JOB, 10,6610802, ETHAN MILLER

FORTRAN program Data for program

slide-9
SLIDE 9

Chapter 1

9 CMPS 111, UC Santa Cruz

Spooling

Original batch systems used tape drives Later batch systems used disks for buffering

Operator read cards onto disk attached to the computer Computer read jobs from disk Computer wrote job results to disk Operator directed that job results be printed from disk

Disks enabled simultaneous peripheral operation on-

line (spooling)

Computer overlapped I/O of one job with execution of

another

Better utilization of the expensive CPU Still only one job active at any given time

slide-10
SLIDE 10

Chapter 1

10 CMPS 111, UC Santa Cruz

Operating system

Third generation: multiprogramming

Multiple jobs in memory

Protected from one another

Operating system protected

from each job as well

Resources (time, hardware)

split between jobs

Still not interactive

User submits job Computer runs it User gets results minutes

(hours, days) later

Job 1 Job 2 Job 3 Memory partitions

slide-11
SLIDE 11

Chapter 1

11 CMPS 111, UC Santa Cruz

Timesharing

Multiprogramming allowed several jobs to be active

at one time

Initially used for batch systems Cheaper hardware terminals -> interactive use

Computer use got much cheaper and easier

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

slide-12
SLIDE 12

Chapter 1

12 CMPS 111, UC Santa Cruz

Types of modern operating systems

Mainframe operating systems: MVS Server operating systems: FreeBSD, Solaris Multiprocessor operating systems: Cellular IRIX Personal computer operating systems: Windows,

Unix

Real-time operating systems: VxWorks Embedded operating systems Smart card operating systems

⇒Some operating systems can fit into more than one

category

slide-13
SLIDE 13

Chapter 1

13 CMPS 111, UC Santa Cruz

Components of a simple PC

Hard drive controller Video controller Memory USB controller Network controller

Outside world

CPU

Computer internals (inside the “box”)

slide-14
SLIDE 14

Chapter 1

14 CMPS 111, UC Santa Cruz

Execute unit Execute unit Execute unit Execute unit

Buffer

Fetch unit Decode unit Fetch unit Decode unit Fetch unit Decode unit

CPU internals

Pipelined CPU Superscalar CPU

slide-15
SLIDE 15

Chapter 1

15 CMPS 111, UC Santa Cruz

Access latency 1 ns 2–5 ns 50 ns 5 ms 50 sec < 1 KB 1 MB 256 MB 40 GB > 1 TB Capacity

Storage pyramid

Registers Cache (SRAM) Main memory (DRAM) Magnetic disk Magnetic tape

Goal: really large memory with very low latency

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 large

memory with low latency

Better Better

slide-16
SLIDE 16

Chapter 1

16 CMPS 111, UC Santa Cruz

Disk drive structure

sector cylinder platter spindle track head actuator surfaces

Data stored on surfaces

Up to two surfaces per platter One or more platters per disk

Data in concentric tracks

Tracks broken into sectors

256B-1KB per sector

Cylinder: corresponding

tracks on all surfaces

Data read and written by

heads

Actuator moves heads Heads move in unison

slide-17
SLIDE 17

Chapter 1

17 CMPS 111, UC Santa Cruz

Memory

User program and data User program and data Operating system Address

0x1d f f f 0x23000 0x27 f f f 0x2b000 0x2 f f f f

Single base/limit pair: set for each process Two base/limit registers: one for program, one for data

Base Limit

User data User program Operating system User data

Base1 Limit2 Limit1 Base2

Address

0x1d f f f 0x23000 0x29000 0x2b f f f 0x2 f f f f 0x2d000 0x24 f f f

slide-18
SLIDE 18

Chapter 1

18 CMPS 111, UC Santa Cruz

Anatomy of a device request

Interrupt controller CPU 5 Disk controller 3 2 6 1 4

Left: sequence as seen by hardware

Request sent to controller, then to disk Disk responds, signals disk controller which tells interrupt controller Interrupt controller notifies CPU

Right: interrupt handling (software point of view)

Instructionn Operating system Instructionn+1 Interrupt handler 1: Interrupt 2: Process interrupt 3: Return

slide-19
SLIDE 19

Chapter 1

19 CMPS 111, UC Santa Cruz

Operating systems concepts

Many of these should be familiar to Unix users… Processes (and trees of processes) Deadlock File systems & directory trees Pipes We’ll cover all of these in more depth later on, but

it’s useful to have some basic definitions now

slide-20
SLIDE 20

Chapter 1

20 CMPS 111, UC Santa Cruz

Processes

  • Process: program in execution

Address space (memory) the

program can use

State (registers, including

program counter & stack pointer)

  • OS keeps track of all processes in

a process table

  • Processes can create other

processes

Process tree tracks these

relationships

A is the root of the tree A created three child processes:

B, C, and D

C created two child processes: E

and F

D created one child process: G

A B E F C D G

slide-21
SLIDE 21

Chapter 1

21 CMPS 111, UC Santa Cruz

Inside a (Unix) process

Processes have three

segments

Text: program code Data: program data

Statically declared variables Areas allocated by malloc()

  • r new

Stack

Automatic variables Procedure call information

Address space growth

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

Stack Data Text 0x7fffffff Data

slide-22
SLIDE 22

Chapter 1

22 CMPS 111, UC Santa Cruz

Deadlock

Potential deadlock Actual deadlock

slide-23
SLIDE 23

Chapter 1

23 CMPS 111, UC Santa Cruz

Root directory bin cse faculty grads ls ps cp csh

Hierarchical file systems

elm sbrandt kag amer4 stuff classes research stuff

slide-24
SLIDE 24

Chapter 1

24 CMPS 111, UC Santa Cruz

Interprocess communication

Processes want to exchange information with each other Many ways to do this, including

Network Pipe (special file): A writes into pipe, and B reads from it

A B

slide-25
SLIDE 25

Chapter 1

25 CMPS 111, UC Santa Cruz

System calls

Programs want the OS to perform a service

Access a file Create a process Others…

Accomplished by system call

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

OS checks information passed to make sure it’s OK

Don’t want programs reading data into other programs’ memory!

slide-26
SLIDE 26

Chapter 1

26 CMPS 111, UC Santa Cruz

Making a system call

System call:

read(fd,buffer,length)

Program pushes arguments,

calls library

Library sets up trap, calls

OS

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

program

Return to caller Trap to kernel Trap code in register Increment SP Call read Push arguments Dispatch Sys call handler Kernel space (OS) User space 0xffffffff 1 2 3 4 5 6 7 8 9 Library (read call) User code

slide-27
SLIDE 27

Chapter 1

27 CMPS 111, UC Santa Cruz

System calls for files & directories

Remove name as a link to an object (deletes the object if name was the only link to it)

s = unlink(name)

Create a new entry (name2) that points to the same object as name1

s = link(name1,name2)

Remove a directory (must be empty)

s = rmdir(name)

Create a new directory

s = mkdir(name,mode)

Get a file’s status information (in buffer)

s = stat(name,&buffer)

Move the “current” pointer for a file

s = lseek(fd,offset,whence)

Write data from a buffer into a file

n = write(fd,buffer,size)

Read data from a file into a buffer

n = read(fd,buffer,size)

Close an open file

s = close(fd)

Open a file for reading and/or writing

fd = open(name,how)

Description Call

slide-28
SLIDE 28

Chapter 1

28 CMPS 111, UC Santa Cruz

Get the elapsed time since 1 Jan 1970

seconds = time(&seconds)

Change a file’s protection bits

s = chmod(name,mode)

Send a signal to a process

s = kill(pid,signal)

Change the working directory

s = chdir(dirname)

Terminate process execution and return status

exit(status)

Replace a process’ core image

s = execve(name,argv,environp)

Wait for a child to terminate

pid=waitpid(pid,&statloc,options)

Create a child process identical to the parent

pid = fork()

Description Call

More system calls

slide-29
SLIDE 29

Chapter 1

29 CMPS 111, UC Santa Cruz

A simple shell

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 */ } }

slide-30
SLIDE 30

Chapter 1

30 CMPS 111, UC Santa Cruz

Monolithic OS structure

Main procedure Service routines Utility routines

slide-31
SLIDE 31

Chapter 1

31 CMPS 111, UC Santa Cruz

Virtual machines

  • First widely used in VM/370 with CMS
  • Available today in VMware

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

Virtual machine keeps things separated

Bare hardware Linux VMware Linux App1 App2 App3 VMware VMware Windows NT FreeBSD I/O instructions System calls Calls to simulate I/O “Real” I/O instructions

slide-32
SLIDE 32

Chapter 1

32 CMPS 111, UC Santa Cruz

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

User mode Kernel mode

Microkernels (client-server)

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

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

Examples include Mach

slide-33
SLIDE 33

Chapter 1

33 CMPS 111, UC Santa Cruz

Metric units

Exa

1,000,000,000,000,000,000

1018 atto

0.000000000000000001

10-18 Peta

1,000,000,000,000,000

1015 femto

0.000000000000001

10-15 Tera

1,000,000,000,000

1012 pico

0.000000000001

10-12 Giga

1,000,000,000

109 nano

0.000000001

10-9 Mega

1,000,000

106 micro

0.000001

10-6 Kilo

1,000

103 milli

0.001

10-3 Prefix

Number

Exp. Prefix

Number

Exp.