+ All Categories
Home > Documents > Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter...

Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter...

Date post: 14-Dec-2015
Category:
Upload: august-buffkin
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
30
Operating Systems: A Modern Perspective, Chapter 2 Slide 2- 1 Copyright © 2004 Pearson Education, Inc. Using the Operating System 2
Transcript
Page 1: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-1

Copyright © 2004 Pearson Education, Inc.

Using the Operating System

2

Page 2: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-2

Copyright © 2004 Pearson Education, Inc.

The Airplane Pilot’s Abstract Machine

Page 3: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-3

Copyright © 2004 Pearson Education, Inc.

Basic Abstractions

ProgramProgram ResultResult

ProgramProgram ResultResult

ProgramProgram ResultResult

… …

Idea

Idea

Idea

Page 4: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-4

Copyright © 2004 Pearson Education, Inc.

Basic Abstractions(2)

ProgramProgram ResultResult

AbstractMachine

AbstractMachine

ProgramProgram ResultResult

ProgramProgram ResultResult

AbstractMachine

PhysicalMachine

… …

Idea

Idea

Idea

Page 5: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-5

Copyright © 2004 Pearson Education, Inc.

Abstract Machine Entities

• Process: A sequential program in execution

• Resource: Any abstract resource that a process can request, and which may can cause the process to be blocked if the resource is unavailable.

• File: A special case of a resource. A linearly-addressed sequence of bytes. “A byte stream.”

Page 6: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-6

Copyright © 2004 Pearson Education, Inc.

Algorithms, Programs, and Processes

Data

FilesFiles

Files

OtherResources

AlgorithmAlgorithm

Idea

SourceProgram

SourceProgram

BinaryProgram

Execution Engine

Process

StackStatus

Page 7: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-7

Copyright © 2004 Pearson Education, Inc.

Classic Process

• OS implements {abstract machine} – one per task

• Multiprogramming enables N programs to be space-muxed in executable memory, and time-muxed across the physical machine processor.

• Result: Have an environment in which there can be multiple programs in execution concurrently*, each as a processes

* Concurrently: Programs appear to execute simultaneously

Page 8: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-8

Copyright © 2004 Pearson Education, Inc.

Process Abstraction

Hardware

DataData

ProcessProcess

Sta

ck

Processor

ExecutableMemory

ProgramProgram

Operating SystemOperating System

Page 9: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-9

Copyright © 2004 Pearson Education, Inc.

Processes Sharing a Program

Shared Program Text

P1

P2

P3

P1 P2 P3

FilesFiles

FilesFiles

FilesFiles

Page 10: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-10

Copyright © 2004 Pearson Education, Inc.

Multithreaded Accountant

Purchase Orders

Invoice

Invoice

(a) Separate Processes

Purchase Orders

InvoiceFirst Accountant

Second Accountant

Accountant & Clone

(b) Double Threaded Process

Page 11: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-11

Copyright © 2004 Pearson Education, Inc.

Modern Process & Thread

• Divide classic process:– Process is an infrastructure in which execution

takes place – address space + resources– Thread is a program in execution within a

process context – each thread has its own stack

DataData

ProcessProcess

Sta

ck

ProgramProgram

Operating SystemOperating System

ThreadThread

Thread

Sta

ck

Sta

ck

Page 12: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-12

Copyright © 2004 Pearson Education, Inc.

A Process with Multiple Threads

Data

FilesFiles

Files

OtherResources

BinaryProgram

Process

StackStatus

StackStatus

StackStatus

Thread (Execution Engine)

Page 13: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-13

Copyright © 2004 Pearson Education, Inc.

More on Processes• Abstraction of processor resource

– Programmer sees an abstract machine environment with spectrum of resources and a set of resource addresses (most of the addresses are memory addresses)

– User perspective is that its program is the only one in execution

– OS perspective is that it runs one program with its resources for a while, then switches to a different process (context switching)

• OS maintains– A process descriptor data structure to implement the

process abstraction• Identity, owner, things it owns/accesses, etc.• Tangible element of a process

– Resource descriptors for each resource

Page 14: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-14

Copyright © 2004 Pearson Education, Inc.

Address Space• Process must be able to reference every

resource in its abstract machine

• Assign each unit of resource an address– Most addresses are for memory locations– Abstract device registers– Mechanisms to manipulate resources

• Addresses used by one process are inaccessible to other processes

• Say that each process has its own address space

Page 15: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-15

Copyright © 2004 Pearson Education, Inc.

Shared Address Space

• Classic processes sharing program shared address space support

• Thread model simplifies the problem– All threads in a process implicitly use that process’s

address space , but no “unrelated threads” have access to the address space

– Now trivial for threads to share a program and data• If you want sharing, encode your work as threads in a process

