lec05 processes

Upload: rayani-budi-andhini

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Lec05 Processes

    1/27

    CSE325 Principles of Operating Systems

    Processes

    David P. Duggan

    [email protected]

    February 1, 2011

  • 8/12/2019 Lec05 Processes

    2/27

    1/30/2011 CSE325 - Processes 2

    Todays Goal:

    1. Process Concept

    2. Process Manager Responsibilities

    3. Process Scheduling

    4. Operations on Processes

    5. Cooperating Processes

    6. Inter-process Communication

  • 8/12/2019 Lec05 Processes

    3/27

    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

  • 8/12/2019 Lec05 Processes

    4/27

    4

    Basic Abstractions

    Program ResultAbstract

    Machine

    Physical

    Machine

    Abstract

    MachineProgram Result

    Idea

    Idea

    Abstract

    MachineProgram Result

    Idea

  • 8/12/2019 Lec05 Processes

    5/27

    1/30/2011 CSE325 - Processes 5

    How Multiprogramming Works

    Processor

    Process 1

    Process 2

    Process 3

    Process 4

    Space-multiplexed Memory

    Time-multiplexed CPU

  • 8/12/2019 Lec05 Processes

    6/27

    1/30/2011 CSE325 - Processes 6

    Process Abstraction

    Operating System

    Hardware

    Data

    Process

    S

    tack

    Processor

    Executable

    Memory

    Program

  • 8/12/2019 Lec05 Processes

    7/27

    7

    OSAddress

    Space

    Implementing the Process Abstraction

    Control

    Unit

    OS interface

    Mac

    hineExecutableM

    emory

    ALU

    CPU

    Pi AddressSpace

    Pi CPU

    Pi Executable

    Memory

    PkAddress

    Space

    Pk CPU

    Pk Executable

    Memory

    PjAddress

    Space

    Pj CPU

    Pj Executable

    Memory

    1/30/2011

  • 8/12/2019 Lec05 Processes

    8/27

    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 actionfunction

    State-variables

    Elementary quantities

    Can assume well-defined values

    State

    Mapping from state-variables into values

    1/30/2011 CSE325 - Processes 8

  • 8/12/2019 Lec05 Processes

    9/27

    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

  • 8/12/2019 Lec05 Processes

    10/27

    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

  • 8/12/2019 Lec05 Processes

    11/27

    11

    External View of the Process Manager

    Hardware

    Application

    Program

    DeviceMgr

    P

    rocessMgr

    M

    emoryMgr

    FileMgr

    UNIX

    DeviceMgr

    P

    rocessMgr

    M

    emoryMgr

    FileMgr

    Windows

    CreateThread()CreateProcess()

    CloseHandle()

    WaitForSingleObject()

    fork()

    exec()wait()

    1/30/2011

  • 8/12/2019 Lec05 Processes

    12/27

    12

    Process Manager Overview

    Program Process

    Abstract Computing Environment

    File

    Manager

    MemoryManager

    DeviceManager

    Protection

    Deadlock

    Synchronization

    Process

    Description

    CPU Other H/W

    SchedulerResource

    ManagerResource

    ManagerResource

    Manager

    MemoryDevices

  • 8/12/2019 Lec05 Processes

    13/27

    13

    Process Concept

    An operating system executes a variety of programs:

    Batch system jobs

    Time-shared systems user programs or tasks

    We use the termsjoband processalmost interchangeably.

    Process a program in execution; process execution must

    progress in sequential fashion.

    A process includes:

    program counter

    stack

    data section

  • 8/12/2019 Lec05 Processes

    14/27

    14

    Algorithms, Programs, and Processes

    Data

    FilesFiles

    Files

    Other

    Resources

    Idea

    Algorithm

    Source

    ProgramBinary

    Program

    Execution Engine

    Process

    StackStatus

    1/30/2011

  • 8/12/2019 Lec05 Processes

    15/27

    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.

  • 8/12/2019 Lec05 Processes

    16/27

    1/30/2011 CSE325 - Processes 16

    Diagram of Process State

    Program

  • 8/12/2019 Lec05 Processes

    17/27

    1/30/2011 CSE325 - Processes 17

    UNIX State Transition Diagram

    Runnable

    StartAllocate

    Done

    Zombie

    Wait by

    parentRunning

    Schedule

    Request

    Sleeping

    Request

    Uninterruptible

    Sleep

    I/O Request

    I/O Complete

    Traced or Stopped

    Resume

  • 8/12/2019 Lec05 Processes

    18/27

    1/30/2011 CSE325 - Processes 18

    Windows NT Thread States

    Initialized

    CreateThread

    Ready

    Activate

    Select

    Standby

    Running

    Terminated

    Waiting

    Transition

    Reinitialize

    Exit

    Preem

    pt

    Dispatch

    Wait

    Wait Complete

    Wait Complete

    Dispatch

  • 8/12/2019 Lec05 Processes

    19/27

    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 toother processes

    Say that each process has its own address space

  • 8/12/2019 Lec05 Processes

    20/27

    20

    Process & Address Space

    Address Space

    Code Resources

    Resources

    Abstract Machine Environment

    Stack

    Data

    Resources

    1/30/2011 CSE325 - Processes

  • 8/12/2019 Lec05 Processes

    21/27

    21

    The Address Space

    Process

    Address

    Space

    Address

    Binding

    Executable

    Memory

    Other objects

    Files

    1/30/2011

  • 8/12/2019 Lec05 Processes

    22/27

    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

  • 8/12/2019 Lec05 Processes

    23/27

    23

    Process Control Block (PCB)

    1/30/2011

  • 8/12/2019 Lec05 Processes

    24/27

    1/30/2011 CSE325 - Processes 24

    EPROCESS

    voi d *Uni quePr ocessI d;

    NT Executive

    Windows NT Process Descriptor

    KPROCESS

    ui nt 32 Ker nel Ti me;ui nt 32 User Ti me;Byt e st at e;

    NT Kernel

  • 8/12/2019 Lec05 Processes

    25/27

    1/30/2011 CSE325 - Processes 25

    CPU Switch From Process to Process

  • 8/12/2019 Lec05 Processes

    26/27

    26

    Context Switching

    Process

    Manager

    Interrupt

    Handler

    P1

    P2

    Pn

    Executable Memory

    Initialization 1

    23

    4

    5

    7Interrupt

    8

    9

    6

    1/30/2011

  • 8/12/2019 Lec05 Processes

    27/27

    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?