topic : process management lecture by: rupinder kaur lecturer it, srs govt. polytechnic college for...

35
Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Upload: jefferson-hillock

Post on 14-Dec-2015

230 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Topic : Process Management

Lecture By: Rupinder KaurLecturer IT,SRS Govt. Polytechnic College for Girls,Ludhiana

Page 2: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Index

Process ConceptProcess statesProcess Control BlockProcesses SchedulingSchedulersScheduling Algorithms

Page 3: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

What is Process?

A Process is a program in execution. A process is more than the program

code, which is some time known as the text section.

It also includes the current activity, as represented by the value of program counter and the contents of the processor’s registers.

Page 4: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Operations on Processes

Process Creation

Process Termination

Page 5: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Process States

Page 6: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Process StatesNew - The process is being created.Running –It means CPU is actually running the

process(i.e. executing the instruction of the process).

Waiting –It means that process needs input or produced an output and it is waiting for the completing of that input /output.

Ready –This state means that process has been created and now it is ready to be picked up by CPU for execution

Terminated - Process has finished execution.

Page 7: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Contains information associated with each process

Process State - e.g. new, ready, running etc.

Process Number – Process ID

Program Counter - address of next instruction to be executed

CPU registers - general purpose registers, stack pointer etc.

Process Control Block

Page 8: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Process Control Block (Cont..)

CPU scheduling information - process priority, pointer

Memory Management information - base/limit information

Accounting information - time limits, process number

I/O Status information - list of I/O devices allocated

Page 9: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Process Scheduling QueuesJob Queue - set of all processes in the

systemReady 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 migration between the various queues.

Page 10: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Schedulers

Long-term scheduler (or job scheduler) - selects which processes should be brought

into the ready queue. invoked very infrequently (seconds,

minutes); may be slow.controls the degree of multiprogramming

Page 11: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Short term scheduler (or CPU scheduler) -

selects which process should execute next and allocates CPU.

invoked very frequently (milliseconds) - must be very fast

Medium Term Schedulerswaps out process temporarilybalances load for better throughput

Schedulers (Cont..)

Page 12: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Scheduling CriteriaCPU utilization — It is defined as how much time

the CPU remain busy .CPU utilization should be as high as possible.

Throughput —It is defined as the no. of process completed as per unit time.

Turnaround time — It is defined as the time between the submission of job and completion of job. so, it is the time taken the process in the ready queues, time during execution by CPU. It should also be as small as possible.

Page 13: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Scheduling Criteria(Cont..)

Waiting time — It is define as the time spent by the process in the ready queue .waiting time should be small.

Response time — It is define as the time when the first response start coming. It should also be as small as possible.

Page 14: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Scheduling Criteria(Cont..)Max CPU utilizationMax throughputMin turnaround timeMin waiting timeMin Response time

Page 15: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Types of CPU SchedulingThere are two types of CPU scheduling :1) Preemptive2)Non-Preemptive

Page 16: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Types of CPU Scheduling (cont..)

A scheduling discipline is non-preemptive if, once a process has been given the CPU, the CPU cannot be taken away from that process.

In nonpreemptive system,- short jobs are made to wait by longer jobs but

the overall treatment of all processes is fair.-a scheduler executes jobs in the following two

situations.When a process switches from running

state to the waiting state.When a process terminates.

Page 17: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Types of CPU Scheduling (cont..)

A scheduling discipline is preemptive if, once a process has been given the CPU can taken away.

Page 18: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Scheduling AlgorithmsFCFS

Round Robin

Priority

Shortest Job First

Feedback Queues

Page 19: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

FCFS (First Come First Serve)Implementation:

As each process becomes ready, it joins the ready queue.

When the current process finishes the oldest process is selected next.

Characteristics:Simple to implementNonpreemptive

Page 20: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

FCFS EXAMPLE :

Process Burst Time P1 8 P2 4 P3 9 P4 5

0 8 12 21 26

Average wait =(0+8+12+21)/4 = 10.25

P1 P2 P3 P4

Page 21: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

SHORTEST JOB FIRST:

• Associate with each process the length of its next CPU burst.

• Use these lengths to schedule the process with the shortest time.

Two schemes:1.  non-preemptive – once CPU given to the

process it cannot be preempted until completes its CPU burst.

2. preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF).

Page 22: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

