Question

In: Computer Science

Process Burst Time P1 6ms P2 2ms P3 7ms P4 3ms P5 8ms P6 10ms Using...

Process Burst Time
P1 6ms
P2 2ms
P3 7ms
P4 3ms
P5 8ms
P6 10ms


Using the table above calculate the average wait time using First Come First Served (FCFS) and Shortest Job First (SJF) CPU scheduling.

Solutions

Expert Solution

1. Calculate average time using FCFS First come First served

Consider the processes P1, P2, P3, P4, P5, P6 given table and given Burst Time, arrives for execution in the same order, with Arrival Time 0, let's find the average waiting time using the FCFS scheduling algorithm.

Average time is = (0 + 6 +8 + 15 +18 +26 )/6

= 73/6

=12.1666667 ms

Diagram:

ALGORITHM:

1-  Input the processes along with their burst time (bt).
2-  Find waiting time (wt) for all processes.
3-  As first process that comes need not to wait so 
    waiting time for process 1 will be 0 i.e. wt[0] = 0.
4-  Find waiting time for all other processes i.e. for
     process i -> 
       wt[i] = bt[i-1] + wt[i-1] .
5-  Find turnaround time = waiting_time + burst_time 
    for all processes.
6-  Find average waiting time = 
                 total_waiting_time / no_of_processes.
7-  Similarly, find average turnaround time = 
                 total_turn_around_time / no_of_processes.

Output of the algorithm will come like this :

2. Calculate average time using SJF Shortest Job First

SJF is of 2 types :

  • Non-Preemptive SJF
  • Preemptive SJF

Let us consider the arrival time for the following processes are:

Process Burst Time Arrival time
p1 6 2
p2 2 0
p3 7 3
p4 3 1
p5 8 4
p6 10 5

Average time = (0+1+3+8+14+21)/6

= 47/6

= 7.833335 ms

Diagram:

Java Code to calulate the average time is for your reference:

import java.util.*;

public class demo{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

System.out.println ("enter no of process:");

int n = sc.nextInt();

int pid[] = new int[n];

int at[] = new int[n];

int bt[] = new int[n];

int ct[] = new int[n];

int ta[] = new int[n];

int wt[] = new int[n];  

int f[] = new int[n];

int st=0, tot=0;

float avgwt=0, avgta=0;

for(int i=0;i<n;i++)

{

System.out.println ("enter process " + (i+1) + " arrival time:");

at[i] = sc.nextInt();

System.out.println ("enter process " + (i+1) + " brust time:");

bt[i] = sc.nextInt();

pid[i] = i+1;

f[i] = 0;

}

boolean a = true;

while(true)

{

int c=n, min=999;

if (tot == n)

break;

for (int i=0; i<n; i++)

{

if ((at[i] <= st) && (f[i] == 0) && (bt[i]<min))

{

min=bt[i];

c=i;

}

}

if (c==n)

st++;

else

{

ct[c]=st+bt[c];

st+=bt[c];

ta[c]=ct[c]-at[c];

wt[c]=ta[c]-bt[c];

f[c]=1;

tot++;

}

}

System.out.println("\npid  arrival brust  complete turn waiting");

for(int i=0;i<n;i++)

{

avgwt+= wt[i];

avgta+= ta[i];

System.out.println(pid[i]+"\t"+at[i]+"\t"+bt[i]+"\t"+ct[i]+"\t"+ta[i]+"\t"+wt[i]);

}

System.out.println ("\naverage tat is "+ (float)(avgta/n));

System.out.println ("average wt is "+ (float)(avgwt/n));

sc.close();

}

}

Output:


Related Solutions

Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,264 106 Accounts receivable 12,618 126 Computer supplies 2,545 128 Prepaid insurance 2,220 131 Prepaid rent 3,300 163 Office equipment 8,000 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,264 106 Accounts receivable 12,618 126 Computer supplies 2,545 128 Prepaid insurance 2,220 131 Prepaid rent 3,300 163 Office equipment 8,000 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,564 106 Accounts receivable 12,818 126 Computer supplies 2,645 128 Prepaid insurance 1,860 131 Prepaid rent 3,200 163 Office equipment 8,700 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,564 106 Accounts receivable 12,818 126 Computer supplies 2,645 128 Prepaid insurance 1,860 131 Prepaid rent 3,200 163 Office equipment 8,700 164 Accumulated depreciation—Office equipment...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5, P6 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2019, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2019) follows. No. Account Title Debit Credit 101 Cash $ 38,664 106 Accounts receivable 12,818 126 Computer supplies 2,545 128 Prepaid insurance 1,980 131 Prepaid rent 3,300 163 Office equipment 8,800 164 Accumulated depreciation—Office equipment...
6. Consider the following set of processes P1, P2, P3, P4. Process Burst Time Arrival Time...
6. Consider the following set of processes P1, P2, P3, P4. Process Burst Time Arrival Time Priority P1 3 0 1 P2 5 1 2 P3 8 3 3 P4 4 4 2 a) Draw Gantt charts that illustrate the execution of these processes using the following scheduling algorithms: first-come, first-served (FCFS), priority scheduling (larger number=high priority), and Round-Bobin (RR, quantum=2). b) Compute the average waiting time, turnaround time for the three algorithms. Turnaround time – amount of time to...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2016, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2016) follows. No. Account Title Debit Credit 101 Cash $ 38,664 106 Accounts receivable 12,718 126 Computer supplies 2,545 128 Prepaid insurance 2,160 131 Prepaid rent 3,020 163 Office equipment 8,400 164 Accumulated depreciation—Office equipment $...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2017, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2017) follows. No. Account Title Debit Credit 101 Cash $ 38,764 106 Accounts receivable 13,418 126 Computer supplies 2,545 128 Prepaid insurance 2,040 131 Prepaid rent 3,140 163 Office equipment 8,000 164 Accumulated depreciation—Office equipment $...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2017, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2017) follows. No. Account Title Debit Credit 101 Cash $ 38,864 106 Accounts receivable 12,718 126 Computer supplies 2,645 128 Prepaid insurance 2,040 131 Prepaid rent 2,940 163 Office equipment 8,400 164 Accumulated depreciation—Office equipment $...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s...
Serial Problem Business Solutions LO P1, P2, P3, P4, P5 After the success of the company’s first two months, Santana Rey continues to operate Business Solutions. The November 30, 2015, unadjusted trial balance of Business Solutions (reflecting its transactions for October and November of 2015) follows. No. Account Title Debit Credit 101   Cash $ 39,164 106   Accounts receivable 12,918 126   Computer supplies 2,645 128   Prepaid insurance 1,980 131   Prepaid rent 2,960 163   Office equipment 8,400 164   Accumulated depreciation—Office equipment $...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT