0% found this document useful (0 votes)
6 views

Operating System Overview2

Uploaded by

Shyamali Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Operating System Overview2

Uploaded by

Shyamali Sarkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

i) Gantt Charts

1. Non-Preemptive Priority Scheduling

Priority Order (lower number indicates higher priority):


P2 (priority 1)
P5 (priority 2)
P1 (priority 3)
P3 (priority 3)
P4 (priority 4)

Gantt Chart:

| P2 | P5 | P1 | P3 | P4 |
0 1 2 12 14 15

Execution Sequence:

1. P2 starts execution at time 1 and finishes at time 2.


2. P5 starts execution at time 2 and finishes at time 7.
3. P1 starts execution at time 7 and finishes at time 17.
4. P3 starts execution at time 17 and finishes at time 19.
5. P4 starts execution at time 19 and finishes at time 20.

2. Round Robin Scheduling (Quantum = 1)

Gantt Chart:

| P1 | P2 | P3 | P4 | P1 | P5 | P1 | P5 | P1 | P5 | P1 |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

Execution Sequence:

1. P1 runs for 1 ms (total 1).


2. P2 runs for 1 ms and finishes (total 2).
3. P3 runs for 1 ms (total 3).
4. P4 runs for 1 ms and finishes (total 4).
5. P1 runs for 1 ms (total 5).
6. P5 runs for 1 ms (total 6).
7. Repeat until all processes are finished.

ii) Turnaround Time Calculation

Turnaround Time (TAT) = Completion Time - Arrival Time

Non-Preemptive Priority Scheduling

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 21/90
Completion Times:
P1: 17
P2: 2
P3: 19
P4: 20
P5: 7

Process Turnaround Time (TAT) Calculation


P1 17 17 - 0 = 17
P2 1 2-1=1
P3 17 19 - 2 = 17

P4 18 20 - 2 = 18
P5 4 7-3=4

Average Turnaround Time = (17 + 1 + 17 + 18 + 4) / 5 = 11.4 ms

Round Robin Scheduling

Completion Times:
P1: 14
P2: 2
P3: 4
P4: 4
P5: 15

Process Turnaround Time (TAT) Calculation


P1 14 14 - 0 = 14

P2 1 2-1=1
P3 2 4-2=2
P4 2 4-2=2
P5 12 15 - 3 = 12

Average Turnaround Time = (14 + 1 + 2 + 2 + 12) / 5 = 6.2 ms

iii) Average Waiting Time Calculation

Waiting Time (WT) = Turnaround Time (TAT) - Burst Time

Non-Preemptive Priority Scheduling

Process Waiting Time (WT) Calculation


P1 7 17 - 10 = 7

P2 0 1-1=0
P3 15 17 - 2 = 15
P4 17 18 - 1 = 17
P5 2 4-5=2

Average Waiting Time = (7 + 0 + 15 + 17 + 2) / 5 = 8.2 ms

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 22/90
Round Robin Scheduling

Process Waiting Time (WT) Calculation


P1 4 14 - 10 = 4
P2 0 1-1=0
P3 0 2-2=0
P4 0 2-1=0
P5 7 12 - 5 = 7

Average Waiting Time = (4 + 0 + 0 + 0 + 7) / 5 = 2.2 ms

Summary

Non-Preemptive Priority Scheduling:


Average Turnaround Time: 11.4 ms
Average Waiting Time: 8.2 ms
Round Robin Scheduling (Quantum = 1):
Average Turnaround Time: 6.2 ms
Average Waiting Time: 2.2 ms

To analyze the given set of processes with their CPU burst times, we will create Gantt charts for both
First-Come-First-Serve (FCFS) and Round Robin (RR) scheduling with a time quantum of 5 milliseconds.
We will also calculate the average waiting time for each scheduling method.

Given Data

Process Burst Time (ms)


P1 15
P2 5
P3 7

P4 10

i) Gantt Chart for FCFS Scheduling

Execution Order: Processes execute in the order of their arrival.


Gantt Chart:

| P1 | P2 | P3 | P4 |
0 15 20 27 37

Completion Times:

P1: 15 ms
P2: 20 ms

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 23/90
P3: 27 ms
P4: 37 ms

ii) Waiting Time Calculation for FCFS

Waiting Time (WT) = Completion Time - Burst Time

Process Completion Time Burst Time Waiting Time (WT)


P1 15 15 15 - 15 = 0

P2 20 5 20 - 5 = 15
P3 27 7 27 - 7 = 20
P4 37 10 37 - 10 = 27

Average Waiting Time (FCFS) = (0 + 15 + 20 + 27) / 4 = 15.5 ms

iii) Gantt Chart for Round Robin Scheduling (Quantum = 5 ms)

Execution Order: Each process runs for 5 ms until completion. If a process does not finish within the
time quantum, it goes back to the queue.
Gantt Chart:

