Skip to document

4. RR Scheduling

An example questions on the Round Robin - Preemptive - Scheduling questions.
Course

Operating Systems Principles (CSCI 340)

16 Documents
Students shared 16 documents in this course
Academic year: 2018/2019
Uploaded by:
0followers
10Uploads
4upvotes

Comments

Please sign in or register to post comments.

Preview text

(RR) Round Robin ~ Preemptive ~ CPU Scheduling Algorithm

Let

P

i

be = Process i where ( i = 0, 1, 2, 3, ...)

q be = Quantum Time for each

P

i

AT be = Arrival Time

BT

be = Burst Time

CT

be = Completion Time

TAT be = Turnaround Time

WT be = Waiting Time

Starting Time is always zero to find CT.

Draw Gantt Chart

with q = 3 milliseconds, ( ms ).

Calculate CT , TAT , WT.

P AT BT CT TAT WT

P

0

0 7???

P

1

2 4???

P

2

4 1???

Drawing Gantt Chart:

Step 0: Start with an empty Gantt Chart. Let RT be =

P

i

’s Remaining Burst Time

and a data structure Queue called PQueue with type

P

i

with q = 3 ms.

Note: The process is enqueue to

PQueue in orderly :

(1) the new process appears at or after its arrival time

(2) the process has remaining burst time (incomplete execution).

The process is dequeue from PQueue to be selectively picked for runtime.

t = 0123456789101112

RT

P

0

7

P

1

4

P

2

1

PQueue →enqueuedequeue→

Step 1: When t = 0 ,

P

0

arrives and is the only process available. Following RR algorithm,

the CPU will check if there is a new process and any other available process. The

new process is

P

0

and there are no other available processes.

P

0

is enqueued.

PQueue P

0

Then the CPU will selectively pick the process to be executed from the Queue. By

dequeuing,

P

0

will be the next process to be executed. And because this algorithm

is preemptive and is RR, this process can only run partial burst time for 3

ms ,

q = 3 , before being paused and resume to complete the remaining duration at

another time.

t = 0123456789101112

RT

P

0

0 7

4

P

1

4

P

2

1

PQueue P

0

Step 2: When

t = 3 ,

P

1

has already arrived and one process (

P

0

) has remaining service time.

Following RR algorithm, the CPU will check if there is a new process and any

other available process. The new process is

P

1

and the other available process is

P

0

.

P

1

and

P

0

are enqueued in order.

PQueue P

0

P

1

P

0

Then the CPU will selectively pick the process to be executed from the Queue. By

dequeuing,

P

1

will be the next process to be executed. And because this algorithm

is preemptive and is RR, it can only run partial burst time for 3

ms ,

q = 3 , before

being paused and resume to complete the remaining duration at another time.

t = 0123456789101112

RT

P

0

0 4

P

1

1 4 → 1

P

2

1

PQueue P

0

P

1

P

0

Step 3: When

t = 6 ,

P

2

has already arrived and one process (

P

1

) has remaining service time.

Following RR algorithm, the CPU will check if there is a new process and any

other available process. The new process is

P

2

and the other available process is

P

1

.

P

2

and

P

1

are enqueued in order.

Note:

P

0

is not available since it is in the

PQueue unless it is dequeued.

PQueue P

1

P

2

P

0

P

1

P

0

t = 0123456789101112

RT

P

0

0 0 1

P

1

1 1 1 → 0

P

2

2 0

PQueue P

0

P

1

P

2

P

0

P

1

P

0

Step 6: When t = 11 ,

P

1

completes and there is no other process available. By dequeuing,

P

0

will be the next process to be executed. And because this algorithm is RR, it can

run the whole duration since its’ burst time is less than or equal to 3

ms (

≤ 3

).

By then,

P

0

completes its service time.

t = 0123456789101112

RT

P

0

0 0 0 1

0

P

1

1 1 0

P

2

2 0

PQueue P

0

P

1

P

2

P

0

P

1

P

0

The Complete Gantt Chart

t = 0123456789101112

RT

P

0

0 0 0 0

P

1

1 1 0

P

2

2 0

PQueue P

0

P

1

P

2

P

0

P

1

P

0

Calculating

CT

,

TAT

,

WT

:

Let

Completion Time (

CT

) be

=

Turnaround Time (

TAT

) be =

Waiting Time ( WT ) be =

for each ms = Finishing Time – Starting Time

for each

ms = Completion Time – Arrival Time

for each ms = Turnaround Time – Burst Time

For

P

0

: Burst Time (

BT

) is 7 milliseconds and Arrival Time (

AT

) is at

t = 0 .

For

P

1

: Burst Time (

BT

) is 4 milliseconds and Arrival Time (

AT

) is at

t = 2 .

For

P

2

: Burst Time ( BT ) is 1 milliseconds and Arrival Time ( AT ) is at t = 4.

t = 0123456789101112

P

0

0 0 0

CT = 12

TAT = 12

WT = 5

P

1

1 1

CT = 11

TAT = 9

WT = 5

P

2

2

CT = 10

TAT = 6

Was this document helpful?

4. RR Scheduling

Course: Operating Systems Principles (CSCI 340)

16 Documents
Students shared 16 documents in this course
Was this document helpful?
asifroni673@gmail.com
(RR) Round Robin ~ Preemptive ~ CPU Scheduling Algorithm
Let
Pi
be = Process
i
where (
i
= 0, 1,
2, 3, …)
q
be = Quantum Time for each
Pi
AT
be = Arrival Time
BT
be = Burst Time
CT
be = Completion Time
TAT
be = Turnaround Time
be = Waiting Time
Starting Time is always zero to find
CT
.
Draw Gantt Chart
with
q=3
milliseconds,
(ms)
.
Calculate
CT
,
TAT
,
.
P
AT
BT
CT
TAT
P0
07???
P1
24???
P2
41???
Drawing Gantt Chart:
Step 0: Start with an empty Gantt Chart. Let
RT
be =
Pi
s Remaining Burst Time
and a data structure Queue called
PQueue
with type
Pi
with
q=3ms
.
Note: The process is enqueue to
PQueue
in orderly:
(1) the new process appears at or after its arrival time
(2) the process has remaining burst time (incomplete execution).
The process is dequeue from
PQueue
to be selectively picked for
runtime.
t=0 12 3 4 5 6 7 8 9 10 11 12
RT
P0
7
P1
4
P2
1
PQueue
enqueue
dequeue
Step 1: When
t=0
,
P0
arrives and is the only process available. Following RR
algorithm, the CPU will check if there is a new process and any other available
process. The new process is
P0
and there are no other available processes.
P0
is enqueued.
PQueue
P0
Then the CPU will selectively pick the process to be executed from the Queue. By