Chapter 2 Memory and process Management

  

Chapter 2

Chapter 2 Memory and process Memory and process

Management

Management

Part 2: Process

management in OS

  

Prepared by: Nor Zuraida Bt Mohd Gaminan

Department of IT & Communication

  Learning Outcome Learning Outcome

  

  By the end of this chapter, student will be able to:

  1)

  Explain role of control blocks and interrupt in the dispatching process

  2)

  Describe various types of scheduling processes

  3)

  Explain diferent types of scheduling algorithms

  4)

  Explain how queuing and the scheduler work together Control blocks Control blocks There are several control felds that must be maintained in support of each active program. Often, a control block is created to hold:

  1) a partition’s key control fags, 2) constants 3) variables The control blocks (one per partition) are linked to form a linked list. The dispatcher typically determines which program is to start by following the chain of pointers from control block to control block.

  

A given control block’s relative position in the linked list might be determined by its priority or computed dynamically, perhaps Control blocks

Control blocks

  • Information about each program is stored in the program’s control block.
  • The dispatcher determines which
Interrupts Interrupts

   An interrupt is an electronic signal. 

  Hardware senses the signal, saves key control information for the currently executing program, and starts the operating system’s

  interrupt handler routine. At that instant, the interrupt ends.

  

  The operating system then handles the interrupt.

  

  Subsequently, after the interrupt is processed,

  

Example of how interrupt

Example of how interrupt

work work

  Step 1:

  

Example of how interrupt

Example of how interrupt

work work

  Step 2:

  

Example of how interrupt

Example of how interrupt

work work

  Step 3:

  

Example of how interrupt

Example of how interrupt

work work

  Step 4:

  

Example of how interrupt

Example of how interrupt

work work

  Step 5:

  

Example of how interrupt

Example of how interrupt

work work

  Step 6:

  Process Process

   A program execution, process execution must progress in sequential fashion

   Process include:

  1) Program counter

  2) Stack 3) Data section 

  Process state:

  • New: The process is being created
  • >Running: Instruction are being executed

  

Process

Process CPU Scheduler CPU Scheduler

  

  Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them

  

  CPU scheduling decisions may take place when a process:

  1. Switches from running to waiting state

  2. Switches from running to ready state

  3. Switches from waiting to ready CPU Scheduler CPU Scheduler

  Preemptive scheduling policy interrupts processing of a job and transfers the CPU to another job.

  • The process may be pre-empted by the operating system when:

  1) a new process arrives (perhaps at a higher priority), or

  2) an interrupt or signal occurs, or 3) a (frequent) clock interrupt occurs.

  

Non-preemptive scheduling policy functions without

external interrupts.

  • - once a process is executing, it will continue to execute until

    it terminates, or

  CPU Scheduling CPU Scheduling

   Scheduling criteria:

  1) CPU utilization

  The ratio of busy time of the processor to the total time passes for processes to fnish.

  Processor Utilization = (Processor buy time) / (Processor busy time + Processor idle time)

   Maximize, to keep as busy as possible

  2) Throughput

  The measure of work done in a unit time CPU Scheduling CPU Scheduling 3) Turnaround time

  

The sum of time spent in the ready queue, execution time

and I/O time. tat = t(process completed) – t(process submitted)

   minimize, time spent in ready queue - afected solely by scheduling policy 5) Response time The amount of time it takes to start responding to a request.

  This criterion is important for interactive systems. rt = t(frst response) – t(submission of request) CPU Scheduling CPU Scheduling

  

  Types of scheduling:

  1)

  long-term scheduling Medium-term scheduling

  3)

  Short-term scheduling Long-term scheduling Long-term scheduling

  

  Determine which programs admitted to system for processing - controls degree of multiprogramming

  

  Once admitted, program becomes a process, either:

  • – added to queue for short-term scheduler
  • – swapped out (to disk), so added to queue for medium-term scheduler
Medium –term scheduling

Medium –term scheduling

  

  Part of swapping function between main memory and disk

  • based on how many processes the OS wants available at any one time
  • must consider memory management if no virtual memory (VM), so look at memory requirements of swapped out processes
Short –term scheduling Short –term scheduling

  (dispatcher) (dispatcher)

  

  Executes most frequently, to decide which process to execute next

  • – Invoked whenever event occurs that interrupts current process or provides an opportunity to preempt current one in favor of another
  • – Events: clock interrupt, I/O interrupt, OS call, signal
CPU Scheduling CPU Scheduling

  

  Types of scheduling algorithm: Basic strategies

  First In First Out (FIFO)

  2)

  Shortest Job First (SJF)

  3)

  Shortest Remaining Time First (SRTF)

  4)

  Round Robin (RR)

  5)

  Priority First Come First Serve First Come First Serve

  (FIFO) (FIFO)

   Non-preemptive. 

  Handles jobs according to their arrival time -- the earlier they arrive, the sooner they’re served.

  

  Simple algorithm to implement -- uses a FIFO queue.

  

  Good for batch systems; not so good for interactive ones.

   Shortest Job First (SJF) Shortest Job First (SJF)

   Non-preemptive. 

  Handles jobs based on length of their CPU cycle time.

  ◦

Use lengths to schedule process with shortest

time.

   Optimal – gives minimum average waiting time for a given set of processes.

  ◦

optimal only when all of jobs are available at

same time and the CPU estimates are available

  

Shortest Remaining Time First

Shortest Remaining Time First

  (SRTF) (SRTF)

   Preemptive version of the SJF algorithm.  Processor allocated to job closest to completion.

  ◦ This job can be preempted if a newer job in

READY queue has a “time to completion”

that's shorter.

   Can’t be implemented in interactive system -- requires advance knowledge of CPU time required to fnish each job.

   Round Robin (RR) Round Robin (RR)

   FCFS with Preemption. 

  Used extensively in interactive systems because it’s easy to implement.

   Isn’t based on job characteristics but on a predetermined slice of time that’s given to each job.

  ◦ Ensures CPU is equally shared among all

active processes and isn’t monopolized by any one job. Priority scheduling Priority scheduling

   Non-preemptive. 

Gives preferential treatment to important jobs.

  ◦ Programs with highest priority are processed frst.

  ◦ Aren’t interrupted until CPU cycles are completed or a natural wait occurs.

   If 2+ jobs with equal priority are in READY queue, processor is allocated to one that arrived frst (frst come frst served within priority).

  

Multi-level queue

Multi-level queue

  

Multi-level queue

Multi-level queue

  

Multi-level queue

Multi-level queue

  

Multi-level feedback queue

Multi-level feedback queue

  (MLFQ) (MLFQ)

  

Multi-level feedback queue

Multi-level feedback queue

  (MLFQ) : Example (MLFQ) : Example Queuing and scheduler Queuing and scheduler

  

  As one program fnishes processing and space becomes available, which program is loaded into memory next?

  

  This decision typically involves two separate modules, a queuing routine and a

  scheduler Queuing and scheduler Queuing and scheduler

  1) As programs enter the system, Multiprogramming and time Multiprogramming and time sharing sharing

  

  A timesharing system allows multiple users to interact with a computer at the same time

  

  Multiprogramming allowed multiple processes to be active at once, which gave rise to the ability for programmers to interact with the computer system directly, while still sharing its resources

  

  In a timesharing system, each user has his or her own virtual machine, in which all system