| P1 | P2 | P3 | P4 | P1 | P3 | P4 |
0 5 10 15 20 25 30 37

Execution Breakdown:

1. P1 runs for 5 ms (remaining 10 ms).


2. P2 runs for 5 ms (completes).
3. P3 runs for 5 ms (remaining 2 ms).
4. P4 runs for 5 ms (remaining 5 ms).
5. P1 runs for 5 ms (remaining 5 ms).
6. P3 runs for 2 ms (completes).
7. P4 runs for 5 ms (completes).

iv) Waiting Time Calculation for RR Scheduling

Completion Times:

P1: 30 ms
P2: 10 ms
P3: 27 ms
P4: 37 ms

Process Completion Time Burst Time Waiting Time (WT)


P1 30 15 30 - 15 = 15
P2 10 5 10 - 5 = 5
P3 27 7 27 - 7 = 20
P4 37 10 37 - 10 = 27

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 24/90
Average Waiting Time (RR) = (15 + 5 + 20 + 27) / 4 = 16.75 ms

Summary

FCFS Scheduling:
Average Waiting Time: 15.5 ms
Round Robin Scheduling (Quantum = 5 ms):
Average Waiting Time: 16.75 ms

To calculate the average turnaround time and average waiting time for the given processes using Round
Robin (RR) scheduling with a time quantum of 2 milliseconds and Shortest Remaining Time First (SRTF)
scheduling, we will follow these steps:

Given Data

Process Arrival Time Burst Time


P1 0 3
P2 1 6
P3 4 4
P4 6 2

1. Round Robin (RR) Scheduling (Quantum = 2 ms)

Gantt Chart

1. Execution Sequence:
Time 0: P1 runs for 2 ms (remaining 1 ms).
Time 2: P2 runs for 2 ms (remaining 4 ms).
Time 4: P1 runs for 1 ms (completes).
Time 5: P3 runs for 2 ms (remaining 2 ms).
Time 7: P4 runs for 2 ms (completes).
Time 9: P2 runs for 2 ms (remaining 2 ms).
Time 11: P3 runs for 2 ms (completes).
Time 13: P2 runs for 2 ms (completes).

Gantt Chart:

| P1 | P2 | P1 | P3 | P4 | P2 | P3 | P2 |
0 2 4 5 7 9 11 13 15

Completion Times

P1: 4 ms
P2: 15 ms
P3: 13 ms
P4: 9 ms
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 25/90
Turnaround Time (TAT)

Turnaround Time (TAT) = Completion Time - Arrival Time

Process Completion Time Arrival Time TAT (ms)


P1 4 0 4-0=4
P2 15 1 15 - 1 = 14
P3 13 4 13 - 4 = 9

P4 9 6 9-6=3

Average Turnaround Time (RR) = (4 + 14 + 9 + 3) / 4 = 7.5 ms

Waiting Time (WT)

Waiting Time (WT) = Turnaround Time (TAT) - Burst Time

Process TAT (ms) Burst Time WT (ms)

P1 4 3 4-3=1
P2 14 6 14 - 6 = 8
P3 9 4 9-4=5
P4 3 2 3-2=1

Average Waiting Time (RR) = (1 + 8 + 5 + 1) / 4 = 3.75 ms

Summary for Round Robin Scheduling:

Average Turnaround Time (RR): 7.5 ms


Average Waiting Time (RR): 3.75 ms

2. Shortest Remaining Time First (SRTF) Scheduling

Gantt Chart

1. Execution Sequence:
Time 0: P1 runs (remaining 3 ms).
Time 1: P2 arrives (remaining 6 ms).
Time 4: P3 arrives (remaining 4 ms).
Time 6: P4 arrives (remaining 2 ms).
Time 6: P4 runs (completes) as it has the shortest remaining time.
Time 8: P1 runs (remaining 1 ms).
Time 9: P2 runs (remaining 4 ms).
Time 11: P3 runs (remaining 2 ms).
Time 13: P2 runs (completes).

Gantt Chart:

| P1 | P4 | P1 | P2 | P3 | P2 |
0 1 4 6 8 11 13 15

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 26/90
Completion Times

P1: 8 ms
P2: 15 ms
P3: 13 ms
P4: 6 ms

Turnaround Time (TAT)

Turnaround Time (TAT) = Completion Time - Arrival Time

Process Completion Time Arrival Time TAT (ms)


P1 8 0 8-0=8
P2 15 1 15 - 1 = 14
P3 13 4 13 - 4 = 9
P4 6 6 6-6=0

Average Turnaround Time (SRTF) = (8 + 14 + 9 + 0) / 4 = 7.75 ms

Waiting Time (WT)

Waiting Time (WT) = Turnaround Time (TAT) - Burst Time

Process TAT (ms) Burst Time WT (ms)


