Process Management Concepts by gmb79530

VIEWS: 16 PAGES: 20

									                Process Management:
                     Concepts




                       Shivkumar Kalyanaraman
                     Rensselaer Polytechnic Institute
                        shivkuma@ecse.rpi.edu
             http://www.ecse.rpi.edu/Homepages/shivkuma
Rensselaer Polytechnic Institute            Shivkumar Kalyanaraman
                                   1
                                   Overview
 Processes
    Structure, creation, termination, communication
    Threads
 Scheduling:
    pre-emptive, non-preemptive
    FCFS, Shortest-Job First, Round Robin, Priority
 Concept checklist
Rensselaer Polytechnic Institute         Shivkumar Kalyanaraman
                                   2
                                   Process Structure
 Process = program in execution
 Processes execute "concurrently”


     Process state:
        New, running, waiting, ready, terminated


     PCB: process control block
        Representation of process in OS
        process state, PC, register values, scheduling and
         memory management info, I/O and file descriptors
Rensselaer Polytechnic Institute                       Shivkumar Kalyanaraman
                                          3
                                   Process Creation
     Create a child: duplicate of parent process:
        Eg: fork() in UNIX
        Advantage: resources inherited -- need not explicitly
         allocate again
        Disadvantage: Need one more step to load a new program if
         some unrelated task needs to be done.
           Eg: shell creating new processes to run user commands



     Loading a new program onto memory image:
        Eg: execve() in UNIX.
        Windows NT allows creation of a child process and loading
         program in one step.                   Shivkumar Kalyanaraman
Rensselaer Polytechnic Institute

                                          4
                                   Process Termination
 Options: exit() by itself or abort() call by parent
   Process id (pid) is needed for abort(), returned by
    the fork() call
 Reasons for abort():
   Resources exceeded. Parent must be able to inspect
    state of child

     UNIX: parent may wait() for child to exit() and the
      wait() returns the pid which can be used to identify
      how many children have terminated
Rensselaer Polytechnic Institute                    Shivkumar Kalyanaraman
                                           5
                                   Context Switch
     Switching between processes, especially the user process and
      kernel process
        Can take upto 1 ms. Pure overhead !
     Hardware support:
        Hardware trap: register saves and jump to trap routine done
         in hardware.
        DECSYSTEM 20: supports multiple register sets. The
         context switch to OS is done by just changing pointer to
         register sets.
        Memory management (swapping in pages or entries into
         TLB) increases context switch overhead. Optimization:
         don’t swap out OS pages!
     Overhead reduction: "threads"
Rensselaer Polytechnic Institute                    Shivkumar Kalyanaraman
                                         6
                                   Threads
     Thread: A basic unit of CPU utilization
        Owns: Program counter, register set and stack space
        Shares: code section, data section and OS resources (open
         files, signals)

     Threads + shared resources = “task”
     Advantages:
        Reduces overhead during creation of new processes
         (threads) and context switching: Eg: server implementations
        “User-level” threads.
            Implemented with user-level thread libraries.
            No need for system calls (and associated context switch)
             to create or transfer control between user-level threads
Rensselaer Polytechnic Institute                  Shivkumar Kalyanaraman
                                      7
                                   Threads (contd)
     Problem:
        No protection from other threads in same task.
        Many kernels (including BSD Unix) use a single-thread for
         the kernel to avoid synchronization problems (eg:
         clobbering common data structures), losing the efficiency of
         threads

     Solaris 2 thread architecture:
        User-level threads
        Light-weight processes
        Multiple kernel level threads (“multi-threaded”)
        Possibly multiple CPUs (multi-processor)
Rensselaer Polytechnic Institute                     Shivkumar Kalyanaraman
                                         8
                            Process Communication
     Shared-memory:
        Just like using a variable or array within the process’s
         address space. System calls only for setup/allocation.
        Fewer new operations => interface simple.
        Implementation/hardware support difficult. Esp. protection.


     Message-passing:
       Explicit communication using system calls.
       Implementation easier: used in Windows NT, with shared-
        memory-like optimizations whenever possible
       Shared memory is sometimes implemented internally using
        message-passing.
Rensselaer Polytechnic Institute                  Shivkumar Kalyanaraman
                                      9
              Process Communication (Contd)
     Buffer size:
        Zero => processes have to “rendezvous” or synchronize
         before being able to communicate. Eg: Ada language
        Bounded or unbounded:
           worry or don’t worry about buffer overflow, blocking
     Naming:
        Direct: name destination process in the system call
           Worry about enumerating each process if
            communication involves multiple processes.
        Indirect: Communicate through a “mailbox” or “port” (NT)
           Mailbox is allocated and processes either send/listen to it
           Worry about who allocates and who does "garbage
            collection.” OS support for latter usually available.
