11/24/19

Problems of Operating System Numerical



PROBLEMS of Operating System Unit: 02

Before going to problems we will discuss some abbreviations and their meaning are as follows: -

   1.   TAT           Turn Around Time
   2.   BT             Burst Time
   3.   AT             Arrival Time
   4.   WT            Waiting Time
   5.   FT/CT       Finish Time / Completion Time

Some basic formula that we use: -

  1.  Turn Around Time(TAT) = Completion time (CT) – Arrival Time (AT)
  2.  Waiting Time (WT) = Turn Around Time (TAT) – Burst Time (BT)
Problem 1.1: -
Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
Burst time
P0
0
2
P1
2
3
P2
4
6
P3
6
4
P4
8
5

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
    1.  FCFS
    2.  SJF
    3.  Round Robin (Quantum = 2)
                    
SOLUTION: -

1.  Using FCFS: -
Using FCFS first we have to prepare GANTT CHART which is as follow: -
 Gantt chart: -







Now we can say that: -
1.   2 is the completion time of P0 (process 0)
2.   5 is the completion time of P1 (processn1)
3.   11 is the completion time of P2 (process 2)
4.   15 is the completion time of P3 (process 3)
5.   20 is the completion time of P4 (process 4)

                      
Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P0
0
2
2
2-0= 2
2-2= 0
P1
2
3
5
5-2= 3
3-3= 0
P2
4
6
11
11-4= 7
7-6= 1
P3
6
4
15
15-6= 9
9-4= 5
P4
8
5
20
20-8= 12
12-5= 7
Total number of process= 5
TAT= 33
WT= 13

Average Turnaround Time= Total TAT/ Number of process
                                           = (33/5)
                                           =6.6 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (13/5)
                                           =2.6 Milliseconds




2.  Using SJN (preemptive type): -

Using SJN first we have to prepare GANTT CHART which is as follow: -
          

           Gantt chart: -




NOTE: - First add smallest AT and it’s BT, then selects the smallest BT from the table in ascending order and prepare GANTT CHART.              

Now we can say that: -
   1.   2 is the completion time of P0 (process 0)
   2.   5 is the completion time of P1 (processn1)
   3.   20 is the completion time of P2 (process 2)
   4.   9  is the completion time of P3 (process 3)
   5.   14 is the completion time of P4 (process 4)

                      
Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P0
0
2
2
2-0= 2
2-2= 0
P1
2
3
5
5-2= 3
3-3= 0
P2
4
6
20
20-4= 16
16-6= 10
P3
6
4
9
9-6= 3
3-4= 1
P4
8
5
14
14-8= 6
6-5= 1
Total number of process= 5
TAT= 30
WT= 12

Average Turnaround Time= Total TAT/ Number of process
                                           = (30/5)
                                           =6.0 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (12/5)
                                           =2.4 Milliseconds



3.    Round Robin (Quantum time/time-slice= 2)
 Quantum is allocated to each process for execution. (it is in milliseconds)




Now we can say that: -
1.   2 is the completion time of P0 (process 0)
2.   11 is the completion time of P1 (processn1)
3.   19 is the completion time of P2 (process 2)
4.   15 is the completion time of P3 (process 3)
5.   20 is the completion time of P4 (process 4)


Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P0
0
2
2
2-0= 2
2-2= 0
P1
2
3
11
11-2= 9
9-3= 6
P2
4
6
19
19-4= 15
15-6= 9
P3
6
4
15
15-6= 9
9-4= 5
P4
8
5
20
20-8= 12
12-5= 7
Total number of process= 5
TAT= 47
WT= 27

Average Turnaround Time= Total TAT/ Number of process
                                           = (47/5)
                                           =9.4 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (27/5)
                                           =5.4 Milliseconds



Problem 1.2: -(Try yourself)

Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
CPU Burst time
P0
0
4
P1
1
6
P2
3
3
P3
9
6
P4
12
6

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
   1.  FCFS
   2.  SJF
   3.  Round Robin (Quantum = 2) 
   Answer: -
       1. FCFS: -
                  
                      Average Turnaround Time =9.2 Milliseconds
       
                                         
                      Average Turnaround Time= 4.2 Milliseconds

       2. SJN: -
                  
                      Average Turnaround Time = 8.6 Milliseconds
       
                                         
                      Average Turnaround Time= 3.6 Milliseconds

       3. Round Robin: -
                  
                      Average Turnaround Time =  Milliseconds
       
                                         
                      Average Turnaround Time Milliseconds

                                        


Problem 1.3: -(Try yourself)

Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
CPU Burst time
P0
0
3
P1
1
5
P2
3
2
P3
9
5
P4
12
5

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
Use Non-preemptive and Preemptive both type scheduling
   1.  FCFS
   2.  SJF
   3.  Round Robin (Quantum = 2)
    NOTE:- Both preemptive and non-preemptive have same result.                          Average         waiting time for SJN is small as compare to FCFS so SJN scheduling is best.

      Answer: -       1. FCFS: -
                  
                      Average Turnaround Time =6.2 Milliseconds
       
                                         
                      Average Turnaround Time= 2.2 Milliseconds

       2. SJN: -
                  
                      Average Turnaround Time = 5.6 Milliseconds
       
                                         
                      Average Turnaround Time= 1.6 Milliseconds

       3. Round Robin: -
                  
                      Average Turnaround Time =  Milliseconds
       
                                         
                      Average Turnaround Time Milliseconds

