Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf ·...

27
CSE325 Principles of Operating Systems Processes David P. Duggan [email protected] January 29, 2013

Transcript of Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf ·...

Page 1: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

CSE325 Principles of Operating Systems

Processes

David P. Duggan

[email protected]

January 29, 2013

Page 2: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 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 - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

Process Concept

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

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

n  Tighter control and compartmentalization

n  Unit of work in modern time-sharing systems

n  Modern systems consist of a collection of processes

n  A program is static, a process is dynamic

1/29/13 CSE325 - Processes 3

Page 4: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

4

Basic Abstractions

Program Result Abstract Machine

Physical Machine

Abstract Machine Program Result

Idea

Idea

Abstract Machine Program Result

Idea

Page 5: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 5

How Multiprogramming Works

Processor

Process 1

Process 2

Process 3

Process 4

Space-multiplexed Memory

Time-multiplexed CPU

Page 6: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 6

Process Abstraction

Operating System

Hardware

Data

Process

Stac

k

Processor

Executable Memory

Program

Page 7: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

7

OS Address Space

Implementing the Process Abstraction

Control Unit

OS interface

Mac

hine

Exe

cuta

ble

Mem

ory

ALU

CPU Pi Address

Space

Pi CPU

Pi Executable Memory

Pk Address Space

Pk CPU

Pk Executable Memory

Pj Address Space

Pj CPU

Pj Executable Memory

1/29/13

Page 8: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

Formal Model

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

n  Some sequence of status values – computation

n  Means of generating a class of such sequences – action function

n  State-variables n  Elementary quantities

n  Can assume well-defined values

n  State n  Mapping from state-variables into values

1/29/13 CSE325 - Processes 8

Page 9: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

Formal Model, contd

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

n  Computation n  Sequence of states, starting with the initial state

n  Action Function n  Mapping from states into states

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

n  f: action function in that state space

n  I <= S: set of initial states

1/29/13 CSE325 - Processes 9

Page 10: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

Formal Model, contd

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

n  Intuitively n  the variable set is memory

n  a state gives the contents of memory

n  the action function is a program

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

n  Multiple processes may share , acting on different variable sets

1/29/13 CSE325 - Processes 10

Page 11: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

11

External View of the Process Manager

Hardware

Application Program

Dev

ice

Mgr

Proc

ess M

gr

Mem

ory

Mgr

Fi

le M

gr

UNIX

Dev

ice

Mgr

Proc

ess M

gr

Mem

ory

Mgr

Fi

le M

gr

Windows

CreateThread() CreateProcess() CloseHandle()

WaitForSingleObject()

fork()

exec() wait()

1/29/13

Page 12: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

12

Process Manager Overview

Program Process

Abstract Computing Environment

File Manager

Memory Manager

Device Manager

Protection Deadlock

Synchronization

Process Description

CPU Other H/W

Scheduler Resource Manager Resource Manager Resource Manager

Memory Devices

Page 13: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

13

Process Concept

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

n  Time-shared systems – user programs or tasks

n  We use the terms job and process almost interchangeably.

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

n  A process includes: n  program counter

n  stack

n  data section

Page 14: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

14

Algorithms, Programs, and Processes

Data

Files Files Files

Other Resources

Idea

Algorithm

Source Program

Binary Program

Execution Engine

Process

Stack Status

1/29/13

Page 15: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 15

Process State

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

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

n  running: Instructions are being executed.

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

n  terminated: The process has finished execution.

Page 16: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 16

Diagram of Process State

Program

Page 17: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 17

UNIX State Transition Diagram

Runnable

Start Allocate

Done

Zombie

Wait by parent

Running

Schedule

Request

Sleeping Request

Uninterruptible Sleep

I/O Request

I/O Complete

Traced or Stopped

Resume

Page 18: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 18

Windows NT Thread States

Initialized

CreateThread

Ready

Activate

Sele

ct

Standby

Running

Terminated

Waiting

Transition

Reinitialize

Exit

Pree

mpt

Dispatch

Wait Wait Complete

Wait Complete

Dispatch

Page 19: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 19

Address Space

n  Process must be able to reference every resource in its abstract machine

n  Assign each unit of resource an address

n  Most addresses are for memory locations

n  Abstract device registers

n  Mechanisms to manipulate resources

n  Addresses used by one process are inaccessible to other processes

n  Say that each process has its own address space

Page 20: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

20

Process & Address Space

Address Space

Code Resources Resources

Abstract Machine Environment

Stack

Data Resources

1/29/13 CSE325 - Processes

Page 21: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

21

The Address Space

Process

Address Space

Address Binding

Executable Memory

Other objects

Files

1/29/13

Page 22: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 22

Process Control Blocks (PCB) or Process Descriptors

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

n  Program counter

n  CPU registers

n  CPU scheduling information

n  Memory-management information

n  Accounting information

n  I/O status information

Page 23: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

23

Process Control Block (PCB)

1/29/13

Page 24: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 24

EPROCESS

… void *UniqueProcessId; …

NT Executive

Windows NT Process Descriptor

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

NT Kernel

Page 25: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 25

CPU Switch From Process to Process

Page 26: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

26

Context Switching

Process Manager

Interrupt Handler

P1

P2

Pn

Executable Memory Initialization

1

2 3

4 5

7 Interrupt

8

9

6

1/29/13

Page 27: Processes - New Mexico Institute of Mining and Technologycs325/spring2013/Lec05-Processes.pdf · Cooperating Processes 6. Inter-process Communication . Process Concept ! Early systems

1/29/13 CSE325 - Processes 27

Context Switch

n  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.

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

n  Time dependent on hardware support.

How to reduce context-switch overheads?