os lecture 7 os process management

Upload: anshu-mittal

Post on 10-Oct-2015

19 views

Category:

Documents


1 download

TRANSCRIPT

  • BITS Pilani K K Birla Goa Campus

    Operating Systems

    Dr. Lucy J. Gudino Dept. of CS and IS

  • BITS Pilani K K Birla Goa Campus

    Operating System: Process Management

  • BITS Pilani, K K Birla Goa Campus

    As a process executes, it changes state

    new: The process is being created.

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

    running: Instructions are being executed.

    waiting(Blocking) : The process is waiting for some event to occur.

    terminated (exit): The process has finished execution.

    Contd Five State Model

  • BITS Pilani, K K Birla Goa Campus

    4 reasons for process creation

    System initialization.

    A user request to create a new process. Example : user request for file print

    Batch environment: a process is created in response to the submission of a job

    Interactive environment : a process is created when a new user attempts to log on

    Contd

  • BITS Pilani, K K Birla Goa Campus

    Normal completion

    Time limit exceeded

    Memory unavailable

    Protection error

    Arithmetic error

    Bounds violation

    I/O failure

    Invalid instruction

    Privileged instruction

    Parent termination

    Parent request

    Reasons for process termination

  • BITS Pilani, K K Birla Goa Campus

    Job queue set of all processes in the system.

    Ready queue set of all processes residing in main memory, ready and waiting to execute.

    Device queues set of processes waiting for an I/O device.

    Process Scheduling Queues

  • BITS Pilani, K K Birla Goa Campus

    Queuing Model

  • BITS Pilani, K K Birla Goa Campus

    Ready queue and device queue

  • BITS Pilani, K K Birla Goa Campus

    Representation of Process Scheduling

  • BITS Pilani, K K Birla Goa Campus

    OS must have information about the current state of

    processes.

    OS must have information about the current state of

    resources in the system.

    OS must keep track of utilization of resources by

    processes.

    OS constructs and maintains tables (control structure) of

    information about each entity it is managing.

    OS as process manager

  • BITS Pilani, K K Birla Goa Campus

    Contd

  • BITS Pilani, K K Birla Goa Campus

    Operating System Control Tables

  • BITS Pilani, K K Birla Goa Campus

    Memory Table

    The allocation of main memory to processes

    The allocation of secondary memory to processes

    Any protection attributes of blocks of main or virtual memory, such as which processes may access certain shared memory regions

    Any information needed to manage virtual memory

    I/O Table

    Status of I/O Operation

    the location in main memory being used as the source or destination of the I/O transfer

    Tables

  • BITS Pilani, K K Birla Goa Campus

    File table

    the existence of files,

    their location on secondary memory,

    current status

    other attributes

    Process Table

    process image : collection of program, data, stack, and PCB

    Tables

  • BITS Pilani, K K Birla Goa Campus

    Types:

    Long-term scheduler (or job scheduler) Decides which processes should be brought into the ready queue.

    Short-term scheduler (or CPU scheduler) Decides which process should be executed next and allocates

    CPU.

    Short term scheduler is invoked very frequently (milliseconds) must be fast

    The long-term scheduler controls the degree of multiprogramming (the number of processes in memory).

    invoked only when a process leaves the system

    can be slow

    Schedulers

  • BITS Pilani, K K Birla Goa Campus

    Long term scheduler I/O bound process and CPU bound process

    I/O bound process: spends more time doing I/O than

    computations, many short CPU bursts. CPU-bound process spends more time doing

    computations; few very long CPU bursts.

    Should select a good process mix of I/O bound and CPU bound

    System should be balanced

    Medium term scheduler Swapping is necessary to improve the process mix

    Scheduler

  • BITS Pilani, K K Birla Goa Campus

    Addition of Medium Term Scheduling

    Operating System Concepts

  • BITS Pilani, K K Birla Goa Campus

    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.

    Kernel saves context of old process in its PCB and loads the context of new process

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

    deciding factors: memory speed, number of registers that must be copied etc.

    Time dependent on hardware support. some systems provide multiple sets of registers

    change the pointer to the current register set

    Context Switch

  • BITS Pilani, K K Birla Goa Campus

    Parent process create children processes, which, in turn create other processes, forming a tree of processes.

    Processes are identified using unique process identifier (pid) : integer number

    each process has one parent but zero, one, two, or more children

    Process Creation

  • BITS Pilani, K K Birla Goa Campus

    Resource sharing

    Parent and children share all resources.

    Children share subset of parents resources.

    Parent and child share no resources.

    When a process is created, initialization data (input) may be passed along by the parent process to the child process

    Execution : 2 possibilities

    Parent and children execute concurrently.

    Parent waits until some or all its children terminate.

    Process Creation (Cont)

  • BITS Pilani, K K Birla Goa Campus

    Address space : two possibilities

    Child is a duplicate of parent. (program and data same)

    Child has a new program loaded into it.

    UNIX examples

    fork system call creates new process

    exec system call used after a fork to replace the process memory space with a new program.

    ps command can be used to list processes

    Process Creation (Cont)

  • BITS Pilani, K K Birla Goa Campus

    Process executes last statement and asks the operating system to delete it (exit). status of the terminating process is return to parent process

    (wait() system call)

    Process resources are deallocated by operating system.

    Parent may terminate execution of children processes (abort). Child has exceeded allocated resources.

    Task assigned to child is no longer required.

    Parent is exiting.

    Operating system does not allow child to continue if its parent terminates.

    Cascading termination.

    Process Termination