Problem 1.4: -(Try yourself)

Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
CPU Burst time
P0
0
1
P1
1
9
P2
2
1
P3
3
9
Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
    1.  FCFS
    2.  SJF

    Answer: -
       1. FCFS: -
                  
                      Average Turnaround Time =9.0 Milliseconds
       
                                         
                      Average Turnaround Time= 4.0 Milliseconds

       2. SJN: -
                  
                      Average Turnaround Time = 7.25 Milliseconds
       
                                         
                      Average Turnaround Time= 2.5 Milliseconds

     
Problem 1.5: -

Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
CPU Burst time
P1
0
6
P2
0
8
P3
0
7
P4
0
3

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
1.  SJF (Use Non-preemptive Scheduling)

Solution: -
Using SJF scheduling, we would schedule these processes according to the following GANT CHART: -
Gantt chart: -
P4
P1
P3
P2
             0                      3                   9                          16                      24  
 
The waiting time for the above Gantt Chart is as follows: -
1.   3 milliseconds for process P1,
2.   16 milliseconds for process P2,
3.   9 milliseconds for process P3,
4.   0 milliseconds for process P4.
Average waiting time = (3+16+9+0)/4
                                  = 28/4
                                  = 7 milliseconds
Similarly, we can calculate Average TAT, And FCFS AWT & ATAT.


Problem 1.6: - (Try yourself)
Consider the following snapshot of an OS with 4 processes:
Process
Arrival Time
CPU Burst time
P1
0
8
P2
1
4
P3
2
9
P4
3
35

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
1.  SJF (Use  Non-preemptive Scheduling)

Problem 1.7: -
Consider the following snapshot of an OS with 5 processes:
Process
Burst Time
Priority
P1
                  10
3
P2
1
1
P3
2
3
P4
1
4
P5
5
2

This process are assumed to have arrived on the order P1,P2,P3,P4 and P5, all at time 0.(means arrival time of each process is 0)
Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
   1.  FCFS
   2.  SJF
   3.  Priority scheduling
   4.  Round Robin (Quantum = 2) 

       
SOLUTION: -
In the problem priority of processes are given but in the FCFS, SJF, and RR there is no need of priority. We are additionally solving this problem for priority scheduling.
Using FCFS: -
Using FCFS first we have to prepare GANTT CHART which is as follow: -
           Gantt chart: -



Now we can say that: -
1.   10 is the completion time of P1 (process 1)
2.   11 is the completion time of P2 (processn2)
3.   13 is the completion time of P3 (process 3)
4.   14 is the completion time of P4 (process 4)
5.   19 is the completion time of P5 (process 5)

                      
Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P1
0
10
10
10-0=10
10-10= 0
P2
0
1
11
11-0=11
11-1= 10
P3
0
2
13
13-0=13
13-2= 11
P4
0
1
14
14-0=14
14-1= 13
P5
0
5
19
19-0=19
19-5= 14
Total number of process= 5
TAT= 67
WT= 48

Average Turnaround Time= Total TAT/ Number of process
                                           = (67/5)
                                           =13.4 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (48/5)
                                           =9.6 Milliseconds
Using SJN: -

Using SJN first we have to prepare GANTT CHART which is as follow: -
           Gantt chart: -


NOTE: - First add smallest AT and it’s BT, then selects the smallest BT from the table in ascending order and prepare GANTT CHART.              
Now we can say that: -
1.   19 is the completion time of P1 (process 1)
2.   1 is the completion time of P2 (processn2)
3.   4 is the completion time of P3 (process 3)
4.   2 is the completion time of P4 (process 4)
5.   9 is the completion time of P5 (process 5)
Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P1
0
10
19
19-0=19
19-10= 9
P2
0
1
1
1-0=1
1-1= 0
P3
0
2
4
4-0=4
4-2= 2
P4
0
1
2
2-0=2
2-1= 1
P5
0
5
9
9-0=9
9-5= 4
Total number of process= 5
TAT= 35
WT= 16

Average Turnaround Time= Total TAT/ Number of process
                                           = (35/5)
                                           =7.0 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (16/5)
                                           =3.2 Milliseconds


Priority Scheduling: -

Using the priority scheduling first we have to prepare GANTT CHART, according to the priority given in the table which is as follow: -
           Gantt chart: -



NOTE: - First add smallest AT and it’s BT, then selects the smallest BT from the table in ascending order and prepare GANTT CHART.              
Now we can say that: -
1.   16 is the completion time of P1 (process 1)
2.   1 is the completion time of P2 (processn2)
3.   18 is the completion time of P3 (process 3)
4.   19 is the completion time of P4 (process 4)
5.   6 is the completion time of P5 (process 5)

Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P1
0
10
16
16-0=16
16-10= 6
P2
0
1
1
1-0=1
1-1= 0
P3
0
2
18
18-0=18
18-2= 16
P4
0
1
19
19-0=19
19-1= 18
P5
0
5
6
6-0=6
6-5= 1
Total number of process= 5
TAT= 60
WT= 50

Average Turnaround Time= Total TAT/ Number of process
                                           = (60/5)
                                           =12.0 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (50/5)
                                           =8.2 Milliseconds



1.    Round Robin (Quantum time/time-slice= 2)
Quantum is allocated to each process for execution. (it is in milliseconds)



Now we can say that: -
1.   16 is the completion time of P1 (process 1)
2.   1 is the completion time of P2 (processn2)
3.   18 is the completion time of P3 (process 3)
4.   19 is the completion time of P4 (process 4)
5.   6 is the completion time of P5 (process 5)

Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P1
0
10
19
19-0=19
19-10= 9
P2
0
1
3
3-0=3
3-1= 2
P3
0
2
5
5-0=5
5-2= 3
P4
0
1
6
6-0=6
6-1= 5
P5
0
5
15
15-0=15
15-5= 10
Total number of process= 5
TAT= 48
WT= 29

Average Turnaround Time= Total TAT/ Number of process
                                           = (48/5)
                                           =9.6 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (29/5)
                                           =5.8 Milliseconds






Problem 1.8: - (Try yourself)
Consider the following snapshot of an OS with 5 processes:
Process
Burst Time
Priority
P1
                  10
3
P2
1
1
P3
2
4
P4
1
5
P5
5
2

This process are assumed to have arrived on the order P1,P2,P3,P4 and P5, all at time 0.(means arrival time of each process is 0)
Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
    1.  FCFS
    2.  SJF
    3.  Priority scheduling
     4.   Round Robin (Quantum = 1)


    
      
Answer: -
       1. FCFS: -
                  
                      Average Turnaround Time =13.4 Milliseconds
       
                                         
                      Average Turnaround Time= 9.6 Milliseconds

       2. SJN: -
                  
                      Average Turnaround Time = 7.0 Milliseconds
       
                                         
                      Average Turnaround Time= 3.2 Milliseconds

    

       3. Round Robin: -
                  
                      Average Turnaround Time =9.2  Milliseconds
       
                                         
                      Average Turnaround Time=5.4  Milliseconds


Problem 1.9: -
Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
CPU Burst time
P1
0
24
P2
0
3
P3
0
3
Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm RR scheduling: -
SOLUTION: -
1.  If we use a time quantum of 4 milliseconds, then process P1 gets the first 4 milliseconds. Since it requires another 20 milliseconds, it is preemptive after the first time quantum, and the CPU is given to the process in the queue, process P2.
2.  Since process P2 does not need 4 milliseconds, it quite before its time quantum expires. The CPU is then given to the next process, process P3.
3.  Once each process has received 1 time quantum, the CPU is returned to the P1 process for an additional time quantum.
4.  The resulting RR schedule is: -
Round Robin (Quantum time/time-slice= taken as 4)



Now we can say that: -
1.   30 is the completion time of P1 (process 1)
2.   7 is the completion time of P2 (processn2)
3.   10 is the completion time of P3 (process 3)

Process
AT
BT
CT
TAT=CT-AT
WT=TAT-BT
P1
0
24
30
30-0=30
30-24= 6
P2
0
3
7
7-0=7
7-3= 4
P3
0
3
10
10-0=10
10-3= 7
Total number of process= 5
TAT= 47
WT= 17

Average Turnaround Time= Total TAT/ Number of process
                                           = (47/5)
                                           =9.4 Milliseconds
Average Turnaround Time= Total WT/ Number of process
                                           = (17/5)
                                           =3.4 Milliseconds

Problem 1.10: -
Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
Burst time
P1
0
10
P2
1
29
P3
3
3
P4
9
7
P5
12
12

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
1.  FCFS
2.  SJF
3.  Round Robin (Quantum = 10 milliseconds)
Which algorithm would give minimum AWT and ATAT?


Problem 1.11: -
Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
Burst time
P1
0
1
P2
1
9
P3
2
1
P4
3
9
P5
3
9

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
1.  FCFS
2.  SJF
3.  Round Robin (Quantum = 4 milliseconds)


Problem 1.11: -
Consider the following snapshot of an OS with 5 processes:
Process
Arrival Time
Burst time
Priority
P1
0
4
6
P2
1
5
5
P3
2
2
3
P4
3
1
4
P5
4
3
2
P6
5
6
1

Compute and prepare a chart for Average Waiting time and Average Turnaround time of each process for algorithm: -
1.  FCFS
2.  SJF
3.  Priority
4.  Round Robin (Quantum = 4 milliseconds)



For any problem you can comment we will definitely reply on your problems.













2 comments:

Please do not enter any spam link in the comment box and use English and Hindi language for comment.

Latest Update

Key Components of XML

Popular Posts