• If you do not want sharing, place threads in separate processes

Page 16: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-16

Copyright © 2004 Pearson Education, Inc.

Process & Address Space

Address Space

CodeResources

Resources

Abstract Machine Environment

Stack

DataResources

Page 17: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-17

Copyright © 2004 Pearson Education, Inc.

Creating a Process

• Here is the classic model for creating processes:

FORK(label): Create another process in the same addressspace beginning execution at instruction labelQUIT(): Terminate the process.JOIN(count): disableInterrupts(); count--; if(count > 0) QUIT(); enableInterrupts();

Page 18: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-18

Copyright © 2004 Pearson Education, Inc.

Example

procA() { while(TRUE) { <compute section A1>; update(x); <compute section A2>; retrieve(y); }}

procB() { while(TRUE) { retrieve(x); <compute section B1>; update(y); <compute section B2>; }}

Process AProcess A Process BProcess B

x

y

Page 19: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-19

Copyright © 2004 Pearson Education, Inc.

UNIX Processes

UNIX Kernel

DataSegment

FilesFiles

Files

OtherResources

TextSegment

StackSegment

Status

Process

Page 20: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-20

Copyright © 2004 Pearson Education, Inc.

UNIX Processes

• Each process has its own address space– Subdivided into text, data, & stack segment– a.out file describes the address space

• OS kernel creates descriptor to manage process

• Process identifier (PID): User handle for the process (descriptor)

• Try “ps” and “ps -aux” (read man page)

Page 21: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-21

Copyright © 2004 Pearson Education, Inc.

Creating/Destroying Processes

• UNIX fork() creates a process– Creates a new address space– Copies text, data, & stack into new adress space– Provides child with access to open files

• UNIX wait() allows a parent to wait for a child to terminate

• UNIX exec() allows a child to run a new program

Page 22: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-22

Copyright © 2004 Pearson Education, Inc.

Resources

• Anything that a process requests from an OS– Available allocated– Not available process is blocked

• Examples– Files– Primary memory address space (“virtual memory”)– Actual primary memory (“physical memory”)– Devices (e.g., window, mouse, kbd, serial port, …)– Network port– … many others …

Page 23: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-23

Copyright © 2004 Pearson Education, Inc.

Files

• Data must be read into (and out of) the machine – I/O devices

• Storage devices provide persistent copy• Need an abstraction to make I/O simple –

the file• A file is a linearly-addressed sequence of

bytes– From/to an input device– Including a storage device

Page 24: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-24

Copyright © 2004 Pearson Education, Inc.

The File Abstraction

Hardware

DataData

ProcessProcess

Sta

ck

Processor

ExecutableMemory

ProgramProgram

Operating SystemOperating System

StorageDevice

FileFile

FileDescriptor

FileDescriptor

Page 25: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-25

Copyright © 2004 Pearson Education, Inc.

UNIX Files

open Specifies file name to be usedclose Release file descriptorread Input a block of informationwrite Output a block of informationlseek Position file for read/writeioctl Device-specific operations

• UNIX and NT try to make every resource (except CPU and RAM) look like a file

• Then can use a common interface:

Page 26: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-26

Copyright © 2004 Pearson Education, Inc.

UNIX File Example#include <stdio.h>#include <fcntl.h>int main() { int inFile, outFile; char *inFileName = “in_test”; char *outFileName = “out_test”; int len; char c;

inFile = open(inFileName, O_RDONLY); outFile = open(outFileName, O_WRONLY);/* Loop through the input file */ while ((len = read(inFile, &c, 1)) > 0) write(outFile, &c, 1);/* Close files and quite */ close(inFile); close(outFile);}

Page 27: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-27

Copyright © 2004 Pearson Education, Inc.

Shell Command Line Interpreter

OS

Interactive User

Shell Program

Application& SystemSoftware

OS System Call InterfaceOS System Call Interface

Page 28: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-28

Copyright © 2004 Pearson Education, Inc.

The Shell Strategy

Shell ProcessShell Process

Processto executecommand

Processto executecommand

% grep first f3

f3

read keyboard fork a process

read file

Page 29: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-29

Copyright © 2004 Pearson Education, Inc.

Bootstrapping

• Computer starts, begins executing a bootstrap program -- initial process

• Loads OS from the disk (or other device)

• Initial process runs OS, creates other processes

Page 30: Slide 2-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 2 Using the Operating System 2.

Operating Systems: A Modern Perspective, Chapter 2

Slide 2-30

Copyright © 2004 Pearson Education, Inc.

Initializing a UNIX Machine

Serial Port A

Serial Port B

Serial Port C

Serial Port Z

login

login

login

login

gettygetty

/etc/passwd


Recommended