in Operating System edited by
964 views
2 votes
2 votes

Four processes- $\text{P}_1, \text{P}_2, \text{P}_3,$ and $\text{P}_4-$ are scheduled to use a single processor. The following table shows the arrival time and duration of each of the four processes.
$$
\begin{array}{|c|c|c|}
\hline \textbf{Process} & \textbf{Arrival Time (seconds)} & \textbf{Duration (seconds)} \\
\hline \hline \text{P}_1 & 0 & 7 \\
\hline \text{P}_2 & 2 & 4 \\
\hline \text{P}_3 & 4 & 1 \\
\hline \text{P}_4 & 5 & 4 \\
\hline
\end{array}
$$
If the system uses a preemptive shortest-job-first scheduling algorithm, what is the average waiting time for the four processes, in seconds?

  1. $2$
  2. $3$
  3. $4$
  4. $5$
in Operating System edited by
964 views

2 Answers

0 votes
0 votes

The process chart looks flow looks like:

(0 to 2s) -→ Running process: P1; Job remaining: 5s (gets preempted by incoming process P2 since execution time of P2 is lesser than the remaining time of P1)

(2 to 4s) -→ Running process: P2; Job remaining: 2s (gets preempted by incoming process P3 since P3 has least execution time among P1, P2 and P3 having remaining executions times equal to 5, 2 and 1 respectively)

(4 to 5s) -→ Running process: P3 (completes execution. Processes available in queue are P1, P2 and P4 having remaining time equal to 5, 2 and 4s. Process P2 gets picked.)

(5 to 7s) --→ Running process: P2 (completes execution. Processes available in queue are P1 and P4 having remaining time equal to 5 and 4s. Process P4 gets picked.)

(7 to 11s) --→ Running process: P4 (completes execution. Processes available in queue is P1 and gets picked.)

( 11 to 16s) --→ Running process: P4 (completes execution)

 

Waiting time = (Finish time – Arrival time) – Process duration

Wait time (P1) = (16 – 0) – 7 = 9

Wait time (P2) = (7 – 2) – 4 = 1

Wait time (P2) = (5 – 4) – 1 = 0

Wait time (P4) = (11 – 5) – 4 = 2

Average wait time = (9 + 1+ 0 + 2) / 4 = 12 / 4 = 3

Hence, answer: (B)

0 votes
0 votes

AT = Arrival Time, BT = Burst Time, CT = Completion Time, TAT = Turnaround Time, WT = Waiting Time

Formula: TAT = CT – AT and WT = TAT – BT

Process AT BT CT TAT WT
P1 0 7 16 16 9
P2 2 4 7 5 1
P3 4 1 5 1 0
P4 5 4 11 6 2

 

Gantt chart: 

$\therefore$ Average(WT) = (9+1+0+2)/4 = 3

Answer: B

Answer:

Related questions