Download - Chapter 2 (Part 2)

Transcript
Page 1: Chapter 2 (Part 2)

PART 2: PROCESS MANAGEMENT IN OS

DEPARTMENT OF IT & COMMUNICATIONPOLITEKNIK TUANKU SYED SIRAJUDDIN

Chapter 2Memory and process

Management

Page 2: Chapter 2 (Part 2)

Learning Outcome

By the end of this chapter, student will be able to:1)Explain role of control blocks and interrupt in the

dispatching process2)Describe various types of scheduling processes3)Explain different types of scheduling algorithms4)Explain how queuing and the scheduler work

together5)Differences between multiprogramming and time

sharing6)Explain how to handle deadlock

Page 3: Chapter 2 (Part 2)

Process

Process – a program in execution.A process – need resources (CPU time, files,

I/O devices) to accomplish task.process execution must progress in

sequential fashion

Page 4: Chapter 2 (Part 2)

Process include:1)Program counter2)Process Stack – containing temp data (subroutine parameters, return addresses, temp variables)3)Data section – containing global variables.

Page 5: Chapter 2 (Part 2)

Process state

Page 6: Chapter 2 (Part 2)

As a processes executes, it changes state.Each process – in on of the following state :

NEW – The process is being created. READY – The process is waiting to be assigned to a

pocessor. RUNNING – Instruction are being executed. WAITING – The process are waiting for some event to

occur (I/O completion or reception of a signal) TERMINATED – The process has finished execution.

……………………….Process state

Page 7: Chapter 2 (Part 2)

Control blocks

Each process is representer in the OS by a process control blok (PCB).

There are several control fields that must be maintained in support of each active program.

Often, a control block is created to hold:

1) a partition’s key control flags,2) constants3) variables

The control blocks (one per partition) are linked to form a linked list.

Page 8: Chapter 2 (Part 2)

………………………..Control blocks

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 taking into account such factors as:

1)program size,2)time in memory,3)peripheral device requirements 4)and other measures of the program’s impact on

system resources.

Page 9: Chapter 2 (Part 2)

Control blocks

•Information about each program is stored in the program’s control block.

•The dispatcher determines whichprogram to start next byfollowing a linked list ofcontrol blocks.

Page 10: Chapter 2 (Part 2)

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,

the dispatcher starts an application program. Eventually, the program that was executing at

the time of the interrupt resumes processing.

Page 11: Chapter 2 (Part 2)

Example of how interrupt work

Step 1:

Page 12: Chapter 2 (Part 2)

Example of how interrupt work

Step 2:

Page 13: Chapter 2 (Part 2)

Example of how interrupt work

Step 3:

Page 14: Chapter 2 (Part 2)

Example of how interrupt work

Step 4:

Page 15: Chapter 2 (Part 2)

Example of how interrupt work

Step 5:

Page 16: Chapter 2 (Part 2)

Example of how interrupt work

Step 6:

Page 17: Chapter 2 (Part 2)

Basic Conceptts :Objective of multiprogramming to have some process running at all time, to maximize CPU utilization.When one process in wait state OS will take the CPU away from that process and gives the CPU to another one. This pattern continues…Uniprecess ??? Only ONE running process. If more than one ???

CPU SCHEDULING

Page 18: Chapter 2 (Part 2)

……………………………….CPU Scheduler

CPU scheduling decisions may take place when a process:1. Switches from running to waiting state2. Switches from running to ready state3. Switches from waiting to ready4. Terminates Scheduling under 1 and 4 is nonpreemptiveAll other scheduling is preemptive

Page 19: Chapter 2 (Part 2)

………………………………...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), or2)an interrupt or signal occurs, or3)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 by switching o the waiting state.

Page 20: Chapter 2 (Part 2)

……………………………………………………………………………………CPU CPU SchedulingScheduling

Scheduling criteria:1)CPU utilizationThe ratio of busy time of the processor to the total time passes for processes to finish.

Processor Utilization = (Processor busy time) /

