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

CS314 Lab3 Solution

The document discusses CPU scheduling problems and solutions using different scheduling algorithms like FCFS, SJF, RR, and priority scheduling. It provides Gantt charts and calculations for average waiting time and turnaround time for each scheduling algorithm on sample processes. It also provides Linux commands to create directories and files to simulate the directory structure of major cities in Saudi Arabia.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

CS314 Lab3 Solution

The document discusses CPU scheduling problems and solutions using different scheduling algorithms like FCFS, SJF, RR, and priority scheduling. It provides Gantt charts and calculations for average waiting time and turnaround time for each scheduling algorithm on sample processes. It also provides Linux commands to create directories and files to simulate the directory structure of major cities in Saudi Arabia.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Jubail University College

Lab – 3

CS314 Operating System

Semester 391
CPU Scheduling Problems:

1. Assume that you have the following jobs in the ready queue to execute with one
processor, with the jobs arriving in the order listed here:

Process Burst Time (Processi)


0 80
1 20
2 10
3 20
4 50

a. Suppose a system uses FCFS scheduling .Create a Gantt chart illustrating the
execution of these processes?
b. What is the turnaround time for process p3?
c. What is the average wait time for the processes?

P0 P1 P2 P3 P4

20 10 20 50
80

0 80 100 110 130 180

Turnaround time for P3 = 130


Waiting time is the total time in the ready queue.
Formula for calculating waiting time = Turnaround time – burst time – arrive after

Waiting Time for P0 = 80 – 80 – 0 = 0


Waiting Time for P1 = 100 – 20 – 0 = 80
Waiting Time for P2 = 110 – 10 – 0 = 100
Waiting Time for P3 = 130 – 20 -0 = 110
Waiting Time for P4 = 180 – 50 – 0 = 130

Average Waiting Time = (80 + 100 + 110 + 130) / 5 = 84

Q-2: Using the process loaded in the previous problem, suppose a system uses SJF
scheduling.
a. Create a Gantt chart illustrating the execution of these processes?
b. What is the turnaround time for process p4?
c. What is the average wait time for the processes?

P2 P1 P3 P4 P0

10 20 20 50 80

0 10 30 50 100 180
Turnaround time for P4 = 100

Waiting Time for P0 = 180 – 80 – 0 =100


Waiting Time for P1 = 30 -20 – 0 = 10
Waiting Time for P2 = 10 – 10 – 0 = 0
Waiting Time for P3 = 50 – 20 – 0 = 30
Waiting Time for P4 = 100 - 50 – 0 = 50

Average Waiting Time = (100 + 10 + 0+ 30 + 50) / 5 = 38


Q-3: Assume that you have the following jobs to execute with one processor, with the
jobs arriving in the order as per the arrival time listed here:

Process Burst Time Arrival Time


(Processi)
0 80 0
1 20 10
2 10 10
3 20 80
4 50 85
a. Suppose a system uses RR scheduling with a quantum of 15. Create a Gantt
chart illustrating the execution of these processes?
b. What is the turnaround time for process p3, p4 & p1?
c. What is the average wait time for the processes?
d. What is the average turnaround time for the processes?

P0 P1 P2 P0 P1 P0 P3 P4 P0 P3 P4 P0 P4

15 15 15 15 15 15 15 15 15 15 15 15 15

0 15 30 45 60 75 90 105 120 135 150 165 180 195


2

P0 P4

15 15

195 210 225

Turnaround time for P3 = 150 – 80(arrive after) = 70


Turnaround time for P4 = 225 – 85 (arrived after) = 140
Turnaround time for P1 = 75 – 10 (arrived after) = 65
Turnaround time for P0 = 210 – 0(arrive after) = 210
Turnaround time for P2 = 45 – 10 (arrived after) = 35

Average Turnaround time = (70 + 140 + 65 + 210 + 35) / 5 = 104


Waiting time is the total time in the ready queue.

Formula for calculating waiting time = Turnaround time – burst time – arrive after

Waiting Time for P0 = 210 – 80(burst time) – 0 (arrive after) = 130


Waiting Time for P1 = 75 – 20 (burst time) - 10 (arrived after) = 45
Waiting Time for P2 = 45 – 10 (burst time) - 10(arrived after) = 25
Waiting Time for P3 = 150 – 20(burst time) - 80 (arrived after) = 50
Waiting Time for P4 = 225 – 50 (burst time) – 85 (arrived after) = 90

Average Waiting Time = (135 + 35 + 20 + 130 + 140) / 5 = 68

e. Create a grant chart illustrating the execution of these processes with a quantum of
10. Now, find the average wait time and turnaround time for all the processes.

Q-4: Assume that you have the following jobs to execute with one processor, with the
jobs arriving in the order as per the arrival time listed here:

Process Burst Time Priority Arrival Time


P1 8 4 0
P2 6 1 2
P3 1 2 2
P4 9 2 1
P5 3 3 3

a. Suppose a system uses RR scheduling with a quantum of 2. Create a Gantt chart


illustrating the execution of these processes and calculate the average wait time
and turnaround time for all the processes.

