CS314 Lab3 Solution
CS314 Lab3 Solution
Lab – 3
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:
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
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
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
P0 P4
15 15
Formula for calculating waiting time = Turnaround time – burst time – arrive after
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:
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
Preemptive:
P1 P4 P2 P4 P3 P5 P1
1 1 6 8 1 3 7
0 1 2 8 16 17 20 27
c. Compare the two scheduling algorithm in terms of waiting time and turnaround
time.
Linux Lab:
Home
Lab3
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.