(Processor busy time + Processor idle time)To keep the CPU as busy as possible

Page 21: Chapter 2 (Part 2)

2) ThroughputIf the CPU is busy executing process then

work is being done.The measure of work done in a unit time

interval. Throughput = (Number of processes completed) / (Time Unit)Long process would take one process/hourShort process might take 10

processes/second.

……………………………………………………………………………………CPU CPU SchedulingScheduling

Page 22: Chapter 2 (Part 2)

………………………………………………………………………………………….CPU .CPU SchedulingScheduling

3) Turnaround time How long it takes to execute a process. The sum of time spent waiting to get into memory, waiting

in ready queue, execution time on CPU and doing I/O time.tat = time(process completed) – time(process submitted)

4) Waiting time The sum of periods spent waiting in the ready queue only.

5) Response time Time from the submission of a request until the first

response is produced. This criterion is important for interactive systems.

rt = t(first response) – t(submission of request)

Page 23: Chapter 2 (Part 2)

…………………………………………………………………………………….CPU .CPU SchedulingScheduling

Types of scheduling:1)long-term scheduling2)Medium-term scheduling3)Short-term scheduling

Page 24: Chapter 2 (Part 2)

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

Page 25: Chapter 2 (Part 2)

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

Page 26: Chapter 2 (Part 2)

Short –term scheduling (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

Page 27: Chapter 2 (Part 2)

Scheduling AlgorithmScheduling Algorithm

CPU scheduling deals with the problem of deciding

which of the processes in the ready queue is to be

allocated the CPU.

Page 28: Chapter 2 (Part 2)

………………………………………………………………………….Scheduling .Scheduling AlgorithmAlgorithm

Types of scheduling algorithm:Basic strategies1)First In First Out (FIFO) / First –Come, First-Served.2)Shortest Job First (SJF)3)Shortest Remaining Time First (SRTF)4)Round Robin (RR)5)Priority

Combined strategies1)Multi-level queue2)Multi-level feedback queue

Page 29: Chapter 2 (Part 2)

First Come First Serve (FIFO)

Non-preemptive.Handles jobs according to their arrival time -- the

earlier they arrive, the sooner they’re served. The process the request the CPU first is allocated the

CPU first.Simplest algorithm to implement -- uses a FIFO

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

ones.Turnaround time is unpredictable.

Page 30: Chapter 2 (Part 2)

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 and accurate.

Doesn’t work in interactive systems because users don’t estimate in advance CPU time required to run their jobs.

Page 31: Chapter 2 (Part 2)

Shortest Remaining Time First (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 finish each job.

SRT involves more overhead than SJN. OS monitors CPU time for all jobs in READY queue

and performs “context switching”.

Page 32: Chapter 2 (Part 2)

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.Time slice is called a time quantum

size crucial to system performance (100 ms to 1-2 secs)

Page 33: Chapter 2 (Part 2)

Priority scheduling

Non-preemptive.Gives preferential treatment to important jobs.

Programs with highest priority are processed first. 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 first (first come first served within priority).

Many different methods of assigning priorities by system administrator or by Processor Manager.

Page 34: Chapter 2 (Part 2)

Multi-level queue

Page 35: Chapter 2 (Part 2)

Multi-level queue

Page 36: Chapter 2 (Part 2)

Multi-level queue

Page 37: Chapter 2 (Part 2)

Multi-level feedback queue (MLFQ)

Page 38: Chapter 2 (Part 2)

Multi-level feedback queue (MLFQ) : Example

Page 39: Chapter 2 (Part 2)

Queuing and scheduler

As one program finishes 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

Page 40: Chapter 2 (Part 2)

Queuing and schedulerQueuing and scheduler

1) As programs enter the system, they are placed on a queue by the queuing routine. 2) When space becomes available, the scheduler selects a program from the queue and loads it into memory.

Page 41: Chapter 2 (Part 2)

Multiprogramming and time 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 resources are (in effect) available for use


Top Related