A computer has two processors, ๐‘€1 and ๐‘€2. Four processes ๐‘ƒ1, ๐‘ƒ2, ๐‘ƒ3, ๐‘ƒ4โ€ฆ

2025

A computer has two processors, ๐‘€1 and ๐‘€2. Four processes ๐‘ƒ1, ๐‘ƒ2, ๐‘ƒ3, ๐‘ƒ4 with CPU bursts of 20, 16, 25, and 10 milliseconds, respectively, arrive at the same time and these are the only processes in the system. The scheduler uses non-preemptive priority scheduling, with priorities decided as follows:

โ€ข ๐‘€1 uses priority of execution for the processes as, ๐‘ƒ1 > ๐‘ƒ3 > ๐‘ƒ2 > ๐‘ƒ4, i.e., ๐‘ƒ1 and ๐‘ƒ4 have highest and lowest priorities, respectively.ย 

โ€ข ๐‘€2 uses priority of execution for the processes as, ๐‘ƒ2 > ๐‘ƒ3 > ๐‘ƒ4 > ๐‘ƒ1, i.e., ๐‘ƒ2 and ๐‘ƒ1 have highest and lowest priorities, respectively.ย 

A process ๐‘ƒ๐‘– is scheduled to a processor ๐‘€๐‘˜, if the processor is free and no other process ๐‘ƒ๐‘— is waiting with higher priority. At any given point of time, a process can be allocated to any one of the free processors without violating the execution priority rules. Ignore the context switch time. What will be the average waiting time of the processes in milliseconds

  1. A.

    9.00

  2. B.

    8.75

  3. C.

    6.50

  4. D.

    7.50

Attempted by 166 students.

Show answer & explanation

Correct answer: A

Given:

  • Bursts: P1 = 20 ms, P2 = 16 ms, P3 = 25 ms, P4 = 10 ms (all arrive at time 0)

  • Two processors, non-preemptive scheduling

  • Priorities on M1: P1 > P3 > P2 > P4

  • Priorities on M2: P2 > P3 > P4 > P1

  • Rule: When a processor becomes free, assign any waiting process provided there is no other waiting process with higher priority for that processor.

Step-by-step scheduling:

  • t = 0 (both processors free):

    • M1 runs P1 from 0 to 20 ms (P1 has highest priority on M1).

    • M2 runs P2 from 0 to 16 ms (P2 has highest priority on M2).

  • t = 16 ms (M2 becomes free; P1 still on M1):

    • Waiting processes: P3 and P4. For M2, P3 has higher priority than P4, so M2 runs P3 from 16 to 41 ms.

  • t = 20 ms (M1 becomes free; P3 running on M2):

    • Only P4 is waiting, and no higher-priority waiting process exists for M1, so M1 runs P4 from 20 to 30 ms.

Gantt-like view (times in ms):

  • M1: | P1 (0โ€“20) | P4 (20โ€“30) | idle (30โ€“41)

  • M2: | P2 (0โ€“16) | P3 (16โ€“41)

Waiting times (start time โˆ’ arrival time, arrival = 0):

  • P1: 0 ms

  • P2: 0 ms

  • P3: 16 ms

  • P4: 20 ms

Average waiting time = (0 + 0 + 16 + 20) / 4 = 9 ms

A video solution is available for this question โ€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir