Solution_Unit2_Assignment
Solution_Unit2_Assignment
PIET/PIT - CSE/IT
Operating System (203105203)
UNIT- 2 ASSIGNMENT - 2
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
2) Consider the following CPU processes with arrival times (in milliseconds)
and length of CPU bursts (in milliseconds) as given below:
P1 = 12-0 = 12
P2 = 6-3 = 3
P3 = 17-5 = 12
P4 = 8 - 6 = 2
Waiting Time
P1 = 12-7 = 5
P2 = 3-3 = 0
P3 = 12-5 = 7
P4 = 2 - 2 = 0
---------------------------------------------------------------------------------------------------------
3) Consider the set of processes with arrival time(in milliseconds), CPU burst
time (in milliseconds), and priority(0 is the highest priority) shown below.
None of the processes have I/O burst time.
The average waiting time (in milliseconds) of all the processes using
preemptive priority scheduling algorithm is _____.
a. 29
b. 30
c. 31
d. 32
Explanation: Turnaround time is the total time taken by the process between
starting and the completion and waiting time is the time for which process is
ready to run but not executed by CPU scheduler. As we know, in all CPU
Scheduling algorithms, shortest job first is optimal i.ie. it gives minimum turn
round time, minimum average waiting time and high throughput and the most
important thing is that shortest remaining time first is the pre-emptive version
of shortest job first. shortest remaining time first scheduling algorithm may
lead to starvation because If the short processes are added to the cpu
scheduler continuously then the currently running process will never be able to
execute as they will get pre-empted but here all the processes are arrived at
same time so there will be no issue such as starvation.
So, the answer is Shortest remaining time first, which is answer (a).
--------------------------------------------------------------------------------------------------------
5) Consider the following processes, with the arrival time and the length of
the CPU burst given in milliseconds. The scheduling algorithm used is
preemptive shortest remaining-time first.
a. 8.25
b. 10.25
c. 6.35
d. 4.25
The processes are scheduled and executed as given in the below Gantt chart.
TAT for P1 = 20 – 0 = 20
TAT for P2 = 10 – 3 = 7
TAT for P3 = 8- 7 = 1
TAT for P4 = 13 – 8 = 5
=( 20 + 7 + 1 + 5 ) / 4 = 33 / 4 = 8.25
---------------------------------------------------------------------------------------------------------
a. N
b. n2
c. 2n
d. Independent of n
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
a. Concurrency
b. Simultaneity
c. Crosscurrent
d. Recurrent
⮚ Solution: Answer is option ( a )
---------------------------------------------------------------------------------------------------------
Arrival
time
Process Priority CPU time required (hh:mm:ss)
P2 9 10 sec 00:00:03
a. 30 sec, 30 sec
b. 30 sec, 10 sec
c. 42 sec, 42 sec
d. 30 sec, 42 sec
---------------------------------------------------------------------------------------------------------
11) Which of the following statements are true?
I. Shortest remaining time first scheduling may cause starvation
II. Preemptive scheduling may cause starvation
III. Round robin is better than FCFS in terms of response time
a. I only
b. I and III only
c. II and III only
d. I, II and III
---------------------------------------------------------------------------------------------------------
a. Round Robin
b. First-In First-Out
c. Multilevel Queue Scheduling
d. Multilevel Queue Scheduling With feedback
---------------------------------------------------------------------------------------------------------
13) Consider a set of n tasks with known runtimes r1, r2, … rn to be run on a
uniprocessor machine. Which of the following processor scheduling
algorithms will result in the maximum throughput?
a. Round-Robin
b. Shortest-Job-First
c. Highest-Response-Ratio-Next
d. First-Come-First-Served
● Explanation:
Throughput means total number of tasks executed per unit time.
shortest Job First has maximum throughput because in this scheduling
technique shortest jobs are executed first hence maximum number of
tasks are completed.
---------------------------------------------------------------------------------------------------------
17) Which of the following level of a thread is the fastest to create and
manage thread?
a. Many-to-Many
b. Kernel
c. Many-to-One
d. User
---------------------------------------------------------------------------------------------------------
18) Which of the following is/are shared by all the threads in a process?
I. Program counter
II. Stack
IV. Registers
a. I and II only
b. III only
c. IV only
d. III and IV only
⮚ Solution : b
---------------------------------------------------------------------------------------------------------
19) Consider an arbitrary set of CPU-bound processes with unequal CPU burst
lengths submitted at the same time to a computer system. Which one of the
following process scheduling algorithms would minimize the average waiting
time in the ready queue?
⮚ Solution : a
---------------------------------------------------------------------------------------------------------
⮚ Solution : d
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
⮚ Solution : c
---------------------------------------------------------------------------------------------------------
23) Interval between the time since submission of the job to the time its
results become available, is called
a. Response Time
b. Throughput
c. Waiting time
d. Turnaround Time
⮚ Solution : a
---------------------------------------------------------------------------------------------------------
⮚ Solution : d
One liner Questions:
1. Process is ________ Activity and Program ____________ Activity.
2. When does a process terminate?
3. List out the name of the section in which process memory can be
divided?
4. What is context Switch?
5. What is Thread?
6. Define Process Scheduling.
7. What is Non Pre-emptive Scheduling and Pre-emptive Scheduling?
Define Throughput, Turnaround time, waiting time, Load Average and
Response Time.
8. Which system call is used for Process Termination?
9. What is Non Pre-emptive Scheduling and Pre-emptive Scheduling?
10. What is Convoy Effect ?
Subjective Questions:
1. Write Difference Between Program and Process.
2. Explain Process States with Diagram.
3. Explain Process Control Block.
4. Write Difference Between Thread and Process.
5. Differentiate between User Level Thread and Kernel Level Thread.
6. Advantages and disadvantages of User Level and Kernel Level Threads.
7. Define Throughput, Turnaround time, waiting time, Response Time,
Load Average.
8. Difference between Long Term, Short Term, Medium Term Schedulers.
Examples :
(1) Consider the following Processes with CPU execution time.Calculate the
average Waiting time and average turnaround time .
P1 0 2
P2 1 3
P3 2 5
P4 3 4
P5 4 6
Solution:
(2) We have 4 processes with process ID P0, P1, P2, and P3. The arrival time of
P0 is 0, P1 is 1, P2 is 2, and P3 is 3. The arrival time and burst time of the
processes are given in the following table. Calculate the average Waiting time
and average turnaround time .
P0 0 6
P1 1 8
P2 2 10
P3 3 12
Solution :
Process Arrival Burst Completion Turnaround
Waiting Time
ID Time Time Time Time
P0 0 6 6 6 0
P1 1 8 14 13 5
P2 2 10 24 22 12
P3 3 12 36 33 21
(2) Consider the set of 6 processes whose arrival time and burst time are given
below.
P1 0 3
P2 1 2
P3 2 1
P4 3 5
P5 4 4
P6 5 2
Gantt Chart-
= 17 unit / 23 unit
= 0.7391 = 73.91%
(3) Consider the set of 5 processes whose arrival time and burst time are given
below-
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
Solution-
Gantt Chart-
P1 7 7–3=4 4–1=3
P2 16 16 – 1 = 15 15 – 4 = 11
P3 9 9–4=5 5–2=3
P4 6 6–0=6 6–6=0
P5 12 12 – 2 = 10 10 – 3 = 7
Now,
● Average Turn Around time = (4 + 15 + 5 + 6 + 10) / 5 = 40 / 5 = 8 unit
● Average waiting time = (3 + 11 + 3 + 0 + 7) / 5 = 24 / 5 = 4.8 unit
(4) Consider the set of 5 processes whose arrival time and burst time are given
below-
P1 3 1
P2 1 4
P3 4 2
P4 0 6
P5 2 3
If the CPU scheduling policy is SJF preemptive, calculate the average waiting
time and average turn around time.
Solution-
Gantt Chart-
Process
Exit time Turn Around time Waiting time
Id
P1 4 4–3=1 1–1=0
P2 6 6–1=5 5–4=1
P3 8 8–4=4 4–2=2
P4 16 16 – 0 = 16 16 – 6 = 10
P5 11 11 – 2 = 9 9–3=6
(5) Consider the set of 3 processes whose arrival time and burst time are given
below- If the CPU scheduling policy is SRTF, calculate the average waiting time
and average turn around time.
P1 0 9
P2 1 4
P3 2 9
Solution-
Gantt Chart-
P1 13 13 – 0 = 13 13 – 9 = 4
P2 5 5–1=4 4–4=0
P3 22 22- 2 = 20 20 – 9 = 11
Now,
● Average Turn Around time = (13 + 4 + 20) / 3 = 37 / 3 = 12.33 unit
● Average waiting time = (4 + 0 + 11) / 3 = 15 / 3 = 5 unit
(6) Consider the set of 5 processes whose arrival time and burst time are given
below-
P1 0 5
P2 1 3
P3 2 1
P4 3 2
P5 4 3
If the CPU scheduling policy is Round Robin with time quantum = 2 unit,
calculate the average waiting time and average turn around time.
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given
below-
P1 0 5
P2 1 3
P3 2 1
P4 3 2
P5 4 3
If the CPU scheduling policy is Round Robin with time quantum = 2 unit, calculate
the average waiting time and average turn around time.
Solution-
Gantt Chart-
Ready Queue-
P5, P1, P2, P5, P4, P1, P3, P2, P1
P1 13 13 – 0 = 13 13 – 5 = 8
P2 12 12 – 1 = 11 11 – 3 = 8
P3 5 5–2=3 3–1=2
P4 9 9–3=6 6–2=4
P5 14 14 – 4 = 10 10 – 3 = 7
P1 5 5
P2 4 6
P3 3 7
P4 1 9
P5 2 2
P6 6 3
If the CPU scheduling policy is Round Robin with time quantum = 3, calculate
the average waiting time and average turn around time.
Solution-
Gantt chart-
Ready Queue-
P3, P1, P4, P2, P3, P6, P1, P4, P2, P3, P5, P4
Process Id Exit time Turn Around time Waiting time
P1 32 32 – 5 = 27 27 – 5 = 22
P2 27 27 – 4 = 23 23 – 6 = 17
P3 33 33 – 3 = 30 30 – 7 = 23
P4 30 30 – 1 = 29 29 – 9 = 20
P5 6 6–2=4 4–2=2
P6 21 21 – 6 = 15 15 – 3 = 12
Now,
● Average Turn Around time = (27 + 23 + 30 + 29 + 4 + 15) / 6 = 128 / 6 = 21.33
unit
● Average waiting time = (22 + 17 + 23 + 20 + 2 + 12) / 6 = 96 / 6 = 16 unit