P1 8 3 8-3=5

P2 14 6 14 - 6 = 8
P3 9 4 9-4=5
P4 0 2 0 - 2 = -2 (not possible, but it finished immediately)

Since P4 finished immediately, we can set its waiting time to 0.


Average Waiting Time (SRTF) = (5 + 8 + 5 + 0) / 4 = 4.5 ms

Summary for SRTF Scheduling:

Average Turnaround Time (SRTF): 7.75 ms


Average Waiting Time (SRTF): 4.5 ms

Final Results:

Round Robin (Quantum = 2 ms):


Average Turnaround Time: 7.5 ms
Average Waiting Time: 3.75 ms
Shortest Remaining Time First (SRTF):
Average Turnaround Time: 7.75 ms
Average Waiting Time: 4.5 ms

To analyze the given set of processes with their CPU burst times, we will create Gantt charts for both
First-Come-First-Serve (FCFS) and Round Robin (RR) scheduling with a time quantum of 5 milliseconds.

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 27/90
We will also calculate the average waiting time for each scheduling method.

Given Data

Process Burst Time (ms)


P1 15
P2 5

P3 7
P4 10

1. First-Come-First-Serve (FCFS) Scheduling

Gantt Chart

Execution Order: Processes execute in the order of their arrival.

Gantt Chart:

| P1 | P2 | P3 | P4 |
0 15 20 27 37

Completion Times:

P1: 15 ms
P2: 20 ms
P3: 27 ms
P4: 37 ms

Waiting Time Calculation for FCFS

Waiting Time (WT) = Completion Time - Burst Time

Process Completion Time Burst Time Waiting Time (WT)


P1 15 15 15 - 15 = 0
P2 20 5 20 - 5 = 15
P3 27 7 27 - 7 = 20
P4 37 10 37 - 10 = 27

Average Waiting Time (FCFS) = (0 + 15 + 20 + 27) / 4 = 15.5 ms

Summary for FCFS Scheduling:

Average Waiting Time (FCFS): 15.5 ms

2. Round Robin (RR) Scheduling (Quantum = 5 ms)

Gantt Chart

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 28/90
Execution Order: Each process runs for 5 ms until completion. If a process does not finish within the
time quantum, it goes back to the queue.
Execution Breakdown:

1. Time 0: P1 runs for 5 ms (remaining 10 ms).


2. Time 5: P2 runs for 5 ms (completes).
3. Time 10: P3 runs for 5 ms (remaining 2 ms).
4. Time 15: P4 runs for 5 ms (remaining 5 ms).
5. Time 20: P1 runs for 5 ms (remaining 5 ms).
6. Time 25: P3 runs for 2 ms (completes).
7. Time 27: P4 runs for 5 ms (completes).
8. Time 32: P1 runs for 5 ms (completes).

Gantt Chart:

| P1 | P2 | P3 | P4 | P1 | P3 | P4 |
0 5 10 15 20 25 27 32

Completion Times

P1: 32 ms
P2: 10 ms
P3: 27 ms
P4: 30 ms

Waiting Time Calculation for RR

Completion Times:

P1: 32 ms
P2: 10 ms
P3: 27 ms
P4: 30 ms

Waiting Time (WT) = Completion Time - Burst Time

Process Completion Time Burst Time Waiting Time (WT)


P1 32 15 32 - 15 = 17
P2 10 5 10 - 5 = 5
P3 27 7 27 - 7 = 20

P4 30 10 30 - 10 = 20

Average Waiting Time (RR) = (17 + 5 + 20 + 20) / 4 = 15.5 ms

Summary for Round Robin Scheduling:

Average Waiting Time (RR): 15.5 ms

Final Results:
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 29/90
FCFS Scheduling:
Average Waiting Time: 15.5 ms
Round Robin Scheduling (Quantum = 5 ms):
Average Waiting Time: 15.5 ms

Both FCFS and Round Robin (with a quantum of 5 ms) yield the same average waiting time in this
scenario.

To analyze the given processes using different scheduling algorithms (FCFS, SJF, SRTF, and Round Robin),
we'll create Gantt charts for each and calculate the average turnaround time (TAT) and average waiting
time (WT) for all the processes.

Given Data

Process Arrival Time (AT) Burst Time (BT)


A 0 8
B 1 4
C 2 9
D 3 5

1. First-Come-First-Serve (FCFS)

Gantt Chart

The order of execution is based on the arrival time:

css

| A | B | C | D |
0 8 12 21 26

Completion Times

A: 8
B: 12
C: 21
D: 26

Turnaround Time (TAT) and Waiting Time (WT) Calculation

TAT = Completion Time - Arrival Time


WT = TAT - Burst Time

Process Completion Time Arrival Time Burst Time Turnaround Time Waiting Time
A 8 0 8 8-0=8 8-8=0

Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 30/90

You might also like