b. Suppose a system uses priority scheduling. Create a Gantt chart illustrating the
execution of these processes with non-preemptive and preemptive priority and
calculate the average wait time and turnaround time for all the processes.

Non-Preemptive:

P1 P2 P4 P3 P5

8 6 9 1 3

0 8 14 23 24 27
Turnaround Time for p1 = 8
Turnaround Time for p2 = 14 – 2 (arrived after) = 12
Turnaround Time for p4 = 23 – 1 (arrived after) = 22
Turnaround Time for p3 = 24 – 2 (arrived after) = 22
Turnaround Time for p5 = 27 – 3 (arrived after) = 24

Average Turnaround Time = (8 + 12 + 22 + 22 + 24)/ 5


= 17.6
Formula for calculating waiting time = Turnaround time – burst time – arrive after

Average Waiting Time for P1 = 8 – 8 – 0 = 0


Average Waiting Time for P2 = 14 – 6 - 2 = 6
Average Waiting Time for P3 = 24– 1- 2 = 21
Average Waiting Time for P4 = 23 - 9 - 1 = 13
Average Waiting Time for P5 = 27 – 3 - 3 = 21

Average Waiting Time = (0 + 6 + 21 + 13 + 21) / 5 = 12.2

Preemptive:

P1 P4 P2 P4 P3 P5 P1

1 1 6 8 1 3 7

0 1 2 8 16 17 20 27

Turnaround Time for p1 = 27


Turnaround Time for p2 = 8 - 2 = 6
Turnaround Time for p3 = 17 – 2 = 15
Turnaround Time for p4 = 16 – 2 = 14
Turnaround Time for p5 = 20 – 3 = 17

Average Turnaround Time = (27 + 6 + 15 + 14 + 17)/ 5


= 15.8
Formula for calculating waiting time = Turnaround time – burst time – arrive after

Average Waiting Time for P1 = 27 – 8 – 0 = 19


Average Waiting Time for P2 = 8 - 6 – 2 (arrived after) = 0
Average Waiting Time for P3 = 17 - 1 – 2 (arrived after) = 14
Average Waiting Time for P4 = 16 - 9 - 1(arrived after) = 6
Average Waiting Time for P5 = 20 - 3 – 3 (arrived after = 14

Average Waiting Time = (19+ 0 + 14 + 6 + 14) / 5 = 10.6

c. Compare the two scheduling algorithm in terms of waiting time and turnaround
time.
Linux Lab:

Write Linux command line instructions to do the following:

Home

Lab3

Jeddah Riyad Dammam

Makkah Medina Jubail Qatif

Al-Kharj Al-Daho

Step-1: Create a new directory called “lab3” under your home directory, then cd to lab3. Create
subdirectories called 1) Jeddah, 2) Riyad, and 3) Dammam. Then create 6 subdirectories, 2 under
directory Jeddah called “Makkah” and “Medina”, 2 under directory Riyad called “Al-Kharj” and “Al-
Daho”, and 2 under directory Dammam called “Jubail” and “Qatif”.

Step -2: From Lab3 move to Jubail directory using cd command Create three files using cat
command named as “abubakr.txt”, “umar.txt”, “ali.txt” containing the following texts:

 Abu Bakr was born in Mecca some time in 573 CE, to a rich family in the Banu Taym clan of
the Quraysh tribe. Abu Bakr's father's name was Uthman Abu Quhafa and his mother was Salma
bint Sakhar.

 Umar was born in Mecca to the Banu Adi clan, which was responsible for arbitration among the
tribes. His father was Khattab ibn Nufayl and his mother was Hantama bint Hisham, from the tribe
of Banu Makhzum.
 
 Ali had been living with Muhammad and Muhammad's wife Khadija since he was five years old.
When Ali was nine, Muhammad announced himself as the Prophet of Islam, and Ali became the
first child to accept Islam.
Step-3: Using ls command, check the creation of the three files. Now, copy the file “abubakr.txt” to
“Makkah” directory. Using the ls command check whether copy was successful or not without
changing the directory. Now, copy all the three files to the “Al-Kharj” directory using a single copy
command. Again, using the ls command check whether copy was successful or not without
changing the directory.

Step-4: From the “Jubail” directory move to “Al-Kharj” directory. Copy and rename the three files
from “Al-Kharj” to “Medina” directory renamed as “abubakr_new.txt”, “umar_new.txt”, and
“ali_nex.txt”.

Step-5: Now move to your home directory using a single command. Then, move to the “Jubail”
directory, and delete all the text files that starts with “a” using a single command. Now move to
the parent directory of ”Jubail” and delete the directory “Jubail”.

Step-6: Move to the directory “Medina” and move all the files that ended with “new” using a single
mv command to the directory “Al-Daho”. Using the ls command check whether move was
successful or not without changing the directory. Now, move to the “Al-Daho” directory. Move the
“ali_new.txt” from the “Al-Daho” to “Makkah” directory. Now delete all the files in the “Al-Daho”
that end with “new”.

Step-7: Delete the “Al-Daho and “Medina” directory using a single delete command for each.

You might also like