Rensselaer Polytechnic Institute                   Shivkumar Kalyanaraman
                                    10
               Process Communication (contd)
     Synchronous communication:
        Blocking wait on a communication resource till other
         parties (sender or receiver) arrive.
        Simpler abstraction, but can be inefficient for large/long
         transfers.
        Basis for the “remote procedure call”(RPC) abstraction


     Asynchronous communication:
        More efficient. Used in networking & multi-processors.
        Involves checksums, acknowledgements & timeouts for
         reliability. More complex implementation.

Rensselaer Polytechnic Institute                   Shivkumar Kalyanaraman
                                    11
                                   Scheduling Concepts
 Process execution:
    cycles of CPU-burst followed by I/O burst.
    Size of CPU burst typically small (fig 5.2)
 Scheduler moves processes between queues and CPU
    Ready queue not necessarily FIFO


 Nonpreemptive: Running process either terminates or
  goes to waiting state.
 Preemptive: Running -> Ready possible

Rensselaer Polytechnic Institute                    Shivkumar Kalyanaraman
                                           12
                         More scheduling concepts
       Preemptive scheduling:
          requires timers & mechanisms to preserve
           integrity of shared data, complex kernel

       Dispatcher: gives control of CPU to process
        selected by scheduler
          Involves dispatch latency


       Real-time scheduling requires that even kernel
        be pre-emptible
Rensselaer Polytechnic Institute             Shivkumar Kalyanaraman
                                    13
                                   Scheduling Criteria
       CPU Utilization (how busy is CPU ?)

       Throughput (# processes completed/second)

       Turnaround Time (start time to finish time)

       Waiting Time (Total time spent in ready Q)

       Response time (start time to first response time)

       What to optimize? Average, Maximum, Minimum, Variance

Rensselaer Polytechnic Institute                      Shivkumar Kalyanaraman
                                           14
               First-Come First-Served (FCFS)
      Simple to implement: FIFO queue
      Problems:
         High variance in average wait.
         Convoy effect if mix of CPU-bound & I/O
          bound jobs
         Nonpreemptive => not for timesharing systems




Rensselaer Polytechnic Institute         Shivkumar Kalyanaraman
                                   15
                            Shortest-Job-First (SJF)
 Size of next CPU burst determines schedule
 Shortest next-CPU-burst gets to go first
 Optimal => minimum avg waiting time
 Problem: how to find next CPU burst length
 Solution: Long term scheduler uses user-specified
  process time limit
 Short term scheduler: predict using exponential
  averaging technique


Rensselaer Polytechnic Institute                Shivkumar Kalyanaraman
                                       16
                         Shortest-Job-First (contd)
 Exponential averaging:
    T(n+1) = at(n) + (1-a)T(n), where 0 <= a <= 1
    Commonly, a = 1/2 (see fig 5.3)
 SJF can be preemptive (called “shortest remaining
  time first”) or non-preemptive




Rensselaer Polytechnic Institute              Shivkumar Kalyanaraman
                                     17
                                   Priority Scheduling
 Priority associated with each process and CPU
  allocated to process w/ highest priority
 FCFS = equal priority; SJF priority = 1/CPU burst
  time
 Can be defined internally/externally
 Can be preemptive or non preemptive
 Problem: starvation (indefinite blocking)
 Solution: priority with aging




Rensselaer Polytechnic Institute                     Shivkumar Kalyanaraman
                                           18
                          Round-Robin Scheduling
 Allocate constant CPU time-slices in order to
  processes organized in a circular ready Q
 FCFS + circular Q + preemption
 Performance depends upon quantum size
    short quantum => context switching overhead
    infinite quantum => FCFS
    Turnaround time vs quantum size (fig 5.5)
    Rule of thumb: 80% of CPU bursts < quantum



Rensselaer Polytechnic Institute            Shivkumar Kalyanaraman
                                    19
                    Summary: Concept checklist
     Process: process id (pid), process state, PCB, context switching
     Creation: duplicate and/or load program into memory image
     Terminate: exit() or abort()
     Threads, task:
        reduces context switch overhead
        may reduce resource usage redundancy: eg: server
         implementation
     Process Communication:
        message passing or shared memory
        Buffers, naming, sync/async communications
     Scheduling:
        long/medium term & short-term
        FCFS, SJF, Round-robin, Priority
Rensselaer Polytechnic Institute                   Shivkumar Kalyanaraman
                                    20

								
To top