SJFS(Non-Preemptive) Process               Burst Time                    P1                             7                    P2                           4                    P3                            1                    P4                           4SJF (non-preemptive) 0 1 5 9 16

Average waiting time = [9 +1+0+5] /4 =3.7 

P3 P2 P4 P1

Page 23: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

SJFS(Preemptive)Example of Preemptive SJF Process                    Arrival  Time               Burst

TimeP1                                    0.0                               7P2                                    2.0                               4P3                                    4.0                               1P4                                     5.0                              4 SJF (preemptive) 0           2             4               5              7           

11           16          

P1 P2 P3

P2 P4 P1

Page 24: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

SJFS(Preemptive) 0           2             4               5              7           

11           16  Waiting Time = Waiting Time - No. of times

executed – Arrival TimeP1 = 11 – 2 – 0 = 9P2 = 5 – 2 – 2 = 1P3 = 4 – 0 – 4 =0P4 = 7 – 0 – 5 =2Avg. Waiting Time : (9 + 1 + 0 +2)/4 =3

P1 P2 P3 P2 P4 P1

Page 25: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

RR - Round RobinIn case of the Round Robin Scheduling ,the

CPU is allocate to all the processes one by one but for a fixed period of time . This time period is known as time slice or time quantum .

After allocating CPU to a process for a fixed time slice , it shifts to next process and so on.

It is very efficient algorithm for interactive system because response time is very small in this case .

It is similar to FCFS but preemptive in nature.

Page 26: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Example of RRExample of RR with Time Quantum = 2 Process Burst Time P1 5 P2 3 P3 3 The Gantt chart is:

0 2 4 6 8 9 10 11

P1

P2 P3 P1 P2

P3

P1

Page 27: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Example of RR The Gantt chart is:

0 2 4 6 8 9 10 11 Waiting time = Waiting Time – No. of times executedP1 = 10 – 4 = 6P2 = 8 – 2 = 6P3 = 9 – 2 = 7Avg . Waiting Time = (6+6+7)/3 = 6.3

P1 P2 P3 P1 P2 P3 P1

Page 28: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Priority Scheduling

• A priority number (integer) is associated with each process.

• The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority).

       1. Preemptive       2. non-preemptive• SJF is a priority scheduling where priority is the

predicted next CPU burst time.• Problem with the priority scheduling is

Starvation – low priority processes may never execute

Page 29: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Priority SchedulingProcess          Priority Burst Time       P1 2 24 P2 1 3 P3 3 3The Gantt Chart for the non-preemptive schedule is: 0 3 27 30

Waiting time for P1 = 3; P2 = 0; P3 = 27 Average waiting time: (3+ 0 + 27)/3 = 10

P2 P1

P3

Page 30: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Priority SchedulingProcess Burst Time Priority

Arrival Time       P1 3 2 0 P2 2 1 1 P3 1 3 2The Gantt Chart for the preemptive schedule is: 0 1 2 3 5 6

Waiting time for P1 = 3 – 1 - 0 =2; P2 = 1 – 1 = 0; P3 = 5 – 2 = 3 Average waiting time: (2+0+3)/3 = 1.6

P1 P2

P2

P1 P3

Page 31: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Multilevel Queue

• Ready queue is partitioned into separate queues• Each queue has its own scheduling algorithm• Scheduling must be done between the queues.

 

Page 32: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Multilevel Queue SchedulingHighest priority

Lowest priority

SYSTEM PROCESS

INTERACTIVE PROCESS

INTERACTIVE EDITING PROCESS

BATCH PROCESS

STUDENT PROCESS

Page 33: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Multilevel Feedback QueueA process can move between the various queuesMultilevel-feedback-queue scheduler defined by

the following parameters:  1. number of queues  2. scheduling g algorithms for each queue  3. method used to determine when to upgrade a

process   4. method used to determine when to demote a

process  5. method used to determine which queue a

process will enter  when that process needs service

 

Page 34: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

Example of Multilevel Feedback Queue

Three queues:1. Q0 – time quantum 8 milliseconds2. Q1 – time quantum 16 milliseconds3. Q2 – FCFS

Quantum=8

Quantum=16

FCFS

Page 35: Topic : Process Management Lecture By: Rupinder Kaur Lecturer IT, SRS Govt. Polytechnic College for Girls,Ludhiana

THANK YOU