processes - nmt computer science and engineeringcs325/spring 11/lectures/lec05... · 2011-02-09 ·...

27
CSE325 Principles of Operating Systems Processes David P. Duggan [email protected] February 1, 2011

Upload: others

Post on 30-May-2020

4 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

CSE325 Principles of Operating Systems

Processes

David P. Duggan

[email protected]

February 1, 2011

Page 2: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 2

Today’s Goal:

1. Process Concept

2. Process Manager Responsibilities

3. Process Scheduling

4. Operations on Processes

5. Cooperating Processes

6. Inter-process Communication

Page 3: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

Process Concept

Early systems allowed one program at a time Poor utilization of expensive hardware

Defn: A Process is an abstraction of a processor Process is also a program in execution

Tighter control and compartmentalization

Unit of work in modern time-sharing systems

Modern systems consist of a collection of processes

A program is static, a process is dynamic

1/30/2011 CSE325 - Processes 3

Page 4: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

4

Basic Abstractions

Program ResultAbstractMachine

PhysicalMachine

AbstractMachineProgram Result

Idea

Idea

AbstractMachineProgram Result

… …Idea

Page 5: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 5

How Multiprogramming Works

Processor

Process 1

Process 2

Process 3

Process 4

Space-multiplexed Memory

Time-multiplexed CPU

Page 6: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 6

Process Abstraction

Operating System

Hardware

Data

Process

Stac

k

Processor

ExecutableMemory

Program

Page 7: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

7

OSAddressSpace

Implementing the Process Abstraction

ControlUnit

OS interface

Mac

hine

Exe

cuta

ble

Mem

ory

ALU

CPUPi Address

Space

Pi CPU

Pi ExecutableMemory

Pk AddressSpace

Pk CPU

Pk ExecutableMemory

Pj AddressSpace

Pj CPU

Pj ExecutableMemory

1/30/2011

Page 8: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

Formal Model

The process concept is used to model: The states of a system – state

Some sequence of status values – computation

Means of generating a class of such sequences – action function

State-variables Elementary quantities

Can assume well-defined values

State Mapping from state-variables into values

1/30/2011 CSE325 - Processes 8

Page 9: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

Formal Model, contd

State Space Set of possible states for a given set of state-variables

Computation Sequence of states, starting with the initial state

Action Function Mapping from states into states

Process is a triple (S,f,I), where S: state space

f: action function in that state space

I <= S: set of initial states

1/30/2011 CSE325 - Processes 9

Page 10: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

Formal Model, contd

A process generates all computations generated by its action function from its initial states

Intuitively the variable set is memory

a state gives the contents of memory

the action function is a program

If two processes have disjoint state variable sets, they cannot interact Communication among processes is modeled by shared variables

Multiple processes may share WHAT, acting on different variable sets

1/30/2011 CSE325 - Processes 10

Page 11: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

11

External View of the Process Manager

Hardware

ApplicationProgram

Dev

ice

Mgr

Proc

ess M

gr

Mem

ory

Mgr

File

Mgr

UNIX

Dev

ice

Mgr

Proc

ess M

gr

Mem

ory

Mgr

File

Mgr

Windows

CreateThread()CreateProcess()CloseHandle()

WaitForSingleObject()

fork()

exec()wait()

1/30/2011

Page 12: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

12

Process Manager Overview

Program Process

Abstract Computing Environment

FileManager

MemoryManager

DeviceManager

ProtectionDeadlock

Synchronization

ProcessDescription

CPU Other H/W

SchedulerResourceManagerResourceManagerResourceManager

MemoryDevices

Page 13: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

13

Process Concept

An operating system executes a variety of programs: Batch system – jobs

Time-shared systems – user programs or tasks

We use the terms job and process almost interchangeably.

Process – a program in execution; process execution must progress in sequential fashion.

A process includes: program counter

stack

data section

Page 14: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

14

Algorithms, Programs, and Processes

Data

FilesFilesFiles

OtherResources

Idea

Algorithm

SourceProgram

BinaryProgram

Execution Engine

Process

StackStatus

1/30/2011

Page 15: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 15

Process State

As a process executes, it changes state new: The process is being created.

ready: The process is waiting to be assigned to a processor.

running: Instructions are being executed.

waiting: The process is waiting for some event to occur.

terminated: The process has finished execution.

Page 16: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 16

Diagram of Process State

Program

Page 17: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 17

UNIX State Transition Diagram

Runnable

StartAllocate

Done

Zombie

Wait byparent

Running

Schedule

Request

SleepingRequest

UninterruptibleSleep

I/O Request

I/O Complete

Traced or Stopped

Resume

Page 18: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 18

Windows NT Thread States

Initialized

CreateThread

Ready

Activate

Sele

ct

Standby

Running

Terminated

Waiting

Transition

Reinitialize

Exit

Pree

mpt

Dispatch

WaitWait Complete

Wait Complete

Dispatch

Page 19: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 19

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 20: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

20

Process & Address Space

Address Space

Code ResourcesResources

Abstract Machine Environment

Stack

DataResources

1/30/2011 CSE325 - Processes

Page 21: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

21

The Address Space

Process

AddressSpace

AddressBinding

ExecutableMemory

Other objects

Files

1/30/2011

Page 22: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 22

Process Control Blocks (PCB)or Process Descriptors

Information (data structure) associated with each process. Process state

Program counter

CPU registers

CPU scheduling information

Memory-management information

Accounting information

I/O status information

Page 23: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

23

Process Control Block (PCB)

1/30/2011

Page 24: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 24

EPROCESS

…void *UniqueProcessId;…

NT Executive

Windows NT Process Descriptor

KPROCESS…uint32 KernelTime;uint32 UserTime;…Byte state;

NT Kernel

Page 25: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 25

CPU Switch From Process to Process

Page 26: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

26

Context Switching

ProcessManager

InterruptHandler

P1

P2

Pn

Executable MemoryInitialization

1

23

45

7Interrupt

8

9

6

1/30/2011

Page 27: Processes - NMT Computer Science and Engineeringcs325/spring 11/Lectures/Lec05... · 2011-02-09 · 1/30/2011 CSE325 - Processes 2 Today’s Goal: 1. Process Concept 2. Process Manager

1/30/2011 CSE325 - Processes 27

Context Switch

When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process.

Context-switch time is overhead; the system does no useful work while switching.

Time dependent on hardware support.

How to reduce context-switch overheads?