0% found this document useful (0 votes)
5 views11 pages

Os Batch 12

The document discusses scheduling concepts using Gantt charts, focusing on two threads, T1 and T2, and their response times under different scheduling scenarios: non-preemptive, preemptive, and round-robin. It provides detailed calculations for response times and average response times for each case. Additionally, it includes Python code for plotting Gantt charts to visualize the execution timelines of the threads.

Uploaded by

mutahhar82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

Os Batch 12

The document discusses scheduling concepts using Gantt charts, focusing on two threads, T1 and T2, and their response times under different scheduling scenarios: non-preemptive, preemptive, and round-robin. It provides detailed calculations for response times and average response times for each case. Additionally, it includes Python code for plotting Gantt charts to visualize the execution timelines of the threads.

Uploaded by

mutahhar82
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

OPERATING

SYSTEM
Submitted to: Mr.Sikindhar
BATCH -12

REGDNO NAME
231FA04401 BHARGAV
231FA04B15 SHIVA
231FA04C73 ABHIRAM
231FA04D69 GOWTHAM
QUESTION
Gantt charts, which I introduced in the context of hard-real-time scheduling,
can also be used to illustrate other scheduling concepts, such as those
concerning response time. Suppose thread T1 is triggered by an event at
time 0 and needs to run for 1.5 seconds before it can respond. Suppose
thread T2 is triggered by an event occurring 0.3 seconds later than T1's
trigger, and that T2 needs to run 0.2 seconds before it can respond. Draw a
Gantt chart for each of the following three cases, and for each indicate the
response time of T1, the response time of T2, and the average response
time:
a) T1 is allowed to run to completion before T2 is run.
b) T1 is pre-empted when T2 is triggered; only after T2 has completed does
T1 resume. T1 is preempted when T2 is triggered; the two threads are then
executed in a round-robin fashion (starting with T2), until one of them
completes. The time slice (or quantum) is .05 seconds.
c) What is the Average Response Time for both Non-Preemptive Scheduling
and Preemptive Scheduling algorithms?
a) Non-Preemptive Scheduling (T1 Runs to Completion Before T2)
In this case, T1 runs to completion first before T2 starts. The timeline can
be divided as follows:-
 T1 Execution:
T1 starts at time t=0t = 0t=0 and runs for 1.5 seconds until t=1.5t =
1.5t=1.5.
 T2 Execution:
T2 starts after T1 completes, at t=1.5t = 1.5t=1.5, and runs for 0.2
seconds until t=1.7t = 1.7t=1.7.
 Response Times:
 T1 Response Time: 1.51.51.5 seconds (finishes at t=1.5t = 1.5t=1.5).
 T2 Response Time: 1.7−0.3=1.41.7 - 0.3 = 1.41.7−0.3=1.4 seconds.
 Average=T1 Response Time+T2 Response / 2
 Time​=1.5 + 1.4 ​/ 2 = 1.45 seconds
 B) Case b: Preemptive Scheduling (T1 is preempted when T2 is
triggered)
 T1 Execution:
T1 starts at t=0t = 0t=0 and runs until t=0.3t = 0.3t=0.3, when T2 is
triggered.
 T2 Execution:
T2 preempts T1 and runs from t=0.3t = 0.3t=0.3 to t=0.5t = 0.5t=0.5
(0.2 seconds).
 T1 Resumption:
T1 resumes at t=0.5t = 0.5t=0.5 and completes its remaining execution
by t=1.7t = 1.7t=1.7.
 Response Times:
 T1 Response Time: 1.71.71.7 seconds (finishes at t=1.7t = 1.7t=1.7).
 T2 Response Time: 0.5−0.3=0.20.5 - 0.3 = 0.20.5−0.3=0.2 seconds.
 Average Response Time:

Average=T1 Response Time+T2 Response / 2


 21.7+0.2​/ 2 = 0.95 seconds
C) Execution Process:
•T1 starts at t=0t = 0t=0 and runs until t=0.05t = 0.05t=0.05.
•T2 is triggered at t=0.3t = 0.3t=0.3 and preempts T1 after the quantum
of 0.05 seconds.
•After t=0.3t = 0.3t=0.3, T1 and T2 alternate every 0.05 seconds until
each thread completes its execution.
•Execution Timeline:
•T1: Needs 1.5 seconds total, and runs in alternating 0.05s chunks.
•T2: Needs 0.2 seconds and completes quickly due to shorter runtime.
 Response Times:
 T1 Response Time: Time it takes for T1 to complete (approx.
t=1.8t = 1.8t=1.8).
 T2 Response Time: Time it takes for T2 to complete (approx.
t=0.5t = 0.5t=0.5).
CODE import matplotlib.pyplot as plt
def plot_gantt_chart(tasks, title):
fig, ax = plt.subplots(figsize=(10, 2))
for task in tasks:
ax.broken_barh(task['intervals'], (task['y_pos'], 9), facecolors=task['color'],
label=task['label'])
ax.set_ylim(0, 30)
ax.set_xlim(0, 2)
ax.set_xlabel('Time (s)')
ax.set_yticks([])
ax.set_title(title)
ax.legend()
plt.show()
tasks_a = [
{"intervals": [(0, 1.5)], "y_pos": 15, "color": 'blue', "label": 'T1'},
{"intervals": [(1.5, 0.2)], "y_pos": 5, "color": 'orange', "label": 'T2'}
]
plot_gantt_chart(tasks_a, "Case a: Non-Preemptive Scheduling")
tasks_b = [
{"intervals": [(0, 0.3), (0.5, 1.2)], "y_pos": 15, "color": 'blue', "label": 'T1'},
{"intervals": [(0.3, 0.2)], "y_pos": 5, "color": 'orange', "label": 'T2'}
]
plot_gantt_chart(tasks_b, "Case b: Preemptive Scheduling")

# Case c: Round-robin scheduling


tasks_c = [
{"intervals": [(0, 0.05), (0.1, 0.05), (0.2, 0.05), (0.3, 0.05), (0.4, 0.05), (0.5,
0.05), (0.6, 0.05),
(0.7, 0.05), (0.8, 0.05), (0.9, 0.05), (1.0, 0.05), (1.1, 0.05), (1.2,
0.05), (1.3, 0.05),
(1.4, 0.05), (1.5, 0.05)], "y_pos": 15, "color": 'blue', "label": 'T1'},
{"intervals": [(0.05, 0.05), (0.15, 0.05), (0.25, 0.05), (0.35, 0.05)], "y_pos": 5,
"color": 'orange', "label": 'T2'}
]
plot_gantt_chart(tasks_c, "Case c: Round-Robin Scheduling")
output
A)

B)
C)
THANK YOU

